GeoLatte / geolatte-geom

A geometry model that conforms to the OGC Simple Features for SQL specification.
Other
132 stars 63 forks source link

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

Open kad-sidera opened 4 months ago

kad-sidera commented 4 months ago

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?

maesenka commented 4 months ago

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.

kad-sidera commented 4 months ago

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?

maesenka commented 4 months ago

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.