Correcting OpenStreetMap wrong tag values
As a hobbyist consumer of OSM data to render maps, I find wrong tags annoying. Bad values mean that the resulting map is wrong or incomplete, so less useful. I decided to attack the most egregious ones, which include typos, street names instead of type and some other errors. The idea is to attack the long tail first, so I'm not blocked because the next batch of errors (objects with exactly the same error) looks too big (yes, OCD).
So I hacked a small python script to help me find and edit them:
#! /usr/bin/env python3 import os import psycopg2 def main(): db = psycopg2.connect(dbname='europe') cursor = db.cursor() cursor.execute(''' SELECT count(*) AS count, highway FROM planet_osm_line WHERE highway IS NOT NULL GROUP BY highway ORDER BY count ASC ''') data = cursor.fetchall() for count, highway in data: print(f"next {count}: {highway}") cursor.execute(''' SELECT osm_id FROM planet_osm_line WHERE highway = %s ''', (highway, )) for (osm_id, ) in cursor.fetchall(): if osm_id < 0: # in rendering DBs, this is a relation os.system(f"librewolf -P default 'https://www.openstreetmap.org/edit?relation={-osm_id}'") else: os.system(f"librewolf -P default 'https://www.openstreetmap.org/edit?way={osm_id}'") if __name__ == '__main__': main()
It is quite inefficient, but what I want is to edit the errors, not to write a script :) This requires a rendering database, which I already have locally :)
From here the workflow is:
- Analyze the type of error.
- This includes looking at the history of the object.
- Search the wiki.
- Correct the error or leave a note.
- Find the original changeset and leave a note if needed.
- Add any details to te changeset if needed.
In my machine, finding the long tail, and finding each set of errors takes one minute, so I was launching two at the same time. One of the things to notice is that if the object you try to edit does no exists anymore, you get and edit view of the whole planet.