A little more digging found me the answer. Executing e.g.
vars(result.get_way(4755884))
gives the internal structure of the way object:
{'_attribute_modifiers': {'changeset': int,
'timestamp': <function overpy.Element.__init__.<locals>.<lambda>>,
'uid': int,
'version': int,
'visible': <function overpy.Element.__init__.<locals>.<lambda>>},
'_node_ids': [26229733,
291529159,
246189513,
2682629060,
291529223,
3723657411,
3723657424,
2018716449,
291530424,
2018716450,
291530803,
26229737,
1741942073,
4100724928,
4100724934],
'_result': <overpy.Result at 0x221fc5b17f0>,
'attributes': {},
'center_lat': None,
'center_lon': None,
'id': 4755884,
'tags': {'bicycle': 'yes',
'highway': 'residential',
'maxspeed': '20 mph',
'name': 'Reedley Road',
'postal_code': 'BS9',
'sidewalk': 'both'}}
I can therefore access the list of raw node IDs using e.g. result.get_way(4755884)._node_ids
.
It seems you forgot to include the union statement (the two round brackets) in your second example. They're necessary to include nodes, ways, and all nodes referred to by ways in your response. If you leave them out, you will only receive an incomplete answer.
( // <<<<<<< start of union statement
node(45.54,9.19,45.55,9.2);
<;
>;
); // <<<<<<< end of union statement
out meta;
To avoid this mistake in the future, you can enter your query in overpass turbo, then hit "Export" -> "raw data directly from Overpass API". This will create a download link suitable for wget right away.
Best Answer
The following description assumes that you have a list of GPS positions, as well as the OSRM map matching service and Overpass API available.
(1) Use OSRM Map Matching service to identify nearest roads for a trip
OSRM Map matching service accepts a list of GPS positions, or some polyline and matches it to the corresponding OSM ways. This will be the first step of the overall process and returns a list of OSM nodes ids for further processing.
Example: http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?annotations=nodes
I used parameter
annotation=nodes
to include all OSM node ids in the result:See https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#match-service for details.
(2) Fetch ways for node ids via Overpass API
Based on the previous result, extract all OSM node ids and pass those node ids to Overpass API. The following query then retrieves all corresponding highways for those node ids:
Overpass turbo link: http://overpass-turbo.eu/s/pOT
Same query including OSM nodes from both legs in OSRM response: http://overpass-turbo.eu/s/pOW - that's actually a trip from Friedrichstraße via Torstraße to Platz der Vereinten Nationen in Berlin, Germany.
Ways according to a list of node ids
To find a way which contains all of a given list of node ids, you can use the following approach:
overpass turbo link: http://overpass-turbo.eu/s/pPq