9

Simply I just want to convert a MultiLineString data to a list but get the error: TypeError: 'MultiLineString' object is not iterable"

from shapely.geometry import MultiLineString

coords = [((0.0, 0.0), (0.0, 20.0)), ((20.0, 0.0), (20.0, 20.0))]
mlines = MultiLineString(coords)
mls_list = list(mlines)

I use Python 3.7.8 and Shapely 2.0.1.

1 Answer 1

12

You need to use geoms method for multipart geometries.

mls_list = list(mlines.geoms)
print(mls_list)

# OUT:
# [<LINESTRING (0 0, 0 20)>, <LINESTRING (20 0, 20 20)>]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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