Skip to content

Commit 92a450e

Browse files
authored
Merge pull request #98 from pelias/relation_admin_centre
use admin_centre node for relation centroid where available
2 parents 90d5951 + 3c00dd8 commit 92a450e

5 files changed

+28
-1
lines changed

build/pbf2json.darwin-x64

96 Bytes
Binary file not shown.

build/pbf2json.linux-arm

536 Bytes
Binary file not shown.

build/pbf2json.linux-x64

1.05 KB
Binary file not shown.

build/pbf2json.win32-x64

512 Bytes
Binary file not shown.

pbf2json.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strconv"
1414
"strings"
1515

16-
"github.com/paulmach/go.geo"
16+
geo "github.com/paulmach/go.geo"
1717
"github.com/qedus/osmpbf"
1818
"github.com/syndtr/goleveldb/leveldb"
1919
"github.com/syndtr/goleveldb/leveldb/opt"
@@ -353,6 +353,21 @@ func print(d *osmpbf.Decoder, masks *BitmaskMap, db *leveldb.DB, config settings
353353
continue
354354
}
355355

356+
// use 'admin_centre' node centroid where available
357+
// note: only applies to 'boundary=administrative' relations
358+
// see: https://github.com/pelias/pbf2json/pull/98
359+
if v.Tags["boundary"] == "administrative" {
360+
for _, member := range v.Members {
361+
if member.Type == 0 && member.Role == "admin_centre" {
362+
if latlons, err := cacheLookupNodeByID(db, member.ID); err == nil {
363+
latlons["type"] = "admin_centre"
364+
centroid = latlons
365+
break
366+
}
367+
}
368+
}
369+
}
370+
356371
// trim tags
357372
v.Tags = trimTags(v.Tags)
358373

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

524+
func cacheLookupNodeByID(db *leveldb.DB, id int64) (map[string]string, error) {
525+
stringid := strconv.FormatInt(id, 10)
526+
527+
data, err := db.Get([]byte(stringid), nil)
528+
if err != nil {
529+
log.Println("[warn] fetch failed for node ID:", stringid)
530+
return make(map[string]string, 0), err
531+
}
532+
533+
return bytesToLatLon(data), nil
534+
}
535+
509536
func cacheLookupNodes(db *leveldb.DB, way *osmpbf.Way) ([]map[string]string, error) {
510537

511538
var container []map[string]string

0 commit comments

Comments
 (0)