NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I'm currently using the Overpass API to do some queries that give me a particular Way of interest with highway=residential|unclassified|tertiary|secondary. Now I would like to find the nearest Way with highway=motorway|trunk|primary. I know I could do something like this:

way(123456789)->.myroad;
way(around.myroad:5000)[highway~"^(motorway|trunk|primary)$"];
out qt;

and then process through the results, calculating the distance between each of the returned ways and my original road way and take the shortest one. If none are found I could requery for 10000 meters, etc. But that is not precise enough for my needs. The closest Way in straight overland distance is not necessarily the closest by roads. It may not even connect for dozens of miles due to terrain.

Is there maybe a routing API that could handle this type of need? I'd prefer something that uses OSM data so I could feed it in the way ID for my starting road, but I could just as easily specify a coordinate. I wouldnt be able to specify a definite destination.

As a bonus, I'd also like to be able to do the same thing for other types of map features as well, like nearest (by road distance, not as the crow flies) city/town, bus stop, gas station, etc to the smaller road.

asked 03 Feb '17, 00:37

joshcoady's gravatar image

joshcoady
11112
accept rate: 0%

edited 03 Feb '17, 00:44


I doubt that there is a off the shelf solution but it wouldn't be particularly difficult to do with any of the available routing engines (for example OSRM or graphhopper), you should however probably run your own instance if you are planing to do such queries in a larger way.

permanent link

answered 03 Feb '17, 10:25

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701
accept rate: 18%

Could you give me a push in the right direction? I looked (briefly) at OSRM, but it seemed like I needed to know the destination in order for it to route. Did I miss another way to query for a route? Yes, I'll be doing this on private instances.

(03 Feb '17, 17:34) joshcoady

Yes, you need to know two points. One point is the road you are currently on and the other point the road you found via Overpass API. With OSRM you can check if the road is connected to your road and how long the distance/drive time will be. Needs still a lot of queries in the worst case, though.

(03 Feb '17, 19:07) scai ♦

You're right. I think that should mostly be doable. I think I could do it with a max of 1-2 overpass queries to see if there are a couple highways in the immediate vicinity of the road (maybe 3km then 10km radius). If that results in 1-4 highways, route to each and find the nearest one. If results in zero or 5+ then I'm thinking I could just route to 4 points 200km N, S, E, and W of the road and one of those should eventually use a highway. So a max of 4 routing queries.

(04 Feb '17, 03:31) joshcoady
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×483
×85

question asked: 03 Feb '17, 00:37

question was seen: 2,850 times

last updated: 04 Feb '17, 03:31

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum