Extract points/coordinates from a polygon in Shapely

ryanjdillon picture ryanjdillon · Dec 9, 2013 · Viewed 88.6k times · Source

How do you get/extract the points that define a shapely polygon? Thanks!

Example of a shapely polygon

from shapely.geometry import Polygon

# Create polygon from lists of points
x = [list of x vals]
y = [list of y vals]

polygon = Polygon(x,y)

Answer

ryanjdillon picture ryanjdillon · Dec 9, 2013

So, I discovered the trick is to use a combination of the Polygon class methods to achieve this.

If you want geodesic coordinates, you then need to transform these back to WGS84 (via pyproj, matplotlib's basemap, or something).

from shapely.geometry import Polygon

#Create polygon from lists of points
x = [list of x vals]
y = [list of y vals]

some_poly = Polygon(x,y)

# Extract the point values that define the perimeter of the polygon
x, y = some_poly.exterior.coords.xy