如何从 wkt MultiPolygon 获取坐标

How to get coordinates from wkt MultiPolygon

我有一个 wkt 格式的 MultiPolygon 列表,我必须从这些点获取坐标。

有人能帮帮我吗? 提前致谢

您可以使用 Shapely Python 模块来解析 WKT 几何并提取坐标。

试试这个:

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)

输出:

[(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)]