-1

I have this pandas dataframe which I converted from a polygon( with latitudes and longitudes).I need to separate this into rows (each row with one lat and long pair). Can anyone please help. Thanks. enter image description here

I just need an index and evert lat-long pair in each row.

I tried other stack overflow solutions but not able to resolve this

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Can you please edit the answer and insert a textual copy of your dataframe in code fences? We don't like images of data here. And especially not image links. – Joooeey Apr 19 '23 at 19:53

1 Answers1

0

I think the following code snippet can help you out:

import geopandas as gpd
import shapely

gdf = gpd.GeoDataFrame(
    geometry=[shapely.Polygon([[50.0, 50.0], [50.0, 50.1], [50.1, 50.1], [50.1, 50.0], [50.0, 50.0]])]
)
coordinates = shapely.get_coordinates(gdf.geometry[0])
points = [shapely.Point(coordinate[0], coordinate[1]) for coordinate in coordinates]
coords_gdf = gpd.GeoDataFrame(geometry=points)
print(coords_gdf)

Result:

                    geometry
0  POINT (50.00000 50.00000)
1  POINT (50.00000 50.10000)
2  POINT (50.10000 50.10000)
3  POINT (50.10000 50.00000)
4  POINT (50.00000 50.00000)
Pieter
  • 340
  • 1
  • 6