GeoLatte/geolatte-geom

Expecting an exception when parsing a GeoJSON feature which number of coordinates doesn't match coordinateDimension

kad-sidera opened this issue · 3 comments

When parsing a feature with a Point geometry, I would expect an exception when the number of coordinates doesn't match the coordinateDimension. Instead, the feature is successfully parsed.

Example feature:

    {
      type: "Feature",
      geometry: {
        type: "Point",
        coordinates: [1.1, 2.2, 3.3],
      },
    }

When parsing this feature with a CRS that has a coordinateDimension of 2, the resulting feature has 2 coordinates.

Would it be possible to throw an exception during parsing when the number of coordinates doesn't match coordinateDimension? This could be a Setting, so it won't break current behavior. And would a Pull Request be accepted for this new setting?

The current behavior is motivated by the fact that most CRS definitions in common use seem to be 2D, but for many use cases users need 3D or 3DM coordinates.
But if you need to have the parser be strict in the coordinate dimension, then having a special feature setting for this is I think a good solution. I'd be happy to consider a PR for this.

Thanks for your answer!

In the meanwhile I've realised that throwing an exception when the number of coordinates doesn't match the coordinateDimension will not fix the problem it was supposed to fix.

The features that get parsed can have a 2D or 3D Point. To fix the problem, it would be necessary that the number of coordinates in the parsed Geometry would match the number of coordinates in the original feature.

Is this already possible with Geolatte? Or would it be possible to add a new setting for this?

I don't exactly understand what your use case is. What are the "original features" here?

For what it is worth, Geolatte ensures that if you serialize a feature, no additional coordinate values are introduced. In other words there is an invariant like

assertEquals(geom.getCoordinateDimension(),
mapper.readValue(mapper.writeValueAsString(geom), Geometry.class).getCoordinateDimension())

for any Geometry geom.