Reputation: 1254
I have a MultiPolygon list in wkt format and I have to get the coordinates from those points.
Could anyone help me please? Thanks in advance
Upvotes: 2
Views: 2905
Reputation: 23738
You can use the Shapely Python module to parse WKT geometry and extract the coordinates.
Try this:
import shapely.wkt
shapes = [ 'MULTIPOLYGON (((69.0 41.0, 69.0 41.4, 69.4 41.4, 69.4 41.0, 69.0 41.0)), ((59.0 42.0, 59.0 42.4, 59.4 42.4, 59.4 42.0, 59.0 42.0)))' ]
for shape in shapes:
shapelyObject = shapely.wkt.loads(shape)
for polygon in shapelyObject:
coords = list(polygon.exterior.coords)
print(coords)
Output:
[(69.0, 41.0), (69.0, 41.4), (69.4, 41.4), (69.4, 41.0), (69.0, 41.0)]
[(59.0, 42.0), (59.0, 42.4), (59.4, 42.4), (59.4, 42.0), (59.0, 42.0)]
Upvotes: 3