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

本文介绍了一种使用Python代码根据经纬度坐标计算多边形面积的方法,适用于顺时针或逆时针相连的经纬度点,确保了计算精度,并提供了具体示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

附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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值