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

Polygonizer throws NullPointerException #691

Closed
clarisma opened this issue Feb 10, 2021 · 6 comments
Closed

Polygonizer throws NullPointerException #691

clarisma opened this issue Feb 10, 2021 · 6 comments

Comments

@clarisma
Copy link

Polygonization throws NullPointerException using the following input geometry:

MULTILINESTRING ((143145039 659338416, 143146736 659338410, 143146496 659332192, 143152064 659332033, 143151920 659338391, 143153808 659338383, 143153951 659330368, 143144624 659330497, 143145039 659338416),
(143146736 659338410, 143151920 659338391, 143152064 659332033, 143146496 659332192, 143146736 659338410))

java.lang.NullPointerException: Cannot read field "y" because "p" is null
at org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator.locate(IndexedPointInAreaLocator.java:88)
at org.locationtech.jts.operation.polygonize.EdgeRing.isInRing(EdgeRing.java:261)
at org.locationtech.jts.operation.polygonize.EdgeRing.findEdgeRingContaining(EdgeRing.java:87)
at org.locationtech.jts.operation.polygonize.HoleAssigner.findShellContaining(HoleAssigner.java:106)
at org.locationtech.jts.operation.polygonize.HoleAssigner.assignHoleToShell(HoleAssigner.java:78)
at org.locationtech.jts.operation.polygonize.HoleAssigner.assignHolesToShells(HoleAssigner.java:72)
at org.locationtech.jts.operation.polygonize.HoleAssigner.assignHolesToShells(HoleAssigner.java:40)
at org.locationtech.jts.operation.polygonize.Polygonizer.polygonize(Polygonizer.java:255)
at org.locationtech.jts.operation.polygonize.Polygonizer.getGeometry(Polygonizer.java:188)

I can work around this issue by unioning the geometry prior to passing it to the Polygonizer.

@dr-jts
Copy link
Contributor

dr-jts commented Feb 10, 2021

That linework is not fully noded, as required by Polygonizer. But it should throw a more informative exception.

@dr-jts dr-jts changed the title Polygonization throws NullPointerException Polygonizer throws NullPointerException Feb 10, 2021
@dr-jts
Copy link
Contributor

dr-jts commented Feb 10, 2021

Fixed by #692

@dr-jts dr-jts closed this as completed Feb 10, 2021
@clarisma
Copy link
Author

Thanks for the fast fix, I'll have a look at it tomorrow.
Could you explain the "not fully noded" part? The two linestrings polygonize fine individually. The four vertexes of the squarish shape are shared by the outer U-shape; their edges don't cross. I know I'm missing something, but I can't figure out what.

@dr-jts
Copy link
Contributor

dr-jts commented Feb 10, 2021

Input to the Polygonizer must touch only at endpoints (nodes). These lines clearly violate that.

Note that this also precludes input lines which share lines segments (or subsegments). This data also violates that.

@clarisma
Copy link
Author

Yes, I figured the collinear edges might be the issue.
However, this geometry has shared segments as well, but produces two valid polygons:

MULTILINESTRING ((100 100, 200 100, 200 200, 100 200, 100 100),
(200 100, 300 100, 300 200, 200 200, 200 100))

@dr-jts
Copy link
Contributor

dr-jts commented Feb 10, 2021

Invalid input may still produce valid output. But it also may not....

With the fix for this issue, in fact the data above also produces valid output.

But these examples are outside the operating range of Polygonizer, so all bets are off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants