Get the name of a street and maxspeed given a node id

69 Views Asked by At

I need to obtain the name and maxspeed given the node id.

I can obtain that using the latitude and longitude, but I don’t know how do this using a node id. Example:

https://overpass-api.de/api/interpreter?data=[out:json];way[maxspeed](around:5.0,36.6870970,-4.4531804);out%20center;

Output

{
    "version": 0.6,
    "generator": "Overpass API 0.7.61.5 4133829e",
    "osm3s": {
        "timestamp_osm_base": "2023-10-13T14:02:30Z",
        "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
    },
    "elements": [
        {
            "type": "way",
            "id": 60727865,
            "center": {
                "lat": 36.6880970,
                "lon": -4.4541804
            },
            "nodes": [
                746325927,
                3650408717,
                7067178413,
                3547298108,
                3650408715,
                760219855,
                5245547649,
                5417047626,
                3650408712,
                760219851
            ],
            "tags": {
                "cycleway:right": "shared_lane",
                "highway": "primary",
                "lanes": "2",
                "lit": "yes",
                **"maxspeed": "50",**
                "name": "Avenida Molière",
                "oneway": "yes",
                "parking:right:orientation": "diagonal",
                "sidewalk": "right",
                "surface": "asphalt"
            }
        }
    ]
}

The sense is that I can obtain the nodes using the /nearest/ query of the OSRM API. The idea is obtain the nearest point and its node id, and the attack Overpass API with the node id to obtain the maxpspeed information.

Solved

https://overpass-api.de/api/interpreter?data=[out:json];node(id:5417047626);out;

This better:

https://overpass-api.de/api/interpreter?data=[out:json];node(id:5417047626);way(bn);out geom;
1

There are 1 best solutions below

0
user1857654 On
#!/usr/bin/env python
import requests
osrm_url = "https://router.project-osrm.org/route/v1/driving/36.6880970,-4.4541804?nearest"
osrm_response = requests.get(osrm_url)
osrm_json = osrm_response.json()
if "waypoints" not in osrm_json:
    print("No nodes near the specified latitude and longitude")
    exit(1)
node_id = osrm_json["waypoints"][0]["nodes"][0]
overpass_url = "https://overpass-api.de/api/interpreter?data=[out:json];node(id={node_id});out skeleton;"
overpass_response = requests.get(overpass_url.format(node_id=node_id))
overpass_json = overpass_response.json()
node = overpass_json["elements"][0]
name = node["tags"]["name"]
maxspeed = node["tags"]["maxspeed"]
print(name, maxspeed)