ryanjdillon - 1 year ago 287

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)

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**