ryanjdillon - 2 months ago 36

Python Question

How do you get/extract the points that define a

`shapely`

Thanks!

`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

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
```