Skip to content

Commit

Permalink
Merge pull request #98 from pelias/relation_admin_centre
Browse files Browse the repository at this point in the history
use admin_centre node for relation centroid where available
  • Loading branch information
missinglink authored Jul 21, 2021
2 parents 90d5951 + 3c00dd8 commit 92a450e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Binary file modified build/pbf2json.darwin-x64
Binary file not shown.
Binary file modified build/pbf2json.linux-arm
Binary file not shown.
Binary file modified build/pbf2json.linux-x64
Binary file not shown.
Binary file modified build/pbf2json.win32-x64
Binary file not shown.
29 changes: 28 additions & 1 deletion pbf2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/paulmach/go.geo"
geo "github.com/paulmach/go.geo"
"github.com/qedus/osmpbf"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
Expand Down Expand Up @@ -353,6 +353,21 @@ func print(d *osmpbf.Decoder, masks *BitmaskMap, db *leveldb.DB, config settings
continue
}

// use 'admin_centre' node centroid where available
// note: only applies to 'boundary=administrative' relations
// see: https://github.com/pelias/pbf2json/pull/98
if v.Tags["boundary"] == "administrative" {
for _, member := range v.Members {
if member.Type == 0 && member.Role == "admin_centre" {
if latlons, err := cacheLookupNodeByID(db, member.ID); err == nil {
latlons["type"] = "admin_centre"
centroid = latlons
break
}
}
}
}

// trim tags
v.Tags = trimTags(v.Tags)

Expand Down Expand Up @@ -506,6 +521,18 @@ func cacheFlush(db *leveldb.DB, batch *leveldb.Batch, sync bool) {
batch.Reset()
}

func cacheLookupNodeByID(db *leveldb.DB, id int64) (map[string]string, error) {
stringid := strconv.FormatInt(id, 10)

data, err := db.Get([]byte(stringid), nil)
if err != nil {
log.Println("[warn] fetch failed for node ID:", stringid)
return make(map[string]string, 0), err
}

return bytesToLatLon(data), nil
}

func cacheLookupNodes(db *leveldb.DB, way *osmpbf.Way) ([]map[string]string, error) {

var container []map[string]string
Expand Down

0 comments on commit 92a450e

Please sign in to comment.