Separate forward and backward relation in overpass-api

255 views Asked by At

I need to get from overpass-api all the data about one, specific public transport line. Let's say it has a number 148 in my city.

I use something like this example below but this gives me combined ways of forward and backward routes. How can I get them separately?

<osm-script output="json">
  <union>
    <query type="relation">
      <has-kv k="ref" v="148"/>
      <bbox-query s="54.21466404047702" w="18.270263671875" n="54.503143645746924" e="18.840179443359375"/>
    </query>
  
    <recurse type="down" />
  </union>

  <print mode="skeleton" order="quadtile"/>
</osm-script>

1

There are 1 answers

0
dkiselev On BEST ANSWER

You could filter by role: http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Recurse_.28n.2C_w.2C_r.2C_bn.2C_bw.2C_br.29

Here is an example for other route, which have forward and backward ways.

[out:json][timeout:25];

(
  //get relation
  relation["route"="bus"][ref=157]({{bbox}});

  // get ways with particular role
  way(r:"forward");

  // you may also add ways with empty role if you want
  // give role as an empty string
  //way(r:"");

  // get way nodes.
  // We can't use >; operator, because it will recurse to
  // all relation members.
  node(w);
);

out skel qt; 

Try it on overpass-turbo: http://overpass-turbo.eu/s/a4F