diff --git a/build/pbf2json.darwin-x64 b/build/pbf2json.darwin-x64 index a69cefb..d86fd04 100755 Binary files a/build/pbf2json.darwin-x64 and b/build/pbf2json.darwin-x64 differ diff --git a/build/pbf2json.linux-arm b/build/pbf2json.linux-arm index 9c15918..2e4d91a 100755 Binary files a/build/pbf2json.linux-arm and b/build/pbf2json.linux-arm differ diff --git a/build/pbf2json.linux-x64 b/build/pbf2json.linux-x64 index 3d5a1b7..efb0416 100755 Binary files a/build/pbf2json.linux-x64 and b/build/pbf2json.linux-x64 differ diff --git a/build/pbf2json.win32-x64 b/build/pbf2json.win32-x64 index 0fde619..9dddb53 100755 Binary files a/build/pbf2json.win32-x64 and b/build/pbf2json.win32-x64 differ diff --git a/pbf2json.go b/pbf2json.go index 0736630..a09f2ee 100644 --- a/pbf2json.go +++ b/pbf2json.go @@ -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" @@ -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) @@ -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