Hi

First let me say that I am fairy new to OSM and the Overpass api. So forgive my ignorance ;)

I'm working on a small private app where I want to get information about the road I am currently driving on. I am using the following query to get information about the road from the phones current location:

< osm-script>
    < query type="way">
        < around lat="56.09383" lon="9.00309" radius="5"/>
        < has-kv k="highway"/>
    < /query>
    < union>
        < item />
        < recurse type="way-node"/>
    < /union>
    < print order="quadtile"/>
< /osm-script>

In the example above i get the way: "Midtjyske Motorvej" with ID=111435507 I am not sure if this is the best way to do it, but it seems to work quite good for now.

Because I do not want to query Overpass every single second, but still want the information to be rather accurate, I thought about trying to make the app make an educated guess about where I'm heading, and then cache some of this information locally.

So I want the app to query via the overpass API, and then find for example the next 10 adjacent ways (or the next x adjacent ways within a 2 KM radius) of the current way i'm driving on. If for instance I was driving south on the above road: "111435507", the immediate next adjacent way would be: "111435449", the next one would be: "111435478" etc. Is it possible to create one query that can get all the adjacent ways like this?

I don't expect the API to handle direction/course, so I guess I will have to do that calculation my self, and figure out which end point of the way I want to start from - so to speak. But if it is possible, that would of course be great :)

Thanx in advance!

...Allan

asked 28 Sep '13, 21:13

as_dk's gravatar image

as_dk
26113
accept rate: 0%


Although it looks a bit weird this will give you the next 5 adjacent roads for way id 111435507.

[bbox:{{bbox}}];
way(111435507);
(way(around:0)[highway~"."][highway!~"path|track|cycleway|footway"];(._;>;))->.a;
(way(around:0)[highway~"."][highway!~"path|track|cycleway|footway"];(._;>;))->.b;
(way(around:0)[highway~"."][highway!~"path|track|cycleway|footway"];(._;>;))->.c;
(way(around:0)[highway~"."][highway!~"path|track|cycleway|footway"];(._;>;))->.d;
(way(around:0)[highway~"."][highway!~"path|track|cycleway|footway"];(._;>;))->.e;
(.a;.b;.c;.d;.e;);out;

Try it on Overpass Turbo

Note that "around" has no concept of directly connected roads, so you will get some roads which are only crossing the motorway. You will have to manually filter those out in a post processing step.

Edit: Global bbox added to restrict your search to the area you're interested in. Otherwise really long ways will cause some far away data to be fetched.

permanent link

answered 21 Apr '14, 11:50

mmd's gravatar image

mmd
5.6k4988
accept rate: 37%

edited 25 Apr '14, 18:16

Silly question : the radius is one parameter in your current query (expressed in meters). Why simply not change this 'radius' from '5' to '2000' ?

Then you will retrieve all highways within the circle. Then you will have to build a function retrieving the nearest highway from the current phone position (this will depend how you store the geodata in your app but they are plenty of geo-libs doing this for you).

permanent link

answered 30 Sep '13, 14:32

Pieren's gravatar image

Pieren
9.7k2075157
accept rate: 15%

Thanks for the answer :)

I have of course already tried that and it also works fine. But I really want the response data to be as minimal as possible and only return what I need in order to save bandwidth on the mobile device. With a radius of 2km I get about 200Kb at the location in the previous message. Upping that to 5km gives 1Mb – still semi ok I guess. But in a bigger city like (55.703956,12.518066) I get 1Mb of data for only 2 km and 7mb with 5 Km. A lot of data when I know I will only need a small part of that in the current request.

(01 Oct '13, 16:04) as_dk

I really only want to get connecting (better word perhaps than adjacent ways I guess) ways, and nothing else. And preferably only ways at the endnodes, so I don’t get side roads etc.

I’m sorry I did not make that clear in my question.

(01 Oct '13, 16:04) as_dk
1

You can edit and improve your question at any time. I'm surprised by the size of the data. Perhaps the radius should vary with the speed. In urban and dense areas, the speed is necessarily smaller than in country side.

(01 Oct '13, 16:36) Pieren
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:

×355
×139
×64

question asked: 28 Sep '13, 21:13

question was seen: 5,417 times

last updated: 25 Apr '14, 18:16

powered by OSQA