首页 > 解决方案 > 如何在 Geopandas Dataframe 的几何列中访问/获取/提取 POLYGON 的值?

问题描述

如何在 Geopandas 数据框中获取 POLYGON 中的坐标值?

shapefile = gpd.read_file("CAMPOS_PRODUCAO_SIRGASPolygon.shp")

我可以很容易地为我的 POLYGON 的质心做到这一点

用它:

print(campos_shape.centroid.iloc[0].x)
-39.853276865819765
print(type(campos_shape.centroid.iloc[0].x))
<class 'float'>

我想要一个列表或 numpy 数组,其中包含 POLYGON 中的所有 lat 和 lon 点值

那么如何将 POLYGON 转换为 numpy 数组?

标签: pythonpandasgeopandas

解决方案


如果其他人有这个问题,这里有一个对我有用的解决方案:

def coord_lister(geom):
    coords = list(geom.exterior.coords)
    return (coords)

coordinates_list = your_geopandas_df.geometry.apply(coord_lister)

推荐阅读