Created
August 19, 2018 22:09
-
-
Save tmcw/252d58313b9f2701c7edeb09a22567c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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