0

Centroid in Geopandas

I have two location so I want get centroid from geopandas by python? How I do it?

Cotryk
  • 1
  • 1
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 01 '22 at 18:25
  • if you're trying to calculate the centroid of a set of points, see this question: https://stackoverflow.com/questions/70088232/calculate-centroid-of-entire-geodataframe-of-points/70088741#70088741 – Michael Delgado May 01 '22 at 21:29

1 Answers1

4

You can use geopandas.GeoSeries.centroid:

import geopandas as gpd

df = gpd.read_file("polygons.shp")
df["centroid"] = df["geometry"].centroid
df

See also shapely's documentation: object.centroid.

Thomas
  • 8,357
  • 15
  • 45
  • 81