Search code examples
pythonpandasgeopandas

How acess/get/extract the values of POLYGON in a geometry column of Geopandas Dataframe?


How can i get the values of coordinate in a POLYGON in a Geopandas Dataframe?

shapefile = gpd.read_file("CAMPOS_PRODUCAO_SIRGASPolygon.shp")

I can easy do it for a centroid of my POLYGON

with it:

print(campos_shape.centroid.iloc[0].x)
-39.853276865819765
print(type(campos_shape.centroid.iloc[0].x))
<class 'float'>

I want a list or numpy array with all point value of lat and lon contained in POLYGON

So how can i convert a POLYGON to numpy array?


Solution

  • If anyone else has this problem, here is one solution that work for me:

    def coord_lister(geom):
        coords = list(geom.exterior.coords)
        return (coords)
    
    coordinates_list = your_geopandas_df.geometry.apply(coord_lister)