作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我计算一些GeoDataFrame
的质心
M["centroid"] = M.centroid
现在,我想将该列保存在 shp
文件中,然后执行
M[["centroid","geometry"]].to_file("mfile.shp")
但司机提示我无法将点
与我的几何图形一起保存。我想这没问题,但我想知道使用 geopandas
最佳答案
因为 GeoPandas 不允许您保存两个几何列(创建 shapefile 时),所以我建议将 xy 坐标保存到每个质心的列中。由此你总能轻松获得身材匀称的点。
for index, row in M.iterrows():
centroid_coords = row.geometry.centroid.coords.xy
M.loc[index, 'cen_x'] = centroid_coords[0][0]
M.loc[index, 'cen_y'] = centroid_coords[1][0]
M[["cen_x", "cen_y", "geometry"]].to_file("mfile.shp")
根据下面的评论进行编辑(谢谢,没有意识到):
temp = M.centroid
M['cen_x'] = temp.x
M['cen_y'] = temp.y
M[["cen_x", "cen_y", "geometry"]].to_file("mfile.shp")
关于python - 如何将质心与几何图形一起保存在 shapefile 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200106/
我是一名优秀的程序员,十分优秀!