【问题标题】:How acess/get/extract the values of POLYGON in a geometry column of Geopandas Dataframe?如何在 Pandas Dataframe 的几何列中访问/获取/提取 POLYGON 的值?
【发布时间】:2021-11-08 21:18:41
【问题描述】:

如何在 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 数组,其所有点值为 lat 和 lon 包含在 POLYGON 中

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

【问题讨论】:

    标签: python pandas geopandas


    【解决方案1】:

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

    def coord_lister(geom):
        coords = list(geom.exterior.coords)
        return (coords)
    
    coordinates_list = your_geopandas_df.geometry.apply(coord_lister)
    

    【讨论】:

      【解决方案2】:

      更新: 例如,这会为您提供 shapefile 中第一个条目的多边形坐标:

      list(shapefile["geometry"][0].exterior.coords)
      

      【讨论】:

      • 谢谢,请回复,但这样我只会过滤我的数据框,我想要 POLYGON 内的 lat 和 lon 值
      • 加上shapefile["geometry"][0].interior,你可以检查多边形是否也有内坐标。
      • 这对你有用吗?
      • 不,=(。但没关系。我找到了一个解决方案,我会在这里绘制它。
      猜你喜欢
      • 2015-12-11
      • 2019-06-20
      • 2019-02-27
      • 1970-01-01
      • 2021-09-07
      • 2022-01-19
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      相关资源
      最近更新 更多