How to find geo-URI of the center of URL to OSM
Vum mcepl matgedeelt de(n) 8. Dezember 2022 op English. Lescht Aktualiséierung de(n) 24. Dezember 2022I understand that for most members of this community this is offensively primitive, but I have spent an hour ploughing through all APIs, so until https://github.com/mocnik-science/osm-python-tools/issues/70 is fixed perhaps it helps somebody:
# From URL (e.g., "https://www.openstreetmap.org/way/30722274#map=14/49.2925/38.1815")
# to geo-URI of the center of the object: geo:49.2953098,38.1827257
import os.path
import sys
import urllib.parse
from OSMPythonTools.cachingStrategy import CachingStrategy, JSON
from OSMPythonTools.api import Api
from shapely.geometry import shape
CachingStrategy.use(JSON, cacheDir=os.path.expanduser("~/.cache/osm"))
api = Api()
parsed_url = urllib.parse.urlparse(sys.argv[1])
way = api.query(parsed_url.path)
geom = shape(way.geometry())
print(f"geo:{geom.centroid.y:.7f},{geom.centroid.x:.7f}")
Complete program is now hosted at https://sr.ht/~mcepl/osm_where/