I'm new to Overpass API and I need an Overpass QL query that gets a way of type highway by osm_id and also gets the previous and the next way. By previous way I mean all ways with type highway whose last node is the same as the first node of the original way. And with next way I mean all ways whose first node are the same as the last node of the original way.
I have tried (with the help of Chat GPT admittedly) the following query:
[out:json];
way(805290645)->.way;
node(w.way.nodes[0])->.first;
node(w.way.nodes[-1])->.last;
way(around:0.1, .first.last, meta)["highway"]->.next;
way(around:0.1, .last.first, meta)["highway"]->.prev;
(
way(805290645);
.next;
.prev;
);
out meta;
But this returns only the 'original way' way(805290645)
. Like this:
{
"version": 0.6,
"generator": "Overpass API 0.7.59 e21c39fe",
"osm3s": {
"timestamp_osm_base": "2023-02-24T12:38:23Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "way",
"id": 805290645,
"timestamp": "2022-10-05T00:46:15Z",
"version": 10,
"changeset": 127021576,
"user": "A67-A67",
"uid": 553736,
"nodes": [
44390230,
9802326146,
2935854435,
9802326142,
9904639298,
9904639299,
3946339905,
5768131540
],
"tags": {
"access:lanes": "no|no|yes|yes",
"carriageway_ref": "Li",
"highway": "motorway",
"int_ref": "E 25",
"lanes": "4",
"maxspeed": "100",
"maxspeed:conditional": "130 @ (19:00-06:00)",
"noname": "yes",
"official_name": "Rijksweg nr 20",
"oneway": "yes",
"operator": "Rijkswaterstaat",
"overtaking:hgv:conditional": "no @ (Mo-Fr 06:00-19:00)",
"ref": "A20",
"source:official_name": "BAG;NWB",
"surface": "asphalt",
"turn:lanes": "slight_left|slight_left|slight_right|slight_right"
}
}
]
}
Can anyone help me fix this query?
I suggest the following as starting point, which isn't exactly what you've asked for, but way better what ChatGPT offers as a solution (which is in fact invalid Overpass QL syntax):
way(805290645);
node(w:1,-1); // get first and last node of way
out; // print first / last node
way(bn)[highway]; // find highway=* ways which include first/last node
out geom; // print those ways
You can also filter out way 805290645:
way(805290645)->.w;
node(w.w:1,-1);
out;
(way(bn)[highway]; - way.w;);
out geom;
Getting adjacent ways can also be accomplished by using the complete statement. This github issue highlights a few use cases: https://github.com/drolbr/Overpass-API/issues/95