-
Notifications
You must be signed in to change notification settings - Fork 29
/
example_test.go
59 lines (50 loc) · 1.01 KB
/
example_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
package osmpbf_test
import (
"fmt"
"io"
"log"
"os"
"runtime"
"github.com/qedus/osmpbf"
)
// Don't forget to sync with README.md
func Example() {
f, err := os.Open("greater-london-140324.osm.pbf")
if err != nil {
log.Fatal(err)
}
defer f.Close()
d := osmpbf.NewDecoder(f)
// use more memory from the start, it is faster
d.SetBufferSize(osmpbf.MaxBlobSize)
// start decoding with several goroutines, it is faster
err = d.Start(runtime.GOMAXPROCS(-1))
if err != nil {
log.Fatal(err)
}
var nc, wc, rc uint64
for {
if v, err := d.Decode(); err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
} else {
switch v := v.(type) {
case *osmpbf.Node:
// Process Node v.
nc++
case *osmpbf.Way:
// Process Way v.
wc++
case *osmpbf.Relation:
// Process Relation v.
rc++
default:
log.Fatalf("unknown type %T\n", v)
}
}
}
fmt.Printf("Nodes: %d, Ways: %d, Relations: %d\n", nc, wc, rc)
// Output:
// Nodes: 2729006, Ways: 459055, Relations: 12833
}