OpenStreetMap logo OpenStreetMap

OverpassQL for downloading bus roads and bus stops data into JOSM

Posted by eternaltyro on 2 February 2022 in English. Last updated on 5 February 2022.

Background and context šŸ—ŗļø

Iā€™ve been using JOSM to map missing public transport routes in Chennai. Itā€™s a project Iā€™ve been doing for personal reasons which I intend to elaborate in another post and I began with iD only to find later that the order of the route segments matter and iD doesnā€™t make it easy to do reorder segments.

So I started using JOSM with a helper plugin I found. This has made my workflow much easier and faster. One small annoyance though is that I could only download a small section of a fairly large city to edit the map in JOSM. I discovered I could download larger areas if I carefully picked specific ways or nodes since the limitation (to downloading data) is the total size of data that OSM can return.

So I went and searched the web for examples of OverpassQL and their explanations, learned what I could about how the QL works in the time I had and strung together a quick and dirty query that downloads ONLY roads and bus stops within the bounding-box (that I get to easily draw in JOSM).

This probably could be improved for concision. This is the OverpassQL I use to download roads and existing relations in order for me to map bus routes using JOSMā€™s overpass-based data import dialogue window.


[out:xml][timeout:90][bbox:{{bbox}}];
(
  wr["highway"="primary"];
  wr["highway"="primary_link"];
  wr["highway"="secondary"];
  wr["highway"="secondary_link"];
  wr["highway"="tertiary"];
  wr["highway"="tertiary_link"];
  wr["highway"="trunk"];
  wr["highway"="trunk_link"];
  node["highway"="bus_stop"];
  node["bus"="yes"];
  node["public_transport"="platform"];
  node["public_transport"="stop_position"];
);
(._;>;);
out meta;

This has some nice conveniences for me:

  1. It does not download residential roads and therefore does not clutter the viewport
  2. Does not download railway lines
  3. I can download a fairly large area - usually the size of an entire city.
  4. I can do batch / scripted editing of bus stops to add tags (put down your pitchforks - I realized my mistakes early on and have stopped clobbering othersā€™ work unless absolutely necessary)
  5. I can save my JOSM session and not have it eat up a lot of my disk space.

Explanation of the QL

  • nwr is short form for a combination of nodes, ways and relations. Itā€™s basically an OR clause.
    • Other available combos are nw, nr, and wr.
    • Then of course, there are standalone keywords for node, way, and relation.
  • Wildcards are done by specifying just the key without the value: node["public_transport"]; matches all values for the key public_transport
  • Maybe I should add the PTv2 stop_area relation: relation["type"="public_transport"]["public_transport"="stop_area"]; to this code??
  • In the areas I edit, there are hardly any motorways so I donā€™t bother adding them unless I find a missing section.
    • I could add a wildcard for highways, but I donā€™t want the viewport cluttered, so..
  • āš ļø The parentheses groups the queries, if you remove it, only results matching the last statement will be returned.

Notes:

The size on disk for an empty roads-and-bus-stops-only session is ~7 MiB for a city the size of Chennai which Iā€™m editing currently. But there are not many routes or other relations mapped within the city. Even for a better mapped city like Bangalore or Delhi, I think the size on disk will not exceed ~10 MiB. Donā€™t quote me on that though.

OverpassQL documentation is not very friendly. Maybe there should be a page with a zillion examples of all combinations that can be written using this QL with explanations for each of them. I dream.

āš ļø I am probably missing deprecated tags for bus stop platformsšŸš‰. But so far, Iā€™m unaware of any.

Addendum1 (05 Feb 2022)

I realized Iā€™m going to have to download relation data more carefully, meaning something like this:


[out:xml][timeout:90][bbox:{{bbox}}];
(
  ... snip ...
  relation["public_transport"="stop_area"];
  relation["route"="bus"];
  relation["route_master"="bus"];
);
(._;>;);
out meta;

I also realized that (quite late šŸ˜–) that I could take advantage of layers in JOSM. Downloading data as a new layer - and renaming it to my convenience - was the way to go. I could hide the layer if it ever gets in the way.

Original post made - 02 Feb 2022

Location: CMWSSB Division 60, Zone 5 Royapuram, Chennai, Tamil Nadu, 600001, India

Discussion

Comment from nickjohnston on 3 February 2022 at 21:28

Thank you for taking the time to improve the map in Chennai :) I was lucky enough to visit the city for a few days in 2019 and enjoyed using OpenStreetMap there.

For OverpassQL documentation, are you aware of Leigh Doddsā€™ excellent Overpass tutorial? He is also building a collection of useful Overpass queries, see the ā€œfor local mappersā€ section as an example.

Comment from ToniE on 4 February 2022 at 10:13

Maybe you want to check the bus route relations using PTNA - Public Transport Network Analysis?

Check it out: https://ptna.opensteetmap.de

I can add support for your area within few minutes.

Comment from ToniE on 4 February 2022 at 10:15

Sorry, wrong URL, typo

https://ptna.openstreetmap.de/

Comment from mmd on 4 February 2022 at 20:25

You can also find plenty of example queries:

Comment from eternaltyro on 5 February 2022 at 17:10

@nickjohnston, @mmd thank you for the links. They are quite useful. Iā€™m currently going through Doddā€™s Overpass Tutorial.

Comment from eternaltyro on 5 February 2022 at 17:11

@ToniE Yes, please. Iā€™m working in the southern parts of India.

Comment from discontinuity on 12 February 2022 at 19:30

This is super cool and helpful! Iā€™ve been working on bus routes, generally where thereā€™s a lot less stuff around, but still - it would be REALLY helpful not to have all this stuff to accidentally select / clutter up the view!

Comment from AgusQui on 20 February 2022 at 18:54

Thanks!

Log in to leave a comment