[talk-cz] (pro začátečníky) určení středu OSM URL

Matěj Cepl mcepl na cepl.eu
Středa Prosinec 7 18:08:43 UTC 2022


Dobrý den,

chápu, že pro většinu lidí je tohle natolik pritmitivní, že je
to uráží, ale já jsem nad tím prožil hodinu práce, nežli jsem se
všemi těmi API prodral, tak snad to někomu pomůže.

Aneb jak z OSM URL (třeba
"https://www.openstreetmap.org/way/30722274#map=14/49.2925/38.1815")
dojít k geo-URI středu tohoto objektu.

    import urllib.parse
    from OSMPythonTools.cachingStrategy import CachingStrategy, JSON
    from OSMPythonTools.api import Api
    from shapely.geometry import shape

    CachingStrategy.use(JSON, cacheDir=xdg.BaseDirectory.save_cache_path("osm_where"))

    def parse_URL(url):
        api = Api()

        parsed_url = urllib.parse.urlparse(url)
        way = api.query(parsed_url.path)
        geom = shape(way.geometry())
        print(f"geo:{geom.centroid.y},{geom.centroid.x}")

Hezký den,

Matěj
-- 
https://matej.ceplovi.cz/blog/, @mcepl na floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
Two things fill the heart with renewed and increasing awe and
reverence the more often and the more steadily that they are
meditated on: the starry skies above me and the moral law inside
me.
    -- Immanuel Kant: Critique of Practical Reason





Další informace o konferenci talk-cz