fix(datacenters): report newly tagged features osmium cannot export

A still-tagged feature without exportable geometry already keeps its old
line. A newly tagged one had nowhere to go and was dropped silently; it is
now listed as skipped with a warning, so a refresh never loses a site or
hides a broken one.
This commit is contained in:
Trygve Hemminghytt committed 2026-11-03 22:58:09 +01:00
1 parent 04d626a4b1
commit 1f0a8b5f16
3 files changed
+12 -4

No files matched your search

+8 -2
View File
@@ -182,12 +182,13 @@ def feature_line(key, sequence, fresh):
def merge(lines, fresh, rings, tagged):
out, seen, sequence = [], set(), 0
report = {'kept': 0, 'updated': [], 'removed': [], 'added': [], 'unexported': []}
out, seen, known, sequence = [], set(), set(), 0
report = {'kept': 0, 'updated': [], 'removed': [], 'added': [], 'unexported': [], 'skipped': []}
for line in lines:
feature = json.loads(line)
sequence = max(sequence, feature['properties']['id'])
key = osm_key(feature)
known.add(key)
if key in fresh:
seen.add(key)
old_tags = feature['properties']['tags']
@@ -211,6 +212,8 @@ def merge(lines, fresh, rings, tagged):
sequence += 1
out.append(feature_line(key, sequence, fresh[key]))
report['added'].append(key)
# newly tagged, but osmium built no usable geometry: nothing to add yet
report['skipped'] = sorted(set(tagged) - set(fresh) - known, key=lambda k: (k[0], int(k[1:])))
if len({osm_key(json.loads(line)) for line in out}) != len(out):
raise ValueError('Duplicate OSM identity')
return out, report
@@ -239,6 +242,9 @@ def main():
if report['unexported']:
print('warning: kept the old line of tagged features osmium did not export: %s'
% ', '.join(report['unexported']), file=sys.stderr)
if report['skipped']:
print('warning: did not add newly tagged features osmium did not export: %s'
% ', '.join(report['skipped']), file=sys.stderr)
payload = '\n'.join(merged) + '\n'
if args.verify:
if payload != DATASET.read_text(encoding='utf-8'):
+2 -1
View File
@@ -52,9 +52,10 @@ def line(osm_id, sequence):
'type': 'data_center', 'osm_id': osm_id}})
norway = [([(0, 0), (20, 0), (20, 80), (0, 80)], False)]
lines = [line(7, 1), line(8, 2)]
out, report = merge(lines, {}, norway, {'w7'})
out, report = merge(lines, {}, norway, {'w7', 'w12'})
assert out == [lines[0]], out
assert report['unexported'] == ['w7'] and report['removed'] == ['w8'], report
assert report['skipped'] == ['w12'] and report['added'] == [], report
`,
);
});
+2 -1
View File
@@ -29,7 +29,8 @@ reflects OSM as of the extract below, everything else the original snapshot.
- Contact tags are dropped as above; unchanged features keep their original
line, so geometry is only rewritten when tags or rings actually changed.
A feature is removed only once it is no longer tagged; one still tagged but
without an exportable geometry keeps its line and is reported as unexported.
without an exportable geometry keeps its line and is reported as unexported,
and a newly tagged one osmium cannot export is reported as skipped.
- Refresh: `python3 scripts/build-datacenters-norway.py --cache <dir>` uses
Geofabrik's current Norway extract and prints the dated name it used; record
that name, its OSM timestamp and MD5 here. Requires `osmium-tool`.