如何从匀称的点列表创建匀称的多边形? [英] How to create a shapely Polygon from a list of shapely Points?

查看:85
本文介绍了如何从匀称的点列表创建匀称的多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从匀称的点创建一个多边形.

I want to create a polygon from shapely points.

from shapely import geometry
p1 = geometry.Point(0,0)
p2 = geometry.Point(1,0)
p3 = geometry.Point(1,1)
p4 = geometry.Point(0,1)

pointList = [p1, p2, p3, p4, p1]

poly = geometry.Polygon(pointList)

给我一​​个类型错误 TypeError: object of type 'Point' has no len()

gives me an type error TypeError: object of type 'Point' has no len()

如何从匀称的 Point 对象创建 Polygon?

How to create a Polygon from shapely Point objects?

推荐答案

如果您特别想根据匀称的几何点构造多边形,请在列表推导式中调用它们的 x、y 属性.换句话说:

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))'

请注意,shapely 足够聪明,可以代表您闭合多边形,即您不必在最后再次传入第一个点.

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.

这篇关于如何从匀称的点列表创建匀称的多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆