2017-08-17 18 views
1

私はpointsはそれが400平方マイルよりも大きいかどうどのように私はpolygonとスロー例外の面積を計算することができ緯度と経度を持つポリゴンの面積を計算するには?

from shapely import wkt 

def validate_polygon(points): 
    try: 
     wkt.loads("POLYGON((%s))" % points) 
    except Exception as ex: 
     raise WrongRequestDataError("Incorrect points format. " + str(ex)) 

をポリゴンされているかどうかをチェックする次のような方法がありますか?

私はこれをチェックすることを試みた:

polygon = wkt.loads("POLYGON((%s))" % "34.093523 -118.274893,34.091414 -118.275887,34.092082 -118.278062,34.093867 -118.276609,34.093523 -118.274893") 
print(polygon.area) 

4.406979500001112e-06 

を、それは間違った答えのように思えるか、それはこの値を使用する単位の種類とどのよう平方マイルまたはキロメートル^ 2にそれを翻訳するには?

答えて

0

documentationに目を通すと、areaを計算する一般的な方法があります。

1

は、一般的に次のような面積を計算します:

from shapely.geometry import Polygon 
points = [(34.093523, -118.274893), (34.091414, -118.275887), (34.092082, -118.278062), (34.093867, -118.276609), (34.093523, -118.274893)] 
polygon = Polygon(points) 
# the area in square degrees 
area_sdeg = polygon.area 

注:平方メートルで面積計算のために、あなたはhttps://gist.github.com/robinkraft/c6de2f988c9d3f01af3c

+0

質問が更新されました –

+0

本当ですか?この値は非常に大きい 'polygon.area * earth_radius_miles ** 2'です! –

+0

面積計算に関して私は間違っていました。 polygon.areaは方位角を返します...そのために投影を使用する必要があります。 – udo

0

これは完璧に動作最適なソリューションですで説明したように突起部を使用する必要があります私にとっては

def compute_polygon_area(points): 
    coordinates = (tuple(map(float, x.split())) for x in points.split(', ')) 
    xy_coordinates = switch_to_xy_coordinates(coordinates) 
    return Polygon(xy_coordinates).area 

def switch_to_xy_coordinates(coordinates): 
    earth_radius = 6371 # in km 
    lat_dist = pi * earth_radius/180.0 

    latitudes, longitudes = zip(*coordinates) 
    y = (lat * lat_dist for lat in latitudes) 
    x = (lon * lat_dist * cos(radians(lat)) 
    for lat, lon in zip(latitudes, longitudes)) 
    return list(zip(x, y)) 
関連する問題