-
Notifications
You must be signed in to change notification settings - Fork 0
/
densenodes_test.go
174 lines (147 loc) · 3.49 KB
/
densenodes_test.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package main
import (
"encoding/json"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func Setup() {
file, err := os.Open("./testdata/andorra-latest.osm.pbf")
if err != nil {
log.Fatalln("Error reading file:", err)
}
defer file.Close()
err = Parse(file)
if err != nil {
log.Fatal(err)
}
}
func Test_NodetoGEOJSON(t *testing.T) {
Setup()
node, ok := largeMapNode.Get("625025")
if !ok {
log.Fatal("Not in dict!")
}
var str []byte
str, err := json.Marshal(node.Feature)
if err != nil {
log.Fatal("Not in dict!")
}
assert.Equal(t,
"{\"id\":625025,\"type\":\"Feature\",\"bbox\":[1.5527243000000002,42.5142133],\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.5527243000000002,42.5142133]},\"properties\":null}",
string(str))
}
/*
// Can only test on features with one Tag because the order is random.
// So test fail if result is correct because of Tag order.
func Test_SQLString(t *testing.T) {
Setup()
node, ok := largeMapNode.Get("264932716")
if !ok {
log.Fatal("Not in dict!")
}
assert.Equal(t, node.SQLString(), "(264932716, ('\"created_by\"=>\"JOSM\"'), ST_GeomFromText('POINT (1.6483839 42.6004428)'))")
}
func Test_GeoJSON_go_geom(t *testing.T) {
Setup()
node, ok := largeMapNode.Get("4698145789")
if !ok {
log.Fatal("Not in dict!")
}
node2, ok := largeMapNode.Get("625025")
if !ok {
log.Fatal("Not in dict!")
}
newmap := map[string]interface{}{}
for key, value := range node.Tags {
newmap[key] = value
}
mn := geojson.Feature{
ID: fmt.Sprint(node.Id),
BBox: node.Coords.Bounds(),
Geometry: &node.Coords,
Properties: newmap}
mn2 := geojson.Feature{
ID: fmt.Sprint(node2.Id),
BBox: node2.Coords.Bounds(),
Geometry: &node2.Coords,
Properties: map[string]interface{}{}}
// bytes, err := mn2.MarshalJSON()
// if err != nil {
// log.Fatal("Not in dict!")
// }
bounds := geom.NewBounds(geom.XY)
bounds.SetCoords(mn.Geometry.FlatCoords(), mn2.Geometry.FlatCoords())
features := []*geojson.Feature{&mn, &mn2}
fc := geojson.FeatureCollection{
BBox: bounds,
Features: features}
gj, err := fc.MarshalJSON()
if err != nil {
log.Fatal(err)
}
assert.Equal(t, "", string(gj))
}
func Test_GeoJSON_orb(t *testing.T) {
Setup()
node, ok := largeMapNode.Get("4698145789")
if !ok {
log.Fatal("Not in dict!")
}
newmap := map[string]interface{}{}
for key, value := range node.Tags {
newmap[key] = value
}
coords := node.Coords.FlatCoords()
point := orb.Point{coords[0], coords[1]}
mn := orbgj.Feature{
ID: fmt.Sprint(node.Id),
Type: "Point",
// BBox: node.Coords.Bounds(),
Geometry: point,
Properties: newmap}
fc := orbgj.FeatureCollection{
Features: []*orbgj.Feature{&mn},
}
data, err := fc.MarshalJSON()
if err != nil {
log.Fatal(err)
}
println(string(data))
assert.Equal(t, 1, 2)
}
func BenchmarkSingleLoop(b *testing.B) {
os.Stdout, _ = os.Open(os.DevNull)
Setup()
cnt := 0
b.ResetTimer()
for n := 0; n < b.N; n++ {
valuesNodes := largeMapNode.IterBuffered()
for tuple := range valuesNodes {
if val, ok := tuple.Val.Tags["natural"]; ok {
if val == "tree" {
cnt++
}
}
}
}
log.Println("Number of trees: ", cnt)
}
func BenchmarkParallelLoop(b *testing.B) {
os.Stdout, _ = os.Open(os.DevNull)
Setup()
cnt := 0
b.ResetTimer()
for n := 0; n < b.N; n++ {
largeMapNode.IterCb(func(key string, v MyNode) {
if val, ok := v.Tags["natural"]; ok {
if val == "tree" {
cnt++
}
}
})
}
log.Println("Number of trees: ", cnt)
}
*/