data_workshop/way_test.go

64 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-05-22 07:39:43 +00:00
package main
import (
"io"
"log"
"os"
"runtime"
"testing"
"github.com/qedus/osmpbf"
)
func estPBF(t *testing.T) {
2020-05-22 07:39:43 +00:00
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)
}