Skip to content
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

Validation for self-intersection WKT Multipolygon fails at the WKTReader, while works when wrapped in a GEOMETRYCOLLECTION #232

Open
seut opened this issue Sep 20, 2024 · 1 comment
Labels

Comments

@seut
Copy link

seut commented Sep 20, 2024

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.

@dsmiley
Copy link
Contributor

dsmiley commented Sep 20, 2024

I love the clear issue report; looks so ready to turn into a test. I confess I am lacking time to debug this but will be a reviewer.

@dsmiley dsmiley added the bug label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants