-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.go
69 lines (54 loc) · 1.75 KB
/
registry.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
package ntrip_client
import (
"math"
"github.com/chewxy/math32"
"github.com/go-gnss/ntrip"
)
const (
MaximumDistanceToBaseInM = 100 * 1000
)
type StationDistance struct {
mountpoint string
distanceInM float32
}
type Registry interface {
RegisterCaster(url string, details ntrip.CasterEntry) error
RegisterStation(url string, details ntrip.StreamEntry) error
NearestStations(lat float32, lng float32) (distances []StationDistance, err error)
}
type CasterRegistry interface {
}
type StationsRegistry interface {
Register(source CasterSource, mountpoint string, lat float32, lng float32)
}
const (
earthRadiusMeters = 6371010.0
radiansPerDegree = math.Pi / 180.0
)
// DistanceTo computes the distance in meters between 2 points
// It uses the Haversine formula:
// https://www.movable-type.co.uk/scripts/latlong.html
func Distance32(latA float32, lngA float32, latB float32, lngB float32) float32 {
// Convert to radians as float64
lat1 := latA * radiansPerDegree
lat2 := latB * radiansPerDegree
lon1 := lngA * radiansPerDegree
lon2 := lngB * radiansPerDegree
sinDiffLat := math32.Sin((lat2 - lat1) / 2.0)
sinDiffLon := math32.Sin((lon2 - lon1) / 2.0)
a := sinDiffLat*sinDiffLat +
math32.Cos(lat1)*math32.Cos(lat2)*
sinDiffLon*sinDiffLon
c := 2 * math32.Atan2(math32.Sqrt(a), math32.Sqrt(1-a))
return earthRadiusMeters * c
}
func MetersToDegrees32(lengthInM float32, radius float32) float32 {
angle := lengthInM / (radius * radiansPerDegree)
return angle
}
func MetersToLatitudeAngle(lengthInM float32) float32 {
return MetersToDegrees32(lengthInM, earthRadiusMeters)
}
func MetersToLongitudeAngleAtLatitude(lengthInM float32, latitude float32) float32 {
return MetersToDegrees32(lengthInM, earthRadiusMeters*math32.Cos(latitude*radiansPerDegree))
}