I have a list of shapely polygons
myList = [[<shapely.geometry.polygon.Polygon object at 0x110e09d90>], [<shapely.geometry.polygon.Polygon object at 0x110e09f90>], [<shapely.geometry.polygon.Polygon object at 0x110ec9150>]]
How would I create a MultiPolygon
out of them? I cannot get my head around it
It looks like you have a list of lists (each with one item). Before you do anything, make a flat list of geometries:
myGeomList = [x[0] for x in myList]
There are actually a few options to combine them. The best is to do a unary union on a list of geometries, which may result in different geometry types, such as MultiPolygon, but it not always.
from shapely.ops import unary_union
cu = unary_union(myGeomList)
Or you could pass the list to MultiPolgyon()
or GeometryCollection()
, but these might present issues (invalid, inability to use overlay ops, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With