[GIS] Get complete coordinates of a road in OSM Overpass API

openstreetmapoverpass-api

I am trying to get a road entire coordinates using this code

<osm-script output="json">
  <id-query ref="32809713" type="way"/>
  <!-- added by auto repair -->
  <union>
    <item/>
    <recurse type="down"/>
  </union>
  <!-- end of auto repair -->
  <print/>
</osm-script>

The problem with this code is, it only takes part of a road, not entire road. What is wrong?

Best Answer

since the road named I5 is segmented in OSM, you have to query the ref value instead of the id of a segment:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“ref="I 5"”
*/
[out:json][timeout:25];
// gather results
(
  // query part for: “ref="I 5"”
  node["ref"="I 5"];
  way["ref"="I 5"];
  relation["ref"="I 5"];
);
// print results
out body;
>;
out skel qt;

You will get some data from Europe as well, which you can filter out by setting a bbox or area selection.

If your road has no reference number, but a name, you can search for that too:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“name="Eastshore Freeway"”
*/
[out:json][timeout:25];
// gather results
(
  // query part for: “name="Eastshore Freeway"”
  node["name"="Eastshore Freeway"];
  way["name"="Eastshore Freeway"];
  relation["name"="Eastshore Freeway"];
);
// print results
out body;
>;
out skel qt;