Throw error when creating a MultiPoylgon with infinite edges
See original GitHub issueExpected behavior and actual behavior.
As per the doc:
Figure 7. … on the right, a MultiPolygon that is invalid because its members touch at an infinite number of points (along a line).
Thus shapely should throw an error when creating a MultiPoylgon with infinite edges. (I caught this error when trying to save such a geometry with GeoPandas, and it would always convert the MultiPolygon into a single Polygon.)
Steps to reproduce the problem.
This test should throw an error:
from shapely.geometry import Polygon, MultiPolygon
polygon1 = Polygon(((0, 0),
(0, 1),
(1, 1),
(1, 0),
(0, 0)))
polygon2 = Polygon(((1, 0),
(1, 1),
(2, 1),
(2, 0),
(1, 0)))
multipolygon = MultiPolygon([polygon1, polygon2])
Operating system
Linux/Ubuntu
Shapely version and provenance
Shapely 1.6.4.post2 Python 3.5
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
geom_sf(): "polygon edge not found" intermittent error #2252
I am using geom_sf to do some county maps based on tigris data. I successfully followed some examples, but when I try to...
Read more >Merging a list of Polygons to Multipolygons - Stack Overflow
Great Answer! Taking directly MultiPolgyon() does not throw errors but results in faulty results. Tested when combining polygons and ...
Read more >Advanced geospatial analysis - Turf.js
Finds the tangents of a (Multi)Polygon from a Point. ... Infinity - convex hull. ... Throws. Error - if geoJson is invalid. npm...
Read more >Splitting an arbitrary polygon by a line - The Infinite Loop
Essentially, one iterates over the polygon's vertices, checks on which side of the split line they lie and adds them accordingly either to...
Read more >Polygon node order will not correct - sql - GIS Stack Exchange
A common reason for this error is that a polygon has the wrong ring orientation. To create a larger than hemisphere geography instance, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@asmith26 the GEOS library used by Shapely has a global context but that context doesn’t give us anything to strictly require valid geometries. We’d need to do this entirely in Python. If you want it to be entirely transparent, so that
Polygon(..)
raises an exception when invalid, I think the thing to do would be to write a Python context manager that patches all the Shapely geometry constructors when__enter__()
is called and then restores them when__exit__()
is called. I like writing code like this, but I’m not keen to include it in Shapely. Adding features to the library requires more tests and more documentation and I’m super short on time right now.Thank @kannes thanks for this information.
Perhaps there could be a configuration option that one could add to the start of their script to e.g. automatically check validity of all geometries created by the script (and perhaps throw an error instead of just saying “False”). (I appreciate such configurations may add unwanted complications, but I thought I would ask in case something similar already exists or if it inspires other suggestions.)