如何根据给定的点顶点创建多边形? [英] How to create a Polygon given its Point vertices?

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

问题描述

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

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?

推荐答案

如果您特别想从形状良好的几何点构造多边形,请在列表推导中将其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))'

请注意,shape足够聪明,可以代表您关闭多边形,也就是说,您不必在末尾再次传递第一个点.

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天全站免登陆