overpass-api ways query include coordinates - openstreetmap

I'm trying to query Hotels in a specific area. Unfortunately I need to query nodes and ways, because some Hotels are only stored as way and some as nodes.
http://overpass.osm.rambler.ru/cgi/interpreter?data=%28way[tourism~hotel]%28around:5000,50.10707,8.76040%29%29;out;
The result of a way-query doesn't contain any coordinates, only lots of node-refs:
<nd ref="1438833423"/>
Is there a way also to include the coordinates of the nodes in the output or do have to start lots of additional queries for each node?
Tom

Yes, there are several ways to also get geometries for non-node features via the Overpass API. The easiest is probably to use the center output mode (replace out; with out center;): http://overpass-turbo.eu/s/4O4. Other options would be to fetch the node references in a recursion step: http://overpass-turbo.eu/s/4O5 or using the full geometry output mode.
PS: Don't forget that a hotel can also be mapped as a (multipolygon) relation in OSM, not just as a node or way.

Necromancing.
And to actually answer the question:
[out:json];
way(29858799);
out ids geom;
Which will give you the geometries for each point in the selected way.
{
"version": 0.6,
"generator": "Overpass API",
"osm3s": {
"timestamp_osm_base": "2017-10-06T13:59:02Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "way",
"id": 29858799,
"bounds": {
"minlat": 47.3604067,
"minlon": 8.5342631,
"maxlat": 47.3612503,
"maxlon": 8.5352457
},
"geometry": [
{ "lat": 47.3612503, "lon": 8.5351944 },
{ "lat": 47.3612252, "lon": 8.5342631 },
{ "lat": 47.3610145, "lon": 8.5342755 },
{ "lat": 47.3610212, "lon": 8.5345227 },
{ "lat": 47.3606405, "lon": 8.5345451 },
{ "lat": 47.3606350, "lon": 8.5343411 },
{ "lat": 47.3604067, "lon": 8.5343545 },
{ "lat": 47.3604120, "lon": 8.5345623 },
{ "lat": 47.3604308, "lon": 8.5352457 },
{ "lat": 47.3606508, "lon": 8.5352328 },
{ "lat": 47.3606413, "lon": 8.5348784 },
{ "lat": 47.3610383, "lon": 8.5348551 },
{ "lat": 47.3610477, "lon": 8.5352063 },
{ "lat": 47.3612503, "lon": 8.5351944 }
]
}
]
}
https://overpass-turbo.eu/
All the options for out are listed here:
https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Print_.28out.29

Related

How to show nodes and ways on OpenStreetMap using Leaflet?

I was able to correctly query data from the OSM API.
Then, I've been able to show nodes on the map with the following codes:
for (let i = 0; i < data.elements.length; i++) {
let pos;
let marker;
const e = data.elements[i];
if (e.id in this._ids) {
continue;
}
this._ids[e.id] = true;
if (e.type === 'node') {
pos = L.latLng(e.lat, e.lon);
}
else{
pos = L.latLng(e.center.lat, e.center.lon);
}
if (this.options.markerIcon) {
marker = L.marker(pos, { icon: this.options.markerIcon });
}
else {
marker = L.circle(pos, 80, {
stroke: false,
fillColor: '#0000ff',
fillOpacity: 0.9
});
}
}
which gives me the following visual output:
MyOutput-Image
How can I also show lines how it is done on OverpassTurbo:
OverpassTurbo-Image
What does your OSM API query looks like? I assume it's an overpass query, in which case, you might have put an out center at the end, which returns the center of each way.
Over pass out statement :
center: This adds only the centre of the above mentioned bounding box to ways and relations. Note: The center point is not guaranteed to lie inside the polygon (example).
Therefore, each way has a long/lat which is in the middle, which is what you plot as a marker using the e.center.lat
example of a way with out center :
{
"type": "way",
"id": 2263973,
"center": {
"lat": 51.5070645,
"lon": -0.1359499
},
"nodes": [
9789823,
9789817,
3933850766,
...
],
"tags": {...}
}
You could either go through each associated node, and look them up and get the lat and lon. Or use the out geom option which returns the coordinates or the nodes directly:
{
"type": "way",
"id": 2263973,
"bounds": {
"minlat": 51.5064574,
"minlon": -0.1363268,
"maxlat": 51.5076716,
"maxlon": -0.1355731
},
"nodes": [
9789823,
9789817,
...
],
"geometry": [
{ "lat": 51.5064574, "lon": -0.1355731 },
{ "lat": 51.5069432, "lon": -0.1360143 },
{ "lat": 51.5072896, "lon": -0.1363027 },
{ "lat": 51.5073314, "lon": -0.1363255 },
{ "lat": 51.5073531, "lon": -0.1363268 },
{ "lat": 51.5073965, "lon": -0.1363228 },
{ "lat": 51.5074324, "lon": -0.1363027 },
{ "lat": 51.5074691, "lon": -0.1362638 },
{ "lat": 51.5076716, "lon": -0.1356893 }
],
"tags": {...}
}
Notice how you also get the min and max values for latitude and in longitude in a bounds attribute. You can then go through the geometry array, extract all the lat and lon in a latlngs array, and use:
var polyline = L.polyline(latlngs, {color: 'blue'}).addTo(map); to draw a line. See Leaflet doc on polyline
And you can get this, for [highway~motorway]

Getting speed limit based on a single coordinate using here REST API

I want to retrieve speed limit based on a single coordinate(of a road in the USA) using HERE REST API(not PDE). So, I only got the api_key(no app code). I searched and found some solutions which were deprecated and required the PDE api. If anybody knows the latest solution please let me know. Thanks. Anyway I got something which gives speed limit for two coordinates(not my case) and if I put the two coordinates same I get the wrong(very small) value for speed limit. which is given bellow:
https://router.hereapi.com/v8/routes?apiKey=APP_KEY&transportMode=car&origin=-37.956650,145.220673&destination=-37.956650,145.220673&spans=speedLimit&return=polyline
{
"routes": [
{
"id": "0a903f38-aecd-4850-a87e-0848c7583b8a",
"sections": [
{
"id": "4aa23cb0-0209-4e31-bca8-32f4cfb9f98e",
"type": "vehicle",
"departure": {
"time": "2021-02-25T12:52:34+11:00",
"place": {
"type": "place",
"location": {
"lat": -37.9566675,
"lng": 145.2206532
},
"originalLocation": {
"lat": -37.9566501,
"lng": 145.220673
}
}
},
"arrival": {
"time": "2021-02-25T12:52:34+11:00",
"place": {
"type": "place",
"location": {
"lat": -37.9566675,
"lng": 145.2206532
},
"originalLocation": {
"lat": -37.9566501,
"lng": 145.220673
}
}
},
"polyline": "BG1j2soC6iy_0IAA",
"spans": [
{
"offset": 0,
"speedLimit": 27.7777786
}
],
"transport": {
"mode": "car"
}
}
]
}
]
}
Is there any latest rest api service provided by Here that gives speed limit for a geo coordinate(not the pde one)?

get latitude and longitude from node id in overpass API

I use this query to get the latitude and longitude from node id in overpass API:
[out:json]; (
node(2314028892);
node(30223035);
node(268195434);
node(30223039);
); (._;>;); out;
I get this answer:
{
"version": 0.6,
"generator": "Overpass API 0.7.55.3 9da5e7ae",
"osm3s": {
"timestamp_osm_base": "2018-06-28T07:47:01Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "node",
"id": 30223035,
"lat": 52.2917680,
"lon": 10.5265481
},
{
"type": "node",
"id": 30223039,
"lat": 52.2894248,
"lon": 10.5268394
},
{
"type": "node",
"id": 268195434,
"lat": 52.2897618,
"lon": 10.5267852
},
{
"type": "node",
"id": 2314028892,
"lat": 52.2919739,
"lon": 10.5265271,
"tags": {
"bus": "yes",
"name": "Rühmer Weg",
"network": "VRB",
"operator": "Braunschweiger Verkehrs-GmbH",
"public_transport": "stop_position",
"ref": "464"
}
}
]
}
It seems that the elements in the answer have another order. I would like to now if I can get the answer in the same order as in the query. (First the node 2314028892, then 30223035, ... )
Anybody has any idea how could I get this done?
Use "out" after each query statement:
[out:json];
node(2314028892);out
node(30223035);out
node(268195434);out;
node(30223039);out;
For performance reasons, I would recommend to do this as post processing step on your end. You already know the correct sequence, so you can easily apply this to the query result. Also, you can specify multiple node id values in a single query:
[out:json]; node(id:2314028892, 30223035, 268195434, 30223039);out;
Side note: you can also leave out (._;>;); in your query. It's not needed in case of nodes.

Can I retrieve house number on mapbox reverse geocoder?

Currently when I would like to retrieve address for coordinates I make following request as an example:
GET http://api.tiles.mapbox.com/v3/examples.map-zr0njcqy/geocode/-114.0701,51.0495.json
I get address information up to the street level but NO house number. Is there way to retrieve it as well? I think it's such an obvious need and cannot think of any problems extracting this date when you already extracted the rest.
{
"attribution": {
"mapbox-places": "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox © OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>"
},
"query": [
-114.0701,
51.0495
],
"results": [
[
{
"id": "street.31973701",
"lat": 51.0476559,
"lon": -114.0703042,
"name": "3 St SW",
"type": "street"
},
{
"bounds": [
-114.36183200000002,
50.84361600000001,
-113.87432100000002,
51.217528999999985
],
"id": "mapbox-places.10008775",
"lat": 51.03095,
"lon": -114.108491,
"name": "Calgary",
"type": "city"
},
{
"bounds": [
-120.00138351899996,
48.99667665000002,
-110.004763853,
60.00042158400004
],
"id": "province.2553712403",
"lat": 54.872006,
"lon": -115.003552,
"name": "Alberta",
"type": "province"
},
{
"bounds": [
-141.00275000000013,
40.043430830999895,
-47.69751888999983,
86.45371111000011
],
"id": "country.1833980151",
"lat": 76.304456,
"lon": -105.801333,
"name": "Canada",
"type": "country"
}
]
]
}
#rbrundritt is correct.
Most mapping applications (Google, Bing, etc) merely interpolate the location when given a street address. They are aware of the starting and ending address on a given block and then make an educated guess as to where the address you are search for is located on that block based on that. They don't actually store the outlines and the addresses of each property.

iOS Find Location (Latitude,longitude) from Zipcode

What could be the best way to get location for a given zipcode. Would it work for countries outside US/Canada .Thanks
Use the Google geolocating API (try it out on google.com/maps):
Input for a Swiss ZIP code for example:
CH-9014
or a french one:
FR-34000
or german:
de-12101
or US:
us-90210
or canada:
ca-J5Z 1A1
or china:
cn-100000
for example:
yields
{
"status": "OK",
"results": [ {
"types": [ "postal_code" ],
"formatted_address": "9014 St Gallen, Switzerland",
"address_components": [ {
"long_name": "9014",
"short_name": "9014",
"types": [ "postal_code" ]
}, {
"long_name": "St Gallen",
"short_name": "St Gallen",
"types": [ "locality", "political" ]
}, {
"long_name": "Sankt Gallen",
"short_name": "SG",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "Switzerland",
"short_name": "CH",
"types": [ "country", "political" ]
} ],
"geometry": {
"location": {
"lat": 47.4082855,
"lng": 9.3323890
},
"location_type": "APPROXIMATE",
"viewport": {
"southwest": {
"lat": 47.3991076,
"lng": 9.3180504
},
"northeast": {
"lat": 47.4199564,
"lng": 9.3543340
}
},
"bounds": {
"southwest": {
"lat": 47.3991076,
"lng": 9.3180504
},
"northeast": {
"lat": 47.4199564,
"lng": 9.3543340
}
}
}
} ]
}
So the swiss ZIP code 9014 corresponds appx. to this location:
"lat": 47.4082855,
"lng": 9.3323890
See my answer on the geolocating API here:
How to get GLatLng object from address string in advance in google maps?
GeoNames offers a number of various zipcode geocoding services, including search for the location of a given zipcode. They support a number of various countries.
You would probably be most interested in the Placename Lookup for postalcode service
Google's API comes with some fairly nasty restrictions. Better to use open sources like GeoNames per #Claus Broch's suggestion.
I'm adding this answer to also note that MapQuest has recently put up an API to OpenStreetMap data. It doesn't do (as far as I can tell) zip code searching, but location names, directions, altitude etc are all freely queryable. I recently discovered it an I plan on replacing my calls to google maps API with it as soon as I can.
http://developer.mapquest.com/web/products/open