Overpass recursion syntax, completely confused - openstreetmap

Can someone help me figure out the correct elements for the overpass recursion parameter? I just can't figure out the configuration and am a bit overwhelmed by the recursion documentation.
What I would like to retrieve is the distance of a location to the most nearby railway track. Therefore, I am trying to query:
Railtracks that go through a radius of 50m around a fixed location and their respective node-ids
Latitude and longitude of all railway nodes that belong to those railtracks
What I got so far is:
http://overpass-api.de/api/interpreter?data=[out:json];way(around:LATITUDE,LONGITUDE)[%22railway%22];(._;node(w););out;
Returns all railway nodes of all railway-ways that go through the radius of 50m of the defined location. However, it also returns nodes that lie outside of the radius.
http://overpass-api.de/api/interpreter?data=[out:json];way(around:50,48.130927,11.561282)[%22railway%22];(._;%3C;);out;
Returns the ways with all node-ids that go through the radius of 50m
Of course, I could now merge the results of both queries, however, it seems like a bit of an overhead. Does anybody know how to achieve a single query for this?

Ok, I think I figured it out. If anybody is similarily confused, here is my solution:
http://www.overpass-api.de/api/interpreter?data=[out:json];way(around:50,LATITUDE,LONGITUDE)[%22railway%22];(._;%3E;);out;

Related

How to compute bounding boxes of specific roads from Overpass api

I have a high volume dataset with keys like this:
lat:6.897585,
long:52.785805,
speed:12,
bearing:144
Basically it is a dataset of records of various trips on cars. The data was stored every few seconds during each trip. The main goal of this project is to be able to visualize only u-turns (turn arounds) on a map. But for now, I am trying to at least show the data on specifc roads. For that, I am using Overpass API
With the help of Overpass Turbo, I can get a dataset with all the roads I need.
However, in the dataset, the road's geometry is represented with LineString type.
My question is, How can I get a bounding box(es) of the roads from Overpass API, so later on, I can display events that happened only on the given roads? Or maybe you have a better solution on how to achieve this?
A bounding box wouldn't be very helpful here, as using it to filter your points would show everything that falls within the box (which could include other nearby roads)
It sounds like getting a buffer around a linestring might get you closer, but could still include points that are within the buffer but not on the road you are inspecting.
The smarter way to do this would be to assign each event to a road segment using some logic based on their attributes/properties, so you don't have to depend on a spatial filter.

Can't extract geo keys when inserting large polygon

I have been battling this for the past 2 days and can't seem to get it working.
I have the polygon in this gist, which I'm trying to insert into collection with '2dsphere' index on the polygon field. I've gone through quite a few itterations, removing some points from the polygon, trying to sort it so that it's 100% counter-clockwise (which resulted in malformed polygon) and mongo still won't let me insert it. The error I'm seeing is just Can't extract geo keys: without any extra information at the end.
I went for help to geo json validator, which told me, that I need to have the first point at the end of the polygon, but that results in a Edges 0 and 395 cross.. I'm kinda getting hopeless, as I have about 1000 of these polygons from external API and can't go through them 1 by 1. Also the wierd thing is, if I swap latitude with longitude, mongo is able to insert them, but that's not a solution, even the documentation says longitude first. And as can be observed in the gist, pretty much every map I tried can display the polygon and I wasn't able to observe any kind of "disruption" or wierd edges.
I would love if someone could point out what's wrong with the polygon or gime me a nudge in the right direction.
Also this probably shouldn't change anything, but I'm using mongoose and I did try to insert this polygon manualy via the mongo shell.

How can I find all nodes around a point that are members of a way with a certain tag?

I would like to find all highway way member nodes in a certain radius. I cannot see how to do this without using intersection, however, that is not in the API. For example I have this:
[out:json];
way(around:25, 50.61193,-4.68711)["highway"];>->.a;
(node(around:25, 50.61193,-4.68711) - .a);
out;
Result set .a contains the nodes I want but also nodes outside the radius - potentially a large number if the ways are long. I can find all the nodes inside the radius I don't need, as returned by the complete query above. Now I can always perform a second around query and do the intersection of the two result sets outside of Overpass. Or I can do another difference:
[out:json];
way(around:25, 50.61193,-4.68711)["highway"];>->.a;
(node(around:25, 50.61193,-4.68711) - .a)->.b;
(node(around:25, 50.61193,-4.68711) - .b);
out;
This gives the result I want but can it be simplified? I'm certain I'm missing something here.
Indeed, your query can be simplified to an extent that we don't need any difference operator at all. I would recommend the following approach:
We first query for all nodes around a certain lat/lon position and a given radius.
Based on this set of nodes we determine all ways, which contain some of the previously found nodes (-> Hint: that's why we don't need any kind of intersection or difference!).
Using our set of highway ways we now look again for all nodes of those ways within a certain radius of our lat/lon position.
In Overpass QL this reads like:
[out:json];
node(around:25, 50.61193,-4.68711);
way(bn)[highway];
node(w)(around:25, 50.61193,-4.68711);
out;
Try it on Overpass Turbo

OpenStreetMap Api call returns empty set

I am trying to call OpenStreetMap API:
http://api.openstreetmap.org/api/0.6/map?bbox=43.65,-79.38,43.66,-79.37
It returns no error, but map is empty:
Do you have any ideas why?
thanks
I think for the given request, the empty dataset delivered is actually the correct response.
The API documentation says api/0.6/map returns
All nodes that are inside a given bounding box and any relations that reference them.
All ways that reference at least one node that is inside a given bounding box, any relations that reference them [the ways], and any
nodes outside the bounding box that the ways may reference.
All relations that reference one of the nodes, ways or relations included due to the above rules. (Does not apply recursively, see
explanation below.)
As far as I can see, your bounding box selects a bit of Antarctica. What data did you expect?
I guess, in OSM, Antarctica is just a way, describing its outline (and maybe some research stations somewhere). If you now ask for an area in the middle of nowhere there, there are no data to get. This is because within your bbox there are no nodes. The way for the outline/area of Antarctica is only fetched if at least one of its nodes lies within your bounding box.
PS: If you want a piece of Toronto (with lots of data), swap longitude and latitude values :)
https://wiki.openstreetmap.org/wiki/Download#Construct_a_URL_for_the_HTTP_API
it says the bounding box can only be 0.5 by 0.5 degrees. it also says you might want to try XAPI for such a large area

How to find all points away from some polygon?

What I need is to find all points away from rectangle for 10km. Points geometry is the_geom1, rectangles (polygon) geometry is the_geom2. SRID of them is 4258.
I tried:
SELECT *
FROM table1,table2
WHERE ST_DWithin(table1.the_geom1,table2.the_geom2,10000)
and table1.gid=2;
But the result is not Ok. I get way too many results (everything is returned).
What am I doing wrong?
Your query should work. The big issue may be as described in https://gis.stackexchange.com/questions/32711/how-do-i-use-st-dwithin-with-meters which discusses unit conversion issues.
You may have an issue with unit selection or configuration.
If you are telling it, for example, that the geometries must be within 10000 miles, you would get just about everywhere. Even 10000km would likely return everything on the same continent.