-
Notifications
You must be signed in to change notification settings - Fork 18
/
mbr.go
77 lines (77 loc) · 1.79 KB
/
mbr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
//
//import (
// "math"
// "fmt"
// "strings"
//)
//
//// 求最小外接矩形
//type Rectangle struct {
// MaxLat float64
// MinLat float64
// MaxLng float64
// MinLng float64
//}
//
//func New() Rectangle {
// return Rectangle{}
//}
//
//// 生成四个值
//func (r *Rectangle) GetMinRectangle(data [][]float64) Rectangle {
// maxLat, maxLng := float64(-1<<32), float64(-1<<32)
// minLat, minLng := float64(1<<32), float64(1<<32)
// for _, v := range data {
// maxLat = math.Max(maxLat, v[1])
// maxLng = math.Max(maxLng, v[0])
// minLat = math.Min(minLat, v[1])
// minLng = math.Min(minLng, v[0])
//
// }
// r.MaxLng = maxLng
// r.MinLng = minLng
// r.MaxLat = maxLat
// r.MinLat = minLat
// //r = &rectangle{maxLat: maxLat, minLat: minLat, maxLng: maxLng, minLng: minLat}
// return *r
//}
//
//
///*
//
//[116.403322,39.920255],[116.410703,39.897555],[116.402292,39.892353],[116.389846,39.891365]
//*/
//
//// 生成经纬度
//func (r *Rectangle) generateLatLng() [][]float64 {
// result := [][]float64{}
// result = append(result, []float64{r.MaxLng, r.MinLat})
// result = append(result, []float64{r.MinLng, r.MinLat})
// result = append(result, []float64{r.MinLng, r.MaxLat})
// result = append(result, []float64{r.MaxLng, r.MaxLat})
// return result
//}
//
//func generatesJsFile(result [][]float64) string {
// str := "["
// for _, v := range result {
// if v == nil {
// continue
// }
// str += fmt.Sprintf("[%v,%v],", v[0], v[1])
// }
// str = strings.TrimSuffix(str, ",")
// str += "]"
// return str
//
//}
//
//func main() {
// re := [][]float64{{116.304233,39.986398}, {116.449112,39.992589}, {116.493381,39.915599}, {116.33068,39.92224}}
// obj := New()
// obj.GetMinRectangle(re)
// ///fmt.Println(obj.generateLatLng())
// va := generatesJsFile(obj.generateLatLng())
// fmt.Println(va)
//}