Inconsistencies with respect to the Polygon `within` and `intersection` methods.
See original GitHub issueExpected behavior and actual behavior.
I’ve been trying to use the intersection
method to compute the intersection region of the 2 given shapely.geometry.Polygon
instances. I was initially trying to verify the intersection results (let’s call it res
) by checking if a point I know that lies in the result using the contains
method.
I was then trying to dig into the source of this issue and I found that for a few cases the intersection result res
when passed through poly.contains(res)
, the method returns False
where ideally it is supposed to return a True
value as the intersection of the polygon is supposed to be a part both the Polygons.
Steps to reproduce the problem.
- Adding it in the comments below as I was mainly dealing with huge GeoJSON data.
Operating system
Mac OS X Mojave, Ubuntu 18.04
Shapely version and provenance
Shapely - 1.7.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Evaluation of Topological Consistency in CityGML - KIT
As an application, it is examined which matrices can occur as intersection matrices, and how matrices from topologically consistent data look.
Read more >Problems intersecting large polygon shapefiles in QGIS (V2 ...
My method so far has been to intersect these two layers to split the distributions into the hexagonal grid cells. From this I...
Read more >THE POLYGON CONTAINMENT PROBLEM - DTIC
lationships between polygons involves computing their intersection or testing for inclusion of one within the other. All these problems have been.
Read more >Point in polygon - GIS Wiki | The GIS Encyclopedia
Another algorithm is to compute the given point's winding number with respect to the polygon. If the winding number is non-zero, the point...
Read more >Intersection Polygon - an overview | ScienceDirect Topics
All methods have one thing in common—they must find points of intersection between pairs of edges. The edges on which the intersection points...
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
Fundamentally, this is a floating point precision issue, and is not entirely a shapely issue. Yes, with a perfect precision model I would expect the result of an intersection of two geometries to be contained by each geometry. However, this cannot always be safely represented with a double precision model used by Shapely. JTS fails with this specific example too, except when the precision model is changed to a fixed with scale 1000.0.
You can apply a negative buffer with a very small amount, such as a number near machine epsilon of the fraction of square root of area of the intersected area, which should return the desired result:
note that these two geometries are nearly the same:
Thanks for clarifying!