JtsShapeFactory MultipolygonBuilder fails to validate shape
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start by running the provided reproduction, then inspect JtsShapeFactory.MultipolygonBuilder and the ShapeDeserializer and GeometryDeserializer paths that use it. Done means invalid multipolygons are rejected consistently rather than being constructed successfully.
Written by the indexing model from the issue text.
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.
- Dominant language
- Java
- Stars
- 961
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from locationtech/spatial4j
-
question
Difficulty 5/5 Over a week Newbie friendliness 20/100
locationtech/spatial4j#233 · 1 comment ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
locationtech/spatial4j#232 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
locationtech/spatial4j#231 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
locationtech/spatial4j#230 · 2 comments ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
locationtech/spatial4j#227 · 2 comments ·
All issues in locationtech/spatial4j
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100