python - 如何在 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 数组?
解决方案
如果其他人有这个问题,这里有一个对我有用的解决方案:
def coord_lister(geom):
coords = list(geom.exterior.coords)
return (coords)
coordinates_list = your_geopandas_df.geometry.apply(coord_lister)
推荐阅读
- node.js - 快递路线问题
- java - 使用 getCurrentFocus 时 requestFocus 不改变焦点
- python - 使用 Python 的 Hub 和 Spoke 指示
- javascript - 使用 AngularJS 构建步骤向导的最佳方法
- javascript - $('元素').show(); vs $('element').css('visibility', 'visible'):哪个更好用?
- elm - Elm 中声明的 List 类型在哪里?
- ios - UITableView 和消失的行
- node.js - 在树莓派和mongodb之间建立连接
- driver - uboot中的设备驱动
- javascript - AngularJS 在不同模块之间共享存储在控制器中的数据