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
|
/**
* Yats - yats
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Paolo Lulli <kevwe.com>
* @copyright Paolo Lulli 2024
*/
package geo
import (
"fmt"
"github.com/pd0mz/go-maidenhead"
"github.com/uber/h3-go/v4"
"testing"
)
func TestDistance(t *testing.T) {
winnipeg := coordinate{49.895077, -97.138451}
regina := coordinate{50.445210, -104.618896}
result := Distance(winnipeg, regina)
fmt.Printf("%f\n", result)
}
func TestGenerateAllNodes(t *testing.T) {
for lon := -180; lon <= 180; lon += 10 {
for lat := -90; lat <= 90; lat += 10 {
fmt.Printf("Lon: %d Lat: %d\n", lon, lat)
}
fmt.Printf("")
// lon += 10
}
}
func TestMaidenHead(t *testing.T) {
point := coordinate{0, 0}
var p = maidenhead.NewPoint(point.lat, point.lon)
locator, _ := p.Locator(3)
fmt.Printf("Locator: %s\n", locator)
var centerOfMaidenHead, _ = maidenhead.ParseLocatorCentered(locator)
fmt.Printf("long: %f lat: %f", centerOfMaidenHead.Longitude, centerOfMaidenHead.Latitude)
d := Distance(coordinate{centerOfMaidenHead.Latitude, centerOfMaidenHead.Longitude}, point)
fmt.Printf("Distance from maidenhead center: %f", d)
}
func TestH3Cells(t *testing.T) {
latLng := h3.NewLatLng(37.775938728915946, -122.41795063018799)
//resolution := 15 // between 0 (biggest cell) and 15 (smallest cell)
for i := 0; i < 16; i++ {
cell := h3.LatLngToCell(latLng, i)
fmt.Printf("Resolution: %d\t id: %s parent: %s\n", i, cell, cell.Parent(i-1))
}
var p = maidenhead.NewPoint(latLng.Lat, latLng.Lng)
for i := 0; i <= 5; i++ {
locator, _ := p.Locator(i)
fmt.Printf("Locator: %s\n", locator)
}
// Output:
// 8928308280fffff
}
func TestH3VertxDistance(t *testing.T) {
point0 := coordinate{40.690058601, -74.044151762}
point1 := coordinate{40.689907695, -74.045061792}
dist := Distance(point0, point1)
fmt.Printf("distance: %f\n", dist)
}
|