How to create a Polygon given its Point vertices?

隐身守侯 提交于 2019-11-29 13:09:46

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.

Malik Brahimi

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

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

The Polygon constructor doesn't expect a list of Point objects but a list of point coordinates.

See https://shapely.readthedocs.io/en/latest/manual.html#polygons

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

Just put the import section.

I am posting a new answer because I can't comment on a previous post as a comment, because I have lack of "points"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!