2016-11-11 82 views
0

我已经使用如下面的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 

回答

1

您可以通过使用poly1.args,而不是获得积分,因为Polygon对象不是可迭代:

for point in poly1.args: 
    new_point = wgs84(point) 
    poly1_transformed.append(new_point)