forked from pelias/pbf2json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
38 lines (30 loc) · 890 Bytes
/
util.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
package main
import (
geo "github.com/paulmach/go.geo"
"math"
"strconv"
)
func IsPointSetClosed(points *geo.PointSet) bool {
if points.Length() > 2 {
return points.First().Equals(points.Last())
}
return false
}
func PointToLatLon(point *geo.Point) map[string]string {
var latLon = make(map[string]string)
latLon["lat"] = strconv.FormatFloat(point.Lat(), 'f', 7, 64)
latLon["lon"] = strconv.FormatFloat(point.Lng(), 'f', 7, 64)
return latLon
}
func LatLngMapToPointSet(latLons []map[string]string) *geo.PointSet {
points := geo.NewPointSet()
for _, each := range latLons {
var lon, _ = strconv.ParseFloat(each["lon"], 64)
var lat, _ = strconv.ParseFloat(each["lat"], 64)
points.Push(geo.NewPoint(lon, lat))
}
return points
}
func GetAreaOfBounds(bound *geo.Bound) float64 {
return math.Max(bound.GeoWidth(), 0.000001) * math.Max(bound.GeoHeight(), 0.000001)
}