Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 19, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/252d58313b9f2701c7edeb09a22567c1 to your computer and use it in GitHub Desktop.
Save tmcw/252d58313b9f2701c7edeb09a22567c1 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"github.com/paulmach/go.geo"
"github.com/qedus/osmpbf"
"io"
"log"
"os"
"runtime"
"strconv"
)
func main() {
const quadKeyLevel = 6
d := osmpbf.NewDecoder(os.Stdin)
err := d.Start(runtime.GOMAXPROCS(-1))
if err != nil {
log.Fatal(err)
}
charMap := make(map[string]map[string]int)
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:
nameTag, ok := v.Tags["name"]
if ok == true {
for _, runeValue := range nameTag {
quadkey := geo.NewPoint(v.Lon, v.Lat).QuadkeyString(quadKeyLevel)
mm, ok := charMap[quadkey]
if !ok {
mm = make(map[string]int)
charMap[quadkey] = mm
}
charMap[quadkey][strconv.Itoa(int(runeValue))]++
}
}
}
}
}
b, err := json.Marshal(charMap)
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment