parzival
parzival

Reputation: 21

How to convert ESRI shapefile into .csv with the following fields

enter image description here

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

enter image description here

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?

Upvotes: -1

Views: 26

Answers (1)

Marianne
Marianne

Reputation: 161

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.

Upvotes: 0

Related Questions