close

How to create a shapely Polygon from a list of shapely Points?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to create a shapely Polygon from a list of shapely Points in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to create a shapely Polygon from a list of shapely Points?

  1. How to create a shapely Polygon from a list of shapely Points?

    If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a list comprehension.

  2. create a shapely Polygon from a list of shapely Points

    If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a list comprehension.

Method 1

If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a list comprehension. In other words:

from shapely import geometry

poly = geometry.Polygon([[p.x, p.y] for p in pointList])

print(poly.wkt)  # prints: 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'

Note that shapely is clever enough to close the polygon on your behalf, i.e. you don’t necessarily have to pass-in the first point again at the end.

Method 2

Polygon object requires a nested list of numbers, not a list of Point objects.

polygon = Polygon([[0, 0], [1, 0], [1, 1], [0, 1]])

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read