@@ -13,7 +13,7 @@ import (
13
13
"strconv"
14
14
"strings"
15
15
16
- "github.com/paulmach/go.geo"
16
+ geo "github.com/paulmach/go.geo"
17
17
"github.com/qedus/osmpbf"
18
18
"github.com/syndtr/goleveldb/leveldb"
19
19
"github.com/syndtr/goleveldb/leveldb/opt"
@@ -353,6 +353,21 @@ func print(d *osmpbf.Decoder, masks *BitmaskMap, db *leveldb.DB, config settings
353
353
continue
354
354
}
355
355
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
+
356
371
// trim tags
357
372
v .Tags = trimTags (v .Tags )
358
373
@@ -506,6 +521,18 @@ func cacheFlush(db *leveldb.DB, batch *leveldb.Batch, sync bool) {
506
521
batch .Reset ()
507
522
}
508
523
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
+
509
536
func cacheLookupNodes (db * leveldb.DB , way * osmpbf.Way ) ([]map [string ]string , error ) {
510
537
511
538
var container []map [string ]string
0 commit comments