initial import
This commit is contained in:
commit
14f29f88d3
|
@ -0,0 +1,9 @@
|
||||||
|
module git.wntrmute.dev/kyle/gridsq
|
||||||
|
|
||||||
|
go 1.21.3
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.wntrmute.dev/kyle/goutils v1.7.4 // indirect
|
||||||
|
github.com/logocomune/maidenhead v1.0.1 // indirect
|
||||||
|
gopkg.in/billups/golang-geo.v2 v2.0.0-20170124000346-c2931833be19 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,6 @@
|
||||||
|
git.wntrmute.dev/kyle/goutils v1.7.4 h1:kbvUoxRwAEemz4jL52AUKaOipuCX8F8PGTQHS5V3lRY=
|
||||||
|
git.wntrmute.dev/kyle/goutils v1.7.4/go.mod h1:1PGn83Ac98KWyI6yfpCVyP1Ji61PX6lFpROxY+IoTJg=
|
||||||
|
github.com/logocomune/maidenhead v1.0.1 h1:WnBpC/LIhc81QnwDdxEPKHwSAspMCWwsYMuM9vQMFgA=
|
||||||
|
github.com/logocomune/maidenhead v1.0.1/go.mod h1:FLkUKuGyo4uKESNlXG8jgQgaTSApyR2ZZfq7m2Btmjs=
|
||||||
|
gopkg.in/billups/golang-geo.v2 v2.0.0-20170124000346-c2931833be19 h1:vu0Y9rNRRTFG70fnQ/W/CG4N629vz9uaqaY7R7fXnVo=
|
||||||
|
gopkg.in/billups/golang-geo.v2 v2.0.0-20170124000346-c2931833be19/go.mod h1:Wo/E84lJTIKl9WdTGYGLAG+q9zRxnl9RnCZenHqASWk=
|
|
@ -0,0 +1,89 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.wntrmute.dev/kyle/goutils/die"
|
||||||
|
"github.com/logocomune/maidenhead"
|
||||||
|
geo "gopkg.in/billups/golang-geo.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var qths = map[int]string{
|
||||||
|
4: "CM97",
|
||||||
|
6: "CM97cq",
|
||||||
|
8: "CM97cq53",
|
||||||
|
10: "CM97cq53CI",
|
||||||
|
}
|
||||||
|
|
||||||
|
var kmToMile = 0.621371
|
||||||
|
|
||||||
|
func cToP(c maidenhead.Coordinate) *geo.Point {
|
||||||
|
return geo.NewPoint(c.Lat, c.Lng)
|
||||||
|
}
|
||||||
|
|
||||||
|
func distBearing(qth, qsl string) (err error) {
|
||||||
|
var cqth, cqsl maidenhead.Coordinate
|
||||||
|
cqth.Lat, cqth.Lng, err = maidenhead.GridCenter(qth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cqsl.Lat, cqsl.Lng, err = maidenhead.GridCenter(qsl)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pqth := cToP(cqth)
|
||||||
|
pqsl := cToP(cqsl)
|
||||||
|
dist := pqth.GreatCircleDistance(pqsl)
|
||||||
|
bearing := pqth.BearingTo(pqsl)
|
||||||
|
fmt.Printf("%s => %s: distance %0.2f miles, bearing %0.1f°\n",
|
||||||
|
qth, qsl, dist*kmToMile, bearing)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var lat, lon float64
|
||||||
|
var precision int64
|
||||||
|
|
||||||
|
flag.Float64Var(&lat, "lat", 0.0, "latitude of grid")
|
||||||
|
flag.Float64Var(&lon, "lon", 0.0, "longitude of grid")
|
||||||
|
flag.Int64Var(&precision, "d", 6, "number of digits")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if flag.NArg() == 0 {
|
||||||
|
fmt.Println("nothing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := flag.Arg(0)
|
||||||
|
switch cmd {
|
||||||
|
case "geo":
|
||||||
|
grid, err := maidenhead.Locator(lat, lon, int(precision))
|
||||||
|
die.If(err)
|
||||||
|
|
||||||
|
fmt.Printf("%0.6f %0.6f: ", lat, lon)
|
||||||
|
fmt.Println(grid)
|
||||||
|
case "qth":
|
||||||
|
grid, ok := qths[int(precision)]
|
||||||
|
if !ok {
|
||||||
|
fmt.Println(qths[6])
|
||||||
|
} else {
|
||||||
|
fmt.Println(grid)
|
||||||
|
}
|
||||||
|
case "db":
|
||||||
|
var qth, qsl string
|
||||||
|
if flag.NArg() == 2 {
|
||||||
|
qsl = flag.Arg(1)
|
||||||
|
qth = qths[len(qsl)]
|
||||||
|
} else {
|
||||||
|
qsl = flag.Arg(2)
|
||||||
|
qth = flag.Arg(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := distBearing(qth, qsl)
|
||||||
|
die.If(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue