-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JtsShapeFactory MultipolygonBuilder fails to validate shape #219
Comments
Garbage in, Garbage out -- no? Maybe I'm probably missing your point. What do you propose that Spatial4j should do/not-do? |
If you are proposing that the shape be eagerly validated (on construction) then that would definitely be a configurable option. I want to avoid re-validation of already validated data. Consider a persistent store of shapes that are retrieved and matched against some sort of query that needs to be real-time. The shapes were already validated when they were stored. |
My exemple is probably misleading. import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
import org.locationtech.spatial4j.exception.InvalidShapeException;
import org.locationtech.spatial4j.shape.jts.JtsShapeFactory;
public class Main {
public static void main(String[] args) throws Exception {
JtsSpatialContextFactory ctxFactory = new JtsSpatialContextFactory();
ctxFactory.geo = false;
ctxFactory.useJtsLineString = true;
ctxFactory.useJtsMulti = true;
ctxFactory.useJtsPoint = true;
JtsSpatialContext ctx = new JtsSpatialContext(ctxFactory);
JtsShapeFactory shapeFactory = new JtsShapeFactory(ctx, ctxFactory);
JtsShapeFactory.PolygonBuilder polygonBuilder = shapeFactory.polygon()
.pointLatLon(1, 1)
.pointLatLon(-1, -1)
.pointLatLon(1, -1)
.pointLatLon(-1, 1)
.pointLatLon(1, 1);
try {
shapeFactory.multiPolygon().add(polygonBuilder).build();
System.out.println("OK");
} catch (InvalidShapeException e) {
System.out.println("KO: " + e.getMessage());
}
}
} We get I expect the Digging a bit made me notice that the Thank you for your time |
It is possible to create invalid shapes through the
JtsShapeFactory.MultipolygonBuilder
.You can reproduce by running the following class:
Output:
The
JtsShapeFactory.MultipolygonBuilder
is used in theShapeDeserializer
andGeometryDeserializer
classes and can lead jackson to create invalid shapes.The text was updated successfully, but these errors were encountered: