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
1 Answer
Reset to default 0If 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.