Replies: 1 comment
-
Note that all of these shapes are invalid, and invalid geometries may cause unexpected outcomes: shapely.is_valid(shapes)
# array([False, False, False, False]) Make them valid, where the zero-area polygons are better represented as LineString geometries: shapes2 = shapely.make_valid(shapes) Now both approaches create a union as a MultiLineString: print('union_all', shapely.union_all(shapes2))
# union_all MULTILINESTRING ((0 -0.55557, 0 -0.382683), (0 0.707107, 0 0.83147))
union = None
for shape in shapes2:
union = shape if union is None else union.union(shape)
print('iterative: union is now', union)
# iterative: union is now LINESTRING (0 -0.55557, 0 -0.382683)
# iterative: union is now LINESTRING (0 -0.55557, 0 -0.382683)
# iterative: union is now MULTILINESTRING ((0 -0.55557, 0 -0.382683), (0 0.707107, 0 0.83147))
# iterative: union is now MULTILINESTRING ((0 -0.55557, 0 -0.382683), (0 0.707107, 0 0.83147)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am finding the union of a set of 2D triangles. If I use
shapley.union_all()
this succeeds. I can also try to compute the union iteratively. I find that this method is a little faster thanunion_all
.But with some inputs it fails:
I'm not really sure this is a bug or not. In the below, two of the points on the triangle are coincident. The
union
variable starts out as aPOLYGON
, thenLINESTRING
, thenGEOMETRYCOLLECTION (LINESTRING, POLYGON)
, and then it errors.I can mitigate the issue by skipping any shapes for which the area is zero, but that's probably not the most efficient approach.
Steps to reproduce the problem.
Shapely version and provenance
Shapely 2.0.1 installed from PyPI. GOES version string is
3.11.1-CAPI-1.17.1
.Beta Was this translation helpful? Give feedback.
All reactions