I’m interested in creating a map that highlights an entire US highway route (for example, US-127). Something like this from Wikipedia - which unfortunately I can’t just use as it’s only allowed for other Wikimedia projects. I’ve searched around this forum and poked around the documentation, but I’m having a hard time even figuring out where to start. Any advice would be appreciated!
One simple method is to enter into your web browser’s URL the relation (number) of the highway, such as Relation: 99 (northbound) (158012) | OpenStreetMap and seeing that the “orange highlighted selection” on the web page displayed as a result could show what you seek to see. You can also select a different layer to be displayed and the (new) URL will update to contain a layers= tag. This is meant to be easy: the URL is built as
https colon slash slash osm dot org slash relation slash relation-#
(substituting : for colon, / for slash, . for dot and the actual relation number in OSM for relation-#).
This will work only for (sometimes unidirectional, sometimes bidirectional) route relations containing “simply” highway elements, not relations which contain other relations, such as a super-relation that contains both the northbound and southbound route relation (as elements). Trying to display a super relation will display its elements, but the web browser page will not “draw” it / them. You’ll have to click on one of the component (element) relations, “drilling down” one level from the top of the super-relation, and THEN that element WILL be displayed (again, with an “orange highlighted selection,” which can be dismissed by clicking the X in the “panel”).
Then, there is the question of how to find the relation number. Your state may have a wiki that displays tables (for me, this is California/State Highway Relations - OpenStreetMap Wiki ) for highways, but you can also drill down into the map to where you want and then begin to edit (for example, with iD) and select the element that is a member of the route relation, then select (in the editor) the relation. The relation will be shown for you to “Display in OSM.” Click on that, and from there, you either already have or can glean its relation-# and build a URL as above accordingly.
Thanks, that’s a lot more than I knew before! I think if there was a way to display those super-relations then I’d have exactly what I need. For instance, using the US-127 example, I can get the map to display the route in four sections (one for each state, i.e. Michigan) but the entire route is a super-relation.
Anyone have any ideas on how I’d get the whole thing?
When you say “get” the whole thing, you mean “display,” right? I’m assuming the “orange highlighted selection” method gives you what you want displayed, but that super-relation (in this case) limits you to displaying the components only (routes as elements of the super-relation), and that’s not complete enough for you (in this case).
I don’t have an easy one to do this, but “there are methods…” if all you are looking to do is to simply create, say, a screen-dump (.png, .gif…) of the whole highway, once, and then be done. You COULD (with patience and by creating a scratch / throw-away SINGLE relation), make that up using all the elements of the component relations, get your display as I describe before (with the temporary ginormo-single-relation), take your screen shot, then delete the temporary relation you created. But that’s a little unorthodox (as it “temporarily litters” the OSM database) and so I’m not sure I recommend it. But, I have disclosed that it is possible, so, um, yeah.
Postscript: I’ve never done this myself (really), rather, I’m “imagining out loud” to muse a solution. Um, don’t use iD to do this, its relation editor is clunky; I’d recommend JOSM if you consider this.
Let’s not overcomplicate things. This is a very simple overpass query.
[out:json][timeout:180];
rel[type=route][route=road][network="US:US"][ref=127];
(._; >>;);
out skel qt;
Essentially - grab the route relation US:US=127 and then all descendants.
That’s great, thanks! I didn’t even see that something like Overpass Turbo existed when I was looked around before - seems obvious now, of course. Once I went into the settings and selected the “Don’t display small features” option, it looks pretty much like what I was aiming for.
You may also want to look at what AARoads does to display maps of each route, which I know is based on OSM data somehow but I’m not personally that familiar with the specifics.
I’ve done a little more experimentation and discovered Overpass Ultra, which has even more options to play around with. Like this, giving me a green route line on a simple background map:
---
style:
extends: https://api.protomaps.com/styles/v5/white/en.json?key=f8eceeaad6896c92
layers:
- type: line
filter: [==, [geometry-type], LineString]
paint: {line-color: green, line-width: 2}
---
[out:json][timeout:180];
rel[type=route][route=road][network="US:US"][ref=127];
(._; >> ;);
out skel qt;
Unfortunately it doesn’t seem to work well when you zoom out. If you zoom out so you can see the whole route, the line breaks up for some reason (for example, around Cincinnati).
Ah, but it works better if you simplify the query! Got this from an example in the AARoads docs, so thanks much for that reference.
---
style:
extends: https://api.protomaps.com/styles/v5/white/en.json?key=f8eceeaad6896c92
layers:
- type: line
filter: [==, [geometry-type], LineString]
paint: {line-color: green, line-width: 2}
---
[out:json][timeout:180];
rel[route=road][network="US:US"][ref=127];
out geom;
Yes, Ultra does a ton of awesome stuff, and I only know like a tiny fraction of a percent of its capabilities. I did attend this talk on it at State of the Map US about it, which you may find useful as an overview of it:
The AARoads Wiki resorted to this Overpass-based workflow precisely because Wikimedia Maps shut off external access to the geoline and geoshape APIs that power the map overlays on Wikipedia. (You have Pokémon Go tracking websites to thank for Wikimedia’s policy.) As part of this workflow, AARW contributors stash the result of the Overpass query on Wikimedia Commons in GeoJSON format to avoid rerunning a potentially expensive Overpass query every time someone views an article.