I have a lot of GPS coordinates. How can I find the respective element id according the GPS data? (I can not use the webpage and per the mouse click on the query button, since I have too many points...) For example: Given this GPS coordinate: [51.645401, 12.052744] Return the element id: farmland #6249468 How can I do that? asked 09 Feb '17, 16:12 xirururu edited 09 Feb '17, 18:12 |
One Answer:
The query button on the website is implemented using a publicly available service, Overpass-API: https://wiki.openstreetmap.org/wiki/Overpass_API There is some discussion of it in the website code: (the query language used there is documented at https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL ) You can experiment with Overpass-API using a convenient gui at Overpass Turbo: http://overpass-turbo.eu/s/mC9 I've only added a piece of the query there, the is_in operator returns a subset of nearby objects, you'd need to add the around operators and experiment a bit to see if the output is useful for what you need. answered 09 Feb '17, 23:52 maxerickson |
@maxerickson Thanks so much for the answer! Run your is_in() function works perfectly. But how can I write the nearby function? According your query.js file, I made the nearby function. But it doesn't work.
(node(around:100, 51.645401, 12.052744); way(around:100, 51.645401, 12.052744));
out tags;
relation(around:10, 51.645401, 12.052744); out;
Here is my code in overpass-turbo
http://overpass-turbo.eu/s/mCa
There are no features within the 100 meter radius. Increasing it returns some features (200 works for nodes).
Also get rid of the
tags
from the output statement. That removes the geographic information from the results.out geom
will add geographic information for ways and relations.http://overpass-turbo.eu/s/mCd
@maxerickson Thanks! I still have a little doubt, The gps point [51.645401, 12.052744] is actually in the "Farmland #6249468", but why it returned as a nearby feature?
The areas that the is_in operator returns are generated by Overpass API using a set of rules. For landuse types (and most other features), they are only included as areas if they have a name.
The rules are here: https://github.com/drolbr/Overpass-API/blob/master/src/rules/areas.osm3s