Jc LE BERRE
Jc LE BERRE

Reputation: 13

extract coordinates of the center of polygons in a geoJson file in python

I would like to extract the coordinate of the center of each polygon contained in a geojson file.

here is my geojson file: https://france-geojson.gregoiredavid.fr/repo/departements.geojson

What i want is a list of latitude and longitude of the centers of different departments so i can use it to display the code of the department on a choroplethmap in plotly as a scattermapbox.

How can I do that?

Upvotes: 1

Views: 4216

Answers (1)

linog
linog

Reputation: 6226

import geopandas as gpd

df = gpd.read_file("https://france-geojson.gregoiredavid.fr/repo/departements.geojson")

df.head(2)

df["lon"] = df["geometry"].centroid.x
df["lat"] = df["geometry"].centroid.y
df

Upvotes: 4

Related Questions