This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

overpass - get way direction

2

Thinking about how to visualize the direction of a way in mapcontrib or umap instance using an Overpass query: it might be done by querying the second node of a way. If you overlay that node on the way itself, it can show you where it begins. Maybe again for the second-last. (Not the first and last nodes, because they would often overlap with the nodes of an adjacent way)

Say I want to show the direction of highways that don't have a oneway tag in this way, how would I go from this basic query?

[out:json][timeout:25];
(
  way["highway"][!"oneway"]({{bbox}});
);
out body;
>;
out skel qt;

If you have a better idea to approach the problem, do go ahead.

asked 10 Feb '17, 07:49

joost%20schouppe's gravatar image

joost schouppe
3.4k245087
accept rate: 12%


One Answer:

2

visualize the direction of a way

The optimal solution for this would be to make the displaying software (here: umap) render the direction of the lines for one.

[…] by querying the second node of a way.

The Overpass API doesn't (yet?) support nth-child queries for way-nodes (or relation members).

But you could do this in post-processing: After converting the Overpass result to GeoJSON, run something like the following (in nodejs):

var geojson = … geojson.features.forEach(f => { if (f.geometry.type !== "LineString") return; var newcoords = [0,0], coords = f.geometry.coordinates; newcoords[0] = coords[0][0]*0.75+coords[1][0]*0.25; newcoords[1] = coords[0][1]*0.75+coords[1][1]*0.25; geojson.features.push({type:'Feature', properties:{}, geometry:{type:'Point', coordinates:newcoords}}); });

After that, there are additional point features in the geojson which are placed near the start point of each LineString (1 quarter distance towards the second vertex).

answered 23 Feb '17, 16:24

tyr_asd's gravatar image

tyr_asd
1.2k51927
accept rate: 64%

Thanks for the help!

(24 Feb '17, 07:48) joost schouppe

Source code available on GitHub .