+ 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)
}

View File

@@ -2,9 +2,12 @@ package jxutils
import (
"fmt"
"strings"
"testing"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
)
func TestSplitSlice(t *testing.T) {
@@ -101,3 +104,25 @@ func TestSplitStoreName(t *testing.T) {
}
}
}
func TestCalcPolygonAreaAutonavi(t *testing.T) {
// pointers := GetPolygonFromCircle(104.065702, 30.657488, 3000, 128)
// area := CalcPolygonAreaAutonavi(pointers)
// t.Logf("area:%f", area)
db := dao.GetDB()
storeList, err := dao.GetStoreList(db, nil, nil, "")
if err != nil {
t.Fatal(err)
}
strBuilder := &strings.Builder{}
strBuilder.WriteString("\n")
for _, v := range storeList {
if v.DeliveryRangeType == model.DeliveryRangeTypePolygon {
pointers := CoordinateStr2Points(v.DeliveryRange)
area1 := CalcPolygonAreaAutonavi(pointers)
strBuilder.WriteString(fmt.Sprintf("%d,%f\n", v.ID, area1))
}
}
t.Log(strBuilder.String())
}