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:
- It does not download residential roads and therefore does not clutter the viewport
- Does not download railway lines
- I can download a fairly large area - usually the size of an entire city.
- 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)
- 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
, andwr
. - Then of course, there are standalone keywords for
node
,way
, andrelation
.
- Other available combos are
- Wildcards are done by specifying just the key without the value:
node["public_transport"];
matches all values for the keypublic_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
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!