How to get nodes matching multiple tags with specific value on Overpass QL - openstreetmap

I'm trying to fetch POI's that matched with tourism=museum or historic=memorial from Overpass API.
I tried different queries but cannot find right solution, i'm getting empty response.
Here are not working queries
area["name"="Bursa"];
(node["tourism"="museum"](area););
(node["historic"="memorial"](area););
out center;
area["name"="Bursa"];
(node["tourism"="museum"]|["historic"="memorial"](area););
out center;
I tried theese queries on OverpassTurbo
Thanks, Ersin.

You have to use a named set when performing multiple queries on the same area (which is also just a set). Otherwise the second query will be performed on the result of the first query.
area["name"="Bursa"]->.a;
(
node["tourism"="museum"](area.a);
node["historic"="memorial"](area.a);
);
out center;
Also note that you are just querying for nodes, so your query won't find any museums or memorials added as way or relation. The following query will include those, too:
area["name"="Bursa"]->.a;
(
nwr["tourism"="museum"](area.a);
nwr["historic"="memorial"](area.a);
);
out center;

Related

How can I alias labels (using a query) in Grafana?

I'm using Grafana v9.3.2.2 on Azure Grafana
I have a line chart with labels of an ID. I also have an SQL table in which the IDs are mapped to simple strings. I want to alias the IDs in the label to the strings from the SQL
I am trying to look for a transformation to do the conversion.
There is a transformation called “rename by regex”, but that will require me to hardcode for each case. Is there something similar with which I don't have to hardcode for each case.
There is something similar for variables - https://grafana.com/blog/2019/07/17/ask-us-anything-how-to-alias-dashboard-variables-in-grafana-in-sql/. But I don't see anything for transformations.
Use 2 queries in the panel - one for data with IDs and seconds one for mapping ID to string. Then add transformation Outer join and use that field ID to join queries results into one result.
You may need to use also Organize fields transformation to rename, hide unwanted fields, so only right fields will be used in the label at the end.

How to get all of the way IDs that each node is a part of

So I am trying to build an overpass / osm query that will in effect find me all of the nodes that a part of multiple road segments, or 'ways'. I have a challenge in that I am dealing with somewhat large area (Norfolk VA, 100,000 nodes) so I'm trying to find a somewhat performant query.
This following query is useful in that it provides all of the nodes, something I need to iterate over, as any node could be part of another way:
[out:json][timeout:25];
{{geocodeArea:Norfolk, VA}}->.searchArea;
(
(
way["highway"](area.searchArea);
node(w);
);
);
// print results
out body;
>;
out skel qt;
I also found this query which returns to me every node that is a part of multiple ways. Very useful, however very non-performant query, O(n^2), and scales to an entire city very poorly.
way({{bbox}})->.always;
foreach .always -> .currentway(
(.always; - .currentway;)->.allotherways;
node(w.currentway)->.e;
node(w.allotherways)->.f;
node.e.f;
(._ ; .result;) -> .result;
);
.result out meta;
I think the minimum-useful information I need is to have all of the node IDs returned as they are associated with each way (kinda like a map/dict) but I'm really struggling to figure out if that is a possible to make such a call. Appreciate your input!

How to export the roadmap including traffic_signals and street_lamps of a city?

I would like to get some statistics about the roads, their deployed traffic lights, and the lampposts. Is there any way to get these statistics immediately for Shenzhen (China) city?
Secondly: how can I export the road network of a specific city (i.e., Shenzhen) including traffic_signals and street_lamps?
I have tried this code using Overpass API:
[out:csv(::id,::lat,::lon)][timeout:900];
// gather results
(
node["highway"="street_lamp"](22.6242,113.6371,23.0628,114.5462);
);
// print results
out body;
The query doesn't retrieve any results for Shenzhen's(China) coordinates(22.6242,113.6371,23.0628,114.5462).However, when applying on coordinates of London(51.3941,-0.2774,51.56,0.0879), it works and retrieves.
Moreover, when I do simple query like querying PoI:
[out:json][timeout:10];
// gather results
(
node["leisure"](around: 200,22.5,113.9936701,22.6740047,113.9935278);
);
out body;
It also works although in Shenzhen(China). Any way to retrieve nodes tagged with 'street_lamp' and 'traffic_sign' in Chinese cities (i.e., Shenzhen)?
To query within boundaries, use the id of the city boundary's relation, then use map_to_area and then query with the the (area) filter:
rel(3464353);
map_to_area;
node(area)["highway"="street_lamp"];
out;

Is there a way to get results for an overpass query paginated?

Let's say I want to get restaurants in Berlin and I have this query:
[out:json];
area["boundary"="administrative"]["name"="Berlin"] -> .a;
(
node(area.a)["amenity"="restaurant"];
); out center;
Let's say this result set is too big to extract in just one request to overpass. I would like to be able to use something like SQL's OFFSET and LIMIT arguments to get the first 100 results (0-99), process them, then get the next 100 (100-199) and so on.
I can't find an option to do that in the API, is it possible at all? If not, how should I query my data to get it divided into smaller sets?
I know I can increase the memory limit or the timeout, but this still leaves me handling one massive request instead on n small ones, which is how I would like to do it.
OFFSET is not supported by Overpass API, but you can limit the number of result this is getting returned by the query via an additional parameter in the out statement. The following example would return only 100 restaurants in Berlin:
[out:json];
area["boundary"="administrative"]["name"="Berlin"] -> .a;
(
node(area.a)["amenity"="restaurant"];
); out center 100;
One approach to limit the overall data volume could be to count the number of objects in a bounding box, and if that number is too large, split the bounding box in 4 parts. counting is supported via out count;. Once the number of objects is feasible, just use out; to get some results.
node({{bbox}})["amenity"="restaurant"];
out count;

Gremlin query to find the count of a label for all the nodes

Sample query
The following query returns me the count of a label say
"Asset " for a particular id (0) has >>>
g.V().hasId(0).repeat(out()).emit().hasLabel('Asset').count()
But I need to find the count for all the nodes that are present in the graph with a condition as above.
I am able to do it individually but my requirement is to get the count for all the nodes that has that label say 'Asset'.
So I am expecting some thing like
{ v[0]:2
{v[1]:1}
{v[2]:1}
}
where v[1] and v[2] has a node under them with a label say "Asset" respectively, making the overall count v[0] =2 .
There's a few ways you could do it. It's maybe a little weird, but you could use group()
g.V().
group().
by().
by(repeat(out()).emit().hasLabel('Asset').count())
or you could do it with select() and then you don't build a big Map in memory:
g.V().as('v').
map(repeat(out()).emit().hasLabel('Asset').count()).as('count').
select('v','count')
if you want to maintain hierarchy you could use tree():
g.V(0).
repeat(out()).emit().
tree().
by(project('v','count').
by().
by(repeat(out()).emit().hasLabel('Asset')).select(values))
Basically you get a tree from vertex 0 and then apply a project() over that to build that structure per vertex in the tree. I had a different way to do it using union but I found a possible bug and had to come up with a different method (actually Gremlin Guru, Daniel Kuppitz, came up with the above approach). I think the use of project is more natural and readable so definitely the better way. Of course as Mr. Kuppitz pointed out, with project you create an unnecessary Map (which you just get rid of with select(values)). The use of union would be better in that sense.