我使用 sympy.geometry
包创建了一个多边形,如下所示:
poly1 = Polygon((39.,4.), (32.,30.), (40.,10.), (42.,10.), (43.,14.))
多边形的点是经/纬度坐标。 我现在想将多边形投影到椭圆体(地球)上并计算多边形的面积。
我写了下面的代码:
from pyproj import Proj
#specify projection for the Earth using reference ellipsoid"
wgs84=pyproj.Proj("+init=EPSG:4326")
poly1_transformed=[]
for point in poly1:
new_point = wgs84(point)
poly1_transformed.append(new_point)
但是我无法遍历多边形中的点。有什么办法可以做到这一点,或者有其他方法可以投影整个多边形(并最终计算出面积)吗?
这是我的错误:
TypeError
Traceback (most recent call last)
<ipython-input-65-0c7501bb5894> in <module>()
5 wgs84=pyproj.Proj("+init=EPSG:4326")
6
----> 7 for point in poly1:
8 new_point = wgs84(point)
9 print (point, new_point)
TypeError: 'Polygon' object is not iterable
最佳答案
您可以使用 poly1.args
获取点,因为 Polygon
对象不可迭代:
for point in poly1.args:
new_point = wgs84(point)
poly1_transformed.append(new_point)
关于python - 你如何遍历多边形中的点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548542/