Python wrapper to run requests on the endpoint of overpass-API

后端 未结 1 881
梦毁少年i
梦毁少年i 2021-01-14 22:11

we have with Overpass API python wrapper a thin Python wrapper around the OpenStreetMap Overpass API https://github.com/mvexel/overpass-api-python-wrapper

we have so

相关标签:
1条回答
  • 2021-01-14 22:33

    You can try this.

    import overpass    
    
    api = overpass.API()
    query = """
    [out:csv(::id,::type,"name","addr:postcode","addr:city",
    "addr:street","addr:housenumber","website"," contact:email=*")][timeout:30];
    area[name="Madrid"]->.a;
    ( node(area.a)[amenity=hospital];
      way(area.a)[amenity=hospital];
      rel(area.a)[amenity=hospital];);
    out;
    """
    resp = api._get_from_overpass(query)
    data = [row.split('\t') for row in resp.text.split('\n')]
    

    Output:

    for x in data[:5]:
        print(x)
    
    # ['@id', '@type', 'name', 'addr:postcode', 'addr:city', 'addr:street', 'addr:housenumber', 'website', ' contact:email=*']
    # ['597375537', 'node', 'Centro de especialidades Emigrantes', '', '', '', '', '', '']
    # ['1437313175', 'node', '', '', '', '', '', '', '']
    # ['1595068136', 'node', '', '', '', '', '', '', '']
    # ['2320596216', 'node', '', '', '', '', '', '', '']
    

    Or

    api = overpass.API()
    query = """
    area[name="Madrid"]->.a;
    ( node(area.a)[amenity=hospital];
      way(area.a)[amenity=hospital];
      rel(area.a)[amenity=hospital];);
    """
    fmt = 'csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website"," contact:email=*")'
    data = api.get(query, responseformat=fmt)
    

    Output:

    for x in data[:5]:
        print(x)
    
     # ['@id', '@type', 'name', 'addr:postcode', 'addr:city', 'addr:street', 'addr:housenumber', 'website', ' contact:email=*']
     # ['597375537', 'node', 'Centro de especialidades Emigrantes', '', '', '', '', '', '']
     # ['1437313175', 'node', '', '', '', '', '', '', '']
     # ['1595068136', 'node', '', '', '', '', '', '', '']
     # ['2320596216', 'node', '', '', '', '', '', '', '']
    
    0 讨论(0)
提交回复
热议问题