-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
83 lines (75 loc) · 2.26 KB
/
main.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
78
79
80
81
82
83
package main
import (
"fmt"
"log"
"wloc/lib"
"wloc/lib/mac"
"wloc/lib/morton"
"github.com/leaanthony/clir"
)
func main() {
cli := clir.NewCli("morton", "Convert between GPS and morton encoded tile key coordinates", "0.0.1")
var lat float64
var long float64
var level int = 13
cli.IntFlag("level", "Openstreetmap level", &level)
encode := cli.NewSubCommandInheritFlags("encode", "Encode GPS coordinates to morton tile key")
encode.Float64Flag("lat", "latitude", &lat)
encode.Float64Flag("long", "longitude", &long)
encode.Action(func() error {
tileKey := morton.Encode(lat, long, level)
fmt.Println("Tile Key: ", tileKey)
return nil
})
var tileKey int64
decode := cli.NewSubCommand("decode", "Decode morton tile key to GPS coordinates")
decode.Int64Flag("tile", "tile key", &tileKey)
decode.Action(func() error {
log.Println(morton.Unpack(tileKey))
lat, long, _ := morton.Decode(tileKey)
fmt.Println(lat, long)
return nil
})
var mLat int
var mLong int
pack := cli.NewSubCommand("pack", "Pack quadkey encoded coordinates to tilekey")
pack.IntFlag("lat", "latitude", &mLat)
pack.IntFlag("long", "longitude", &mLong)
pack.Action(func() error {
tileKey := morton.Pack(mLat, mLong, 13)
fmt.Println("Tile Key: ", tileKey)
return nil
})
unpack := cli.NewSubCommand("unpack", "Unpack tilekey to quadkey encoded coordinates")
unpack.Int64Flag("tile", "tile key", &tileKey)
unpack.Action(func() error {
mLat, mLong, _ := morton.Unpack(tileKey)
fmt.Println(mLat, mLong)
return nil
})
var bssid int64
macdecode := cli.NewSubCommand("mac", "Decode a MAC address")
macdecode.Int64Flag("mac", "MAC address int64", &bssid)
macdecode.Action(func() error {
fmt.Println(mac.Decode(bssid))
return nil
})
var coord int64
coorddecode := cli.NewSubCommand("coordd", "Decode a coordinate")
coorddecode.Int64Flag("coord", "Coordinate int64", &coord)
coorddecode.Action(func() error {
fmt.Printf("%f\n", lib.CoordFromInt(coord, -8))
return nil
})
var coordf float64
coordencode := cli.NewSubCommand("coorde", "Encode a coordinate")
coordencode.Float64Flag("coord", "Coordinate float64", &coordf)
coordencode.Action(func() error {
fmt.Printf("%d\n", lib.IntFromCoord(coordf, 8))
return nil
})
err := cli.Run()
if err != nil {
panic(err)
}
}