4

I have a GeoDataFrame consisting polygons. How can I convert each polygon into a list of coordinates? Is there any attribute, method or function in GeoPandas to do this?

enter image description here

3 Answers 3

6

A very effective, very fast solution would be to build a function and then use apply instead of a list comprehension

def coord_lister(geom):
    coords = list(geom.exterior.coords)
    return (coords)

coordinates = shp.geometry.apply(coord_lister)
1
  • What is geometry here? A complete example would be more helpful.
    – not2qubit
    Commented Aug 24, 2022 at 17:38
4

You can use the following list comprehension to achieve this:

[list(shp.geometry.exterior[row_id].coords) for row_id in range(shp.shape[0])]

where shp is your geopandas dataframe. It uses the exterior and coords methods from shapely.

2
  • It worked, though there is a problem with multipolygons. Thanks!
    – Vinay
    Commented Oct 31, 2018 at 15:43
  • [list(shp.geometry.exterior.iloc[row_id].coords) for row_id in range(shp.shape[0])]
    – Jackssn
    Commented Aug 25, 2021 at 12:09
0

shp.geomtery.get_coordinates() worked for me.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 26, 2023 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.