64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/qedus/osmpbf"
|
|
)
|
|
|
|
func estPBF(t *testing.T) {
|
|
f, err := os.Open("/home/eson/tools/china-latest.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 {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ways := &KeyList{}
|
|
|
|
var nc, wc, rc uint64
|
|
for {
|
|
if v, err := d.Decode(); err == io.EOF {
|
|
break
|
|
} else if err != nil {
|
|
t.Fatal(err)
|
|
} else {
|
|
switch v := v.(type) {
|
|
case *osmpbf.Node:
|
|
// Process Node v.
|
|
|
|
case *osmpbf.Way:
|
|
// Process Way v.
|
|
// i++
|
|
if name, ok := v.Tags["name:zh"]; ok {
|
|
if _, ok := v.Tags["highway"]; ok {
|
|
wc++
|
|
ways.AppendKey(name)
|
|
}
|
|
}
|
|
|
|
case *osmpbf.Relation:
|
|
// Process Relation v.
|
|
default:
|
|
t.Fatalf("unknown type %T\n", v)
|
|
}
|
|
}
|
|
}
|
|
|
|
SaveData("./data/ways.gob", ways)
|
|
t.Errorf("Nodes: %d, Ways: %d, Relations: %d\n", nc, wc, rc)
|
|
}
|