Validation for self-intersection WKT Multipolygon fails at the WKTReader, while works when wrapped in a `GEOMETRYCOLLECTION`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing both inputs with WKTReader.parse, then read WKTReader.java around parseGeometryCollectionShape and JtsShapeFactory.java around makeShapeFromGeometry and JtsMultiShapeBuilder.build. Compare how the standalone and wrapped MultiPolygon are validated; done means both variants behave consistently for the reported self-intersection case.
Written by the indexing model from the issue text.
Description
Used version 0.8.
We encountered that parsing a WKT MultiPolygon containing a self-intersection works while it will raise a validation error when it is wrapped into a GEOMETRYCOLLECTION.
This code parses the WKT string into a valid MultiPolygon instance.
var reader = (WKTReader) JtsSpatialContext.GEO.getFormats().getWktReader();
var shape = reader.parse(''MULTIPOLYGON (((5 5, 10 5, 10 10, 5 5)), ((6 6, 10 5, 10 10, 6 6)))');
While this one raises a InvalidShapeException:
var reader = (WKTReader) JtsSpatialContext.GEO.getFormats().getWktReader();
var shape = reader.parse(''GEOMETRYCOLLECTION ( MULTIPOLYGON (((5 5, 10 5, 10 10, 5 5)), ((6 6, 10 5, 10 10, 6 6))) )');
Stacktrace:
Caused by: org.locationtech.spatial4j.exception.InvalidShapeException: Self-intersection at or near point (10.0, 5.0, NaN)
at org.locationtech.spatial4j.shape.jts.JtsGeometry.validate(JtsGeometry.java:127)
at org.locationtech.spatial4j.shape.jts.JtsShapeFactory.makeShapeFromGeometry(JtsShapeFactory.java:502)
at org.locationtech.spatial4j.shape.jts.JtsShapeFactory.makeShapeFromGeometry(JtsShapeFactory.java:475)
at org.locationtech.spatial4j.shape.jts.JtsShapeFactory$JtsMultiShapeBuilder.build(JtsShapeFactory.java:446)
at org.locationtech.spatial4j.io.WKTReader.parseGeometryCollectionShape(WKTReader.java:356)
at org.locationtech.spatial4j.io.WKTReader.parseShapeByType(WKTReader.java:165)
at org.locationtech.spatial4j.io.WKTReader.parseIfSupported(WKTReader.java:110)
at org.locationtech.spatial4j.io.WKTReader.parse(WKTReader.java:81)
I would expect that both variants behave the same.
- 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 ·
-
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 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
locationtech/spatial4j#221 ·
All issues in locationtech/spatial4j
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
elastic/gradle-plugins#157 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
cryptomator/hub#497 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
johanhaleby/occurrent#1120 ·