根据经纬度计算多边形的面积

2022-09-20 07:59:33

这里有个前提是:你的经纬度点是依次相连接的点,不是无序的,可以是顺时针,或者逆时针都可以。

附python代码:

import math
def ConvertToRadian(input):
return input * math.pi / 180;
def CalculatePolygonArea0(data):
area = 0;
arr = data.split(';')
arr_len = len(arr)
if arr_len < 3:
return 0.0
temp = []
for i in range(0, arr_len):
temp.append([float(x) for x in arr[i].split(',')])
for i in range(0, arr_len):
area += ConvertToRadian(temp[(i + 1) % arr_len][0] - temp[(i) % arr_len][0]) * (2 + math.sin(ConvertToRadian(temp[(i) % arr_len][1])) + math.sin(ConvertToRadian(temp[(i + 1) % arr_len][1])));
area = area * 6378137.0 * 6378137.0 / 2.0;
return round(math.fabs(area),6);
if (__name__ == "__main__"):
data = "115.989099,39.646023;115.987394,39.645988;115.987371,39.647407;115.986684,39.647423;115.986602,39.648088;115.989095,39.648151;115.989188,39.646021;115.989099,39.646023"

print(CalculatePolygonArea0(data))

Calculate the area of polygon according to the longitude and latitude.

assuming your source is WGS1984, if not then you'll need to adjust the ellipsoid used by the  line(

area = area * 6378137.0 * 6378137.0 / 2.0;

).

转载于:https://www.cnblogs.com/c-w20140301/p/10308431.html

  • 作者:weixin_30877755
  • 原文链接:https://blog.csdn.net/weixin_30877755/article/details/95503523
    更新时间:2022-09-20 07:59:33