最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gis - How to convert ESRI shapefile into .csv with the following fields - Stack Overflow

programmeradmin0浏览0评论

I am trying to convert the data shown here into a .csv that contains these following fields

The current script I have takes in the .shp using geopandas and outputs it as a csv. However, the normal geopandas to csv conversion only gets the shapefile data and the shape geometries. How can I also get the geography object as well included in this or at least the geographical coordinates?

I am trying to convert the data shown here into a .csv that contains these following fields

The current script I have takes in the .shp using geopandas and outputs it as a csv. However, the normal geopandas to csv conversion only gets the shapefile data and the shape geometries. How can I also get the geography object as well included in this or at least the geographical coordinates?

Share Improve this question asked Feb 4 at 18:12 parzivalparzival 214 bronze badges 1
  • Add the code you are using to convert it to csv – Bera Commented Feb 5 at 17:38
Add a comment  | 

1 Answer 1

Reset to default 0

If you want to add a column that has the coordinates of the polygons, you could do something like this :

usa_gdf["geography"] = usa_gdf["geometry"].apply(lambda geom: {"coordinates": [list(coord) for coord in geom.exterior.coords]})

The apply function is meant to perform a specific operation on the dataframe for each row. Here we are using the geometry column, and for each geometry, we extract it's outer ring's coordinates and put that into a new column and we format it however we want. Make sure your data has the WGS84 CRS and if not, create a copy and use this projection.

发布评论

评论列表(0)

  1. 暂无评论