Shapely's polygonize_full operation, which merges line segments into polygons, returns four geometry collections: polygons, dangles, cuts and invalid ring lines. Dangles are defined in the documentation as "edges which have one or both ends which are not incident on another edge endpoint", while cuts are "connected at both ends but do not form part of polygon".

I assumed that the following code, which tries to polygonize a square with one edge missing, should find two dangles and one cut edge:

import shapely

lines = [

polygons, dangles, cuts, invalids = shapely.ops.polygonize_full(lines)

However, the polygons, dangles and invalids collections are all empty, while the cuts collection contains the three original edges:

[str(cut) for cut in cuts]
# This returns ['LINESTRING (1 1, 0 1)', 'LINESTRING (1 0, 1 1)', 'LINESTRING (0 0, 1 0)']

When does polygonize_full detect a dangle? Is there a way to get the dangling edges in my test case (0 0, 1 0 and 1 1, 0 1) using Shapely?


This is an old question, but: polygonize_full will not introduce (in my understanding) edges. Thus, it will not close a polygon. What it does is it generates polygons from line segments, introducing nodes where two segments intersect. Yet, they still need to be able to close the polygon with (sub)segments from the original input. In your input, the shape is a reversed "C", which is open, and forms no polygon.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.