+ CalcPolygonAreaAutonavi

This commit is contained in:
gazebo
2019-09-16 20:54:55 +08:00
parent 312ce745cc
commit 44810b2957
2 changed files with 57 additions and 0 deletions

View File

@@ -495,3 +495,35 @@ func CreateQrOrBarCode(width, height int, codeType, srcData string) (imgBase64 s
return imgBase64, err
}
// 高德地图面积计算公式
// https://blog.csdn.net/zdb1314/article/details/80661602
func CalcPolygonAreaAutonavi(points [][2]float64) (area float64) {
sJ := float64(6378137)
Hq := float64(0.017453292519943295)
c := float64(sJ * Hq)
d := float64(0)
if 3 > len(points) {
return 0
}
for i := 0; i < len(points)-1; i++ {
h := points[i]
k := points[i+1]
u := h[0] * c * math.Cos(h[1]*Hq)
hhh := h[1] * c
v := k[0] * c * math.Cos(k[1]*Hq)
d = d + (u*k[1]*c - v*hhh)
}
g1 := points[len(points)-1]
point := points[0]
eee := g1[0] * c * math.Cos(g1[1]*Hq)
g2 := g1[1] * c
k := point[0] * c * math.Cos(point[1]*Hq)
d += eee*point[1]*c - k*g2
return 0.5 * math.Abs(d) / float64(1000000)
}