Unexpected behaviour using difference with Polygons
See original GitHub issueExpected behavior and actual behavior.
Removing the intersection (difference) of two Polygons from both Polygons should result in two MultiPolygons which consist of two Polygons. However, the actual returned objects are a Polygon and a MultiPolygon.
The images below show the problem (especially the last one where two “visually” disconnected polygons are treated as one)
Intersecting Polygons:
Intersection:
Polygon (which should be a MultiPolygon):
Edit1: Enabling edges shows the connection between both polygons:
Edit2: Interesting enough, a.symmetric:_difference(b)
returns a MultiPolygon with 4 Polygons as expected
Steps to reproduce the problem.
from shapely.geometry import Polygon as plg
a = plg([(489.73, 0), (498.96, 0), (662.21, 282.74), (652.97, 282.74)])
b = plg([(494.06, 282.74), (484.83, 282.74), (648.07, 0), (657.31, 0)])
inter = a.intersection(b) # is a Polygon
a_wo_inter = a.difference(inter) # should be a MultiPolygon but its not! :(
b_wo_inter = b.difference(inter) # is a Multipolygon
print("Intersection:", inter)
print("Polygon A without intersection:", a_wo_inter)
print("Polygon B without intersection:", b_wo_inter)
Operating system
Windows 10 Pro (1803) Build: 17134.112 Debian 8.8 Kernel Version: 4.13.0-1011-gcp
Shapely version and provenance
Installed using conda (also tried using the windows-wheel) shapely 1.6.4 py36h2a969d5_0 (Python 3.6.4)
Installed using repl.it repl-link Shapely-1.6.4.post1-cp36-cp36m-manylinux1_x86_64.whl (Python 3.6.1)
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
@Korred another two years, and just to confirm that those changes have landed in GEOS ànd are exposed in Shapely 2.0 (beta version released to test). Using your example from above:
(and visually inspecting this resulting MultiPolygon shows that it is now the expected result)
I’m going through all the tickets I can find which report problems with JTS/GEOS overlay, so I can verify how the new code works on them. So far am batting 100… 😃
Correct. Hopefully the GEOS changes will land by Q3 2020.
Not that I’m aware of.