-
Notifications
You must be signed in to change notification settings - Fork 171
Open
Description
It is possible to create invalid shapes through the JtsShapeFactory.MultipolygonBuilder.
You can reproduce by running the following class:
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 {
polygonBuilder.build();
System.out.println("OK");
} catch (InvalidShapeException e) {
System.out.println("KO: " + e.getMessage());
}
try {
shapeFactory.multiPolygon().add(polygonBuilder).build();
System.out.println("OK");
} catch (InvalidShapeException e) {
System.out.println("KO: " + e.getMessage());
}
}
}Output:
KO: Self-intersection at or near point (0.0, 0.0, NaN)
OK
The JtsShapeFactory.MultipolygonBuilder is used in the ShapeDeserializer and GeometryDeserializer classes and can lead jackson to create invalid shapes.
Pierre-Hugues
Metadata
Metadata
Assignees
Labels
No labels