OSM : More nodes in a way than defined nodes - openstreetmap

Using OverPass I am requesting all the ways and nodes in a specific area.
The documentation says : "The nodes defining the geometry of the way are enumerated in the correct order, and indicated only by reference using their unique identifier. These nodes must have been already defined separately with their coordinates."
But in the result I get, the definitions of some nodes are missing, as I get some nodes ID child of a way that I can't find in the nodes definition.
Here is my OverPass QL query :
[bbox:{{bbox}}];
(
node;
<;
);
out;
I am missing something ?
Thank you.

Strictly speaking, a solution based on the < (recurse up) statement does not meet your requirements. To find out why, we take a look a the Overpass QL documentation:
The recurse up standalone query is written as a single less than symbol, "<".
It takes an input set. It produces a result set. Its result set is
composed of:
all ways that have a node which appears in the input set; plus
all relations that have a node or way which appears in the input set; plus
all relations that have a way which appears in the result set
You will notice that your query also returns many relations, although in your question you mentioned you wanted only nodes and ways in your result.
A correct query would look as follows. Instead of using <, we're explicitly telling in QL that we only want ways for a set of nodes, and again, all nodes for a set of ways - and nothing else!
(
node({{bbox}});
way(bn);
node(w);
);
out meta;
(Btw: please forget about the Overpass language guide mentioned above. It is incomplete and not maintained at the moment).

Your query doesn't request all "ways and nodes". Instead it just requests nodes and performs a "recurse up" to get ways these nodes are part of. However for these ways you will only obtain the nodes from your initial query. You will need an additional "recurse down" to query for all other nodes these ways consist of:
[bbox:{{bbox}}];
(
node;
<;
);
out body;
>;
out;
Example: https://overpass-turbo.eu/s/FGj

Related

How to find nodes within ways in Overpass QL?

I have a query which returns a number of ways. I want to find nodes matching certain criteria which appear within those ways. Note that the nodes I'm interested in do not form part of the way itself, but do appear within the bounds of the way. Also, the ways do not all have corresponding areas, so using the area search doesn't work in all cases.
I've got a minimal example which finds way 95677318, and I want to be able to find node 1552949334:
(
way({{bbox}})["man_made"="lighthouse"];
)->.searchArea;
/*doesn't work:*/
/*node(area.searchArea)["seamark:name"];*/
/*recur down and find node directly, just for the purpose of this question*/
(
.searchArea;>;
node({{bbox}})["seamark:name"];
);
out;
(Try it on https://overpass-turbo.eu/s/EpV)
This feature is not yet available as of release 0.7.55. In case there's no corresponding area available on the Overpass server, this kind of query is simply not feasible.
See https://github.com/drolbr/Overpass-API/issues/77 for details.

what is the best way to retrive information in a graph through has Step

I'm using titan graph db with tinkerpop plugin. What is the best way to retrieve a vertex using has step?
Assuming employeeId is a unique attribute which has a unique vertex centric index defined.
Is it through label
i.e g.V().has(label,'employee').has('employeeId','emp123')
g.V().has('employee','employeeId','emp123')
(or)
is it better to retrieve a vertex based on Unique properties directly?
i.e g.V().has('employeeId','emp123')
Which one of the two is the quickest and better way?
First you have 2 options to create the index:
mgmt.buildIndex('byEmployeeId', Vertex.class).addKey(employeeId).buildCompositeIndex()
mgmt.buildIndex('byEmployeeId', Vertex.class).addKey(employeeId).indexOnly(employee).buildCompositeIndex()
For option 1 it doesn't really matter which query you're going to use. For option 2 it's mandatory to use g.V().has('employee','employeeId','emp123').
Note that g.V().hasLabel('employee').has('employeeId','emp123') will NOT select all employees first. Titan is smart enough to apply those filter conditions, that can leverage an index, first.
One more thing I want to point out is this: The whole point of indexOnly() is to allow to share properties between different types of vertices. So instead of calling the property employeeId, you could call it uuid and also use it for employers, companies, etc:
mgmt.buildIndex('employeeById', Vertex.class).addKey(uuid).indexOnly(employee).buildCompositeIndex()
mgmt.buildIndex('employerById', Vertex.class).addKey(uuid).indexOnly(employer).buildCompositeIndex()
mgmt.buildIndex('companyById', Vertex.class).addKey(uuid).indexOnly(company).buildCompositeIndex()
Your queries will then always have this pattern: g.V().has('<label>','<prop-key>','<prop-value>'). This is in fact the only way to go in DSE Graph, since we got completely rid of global indexes that span across all types of vertices. At first I really didn't like this decision, but meanwhile I have to agree that this is so much cleaner.
The second option g.V().has('employeeId','emp123') is better as long as the property employeeId has been indexed for better performance.
This is because each step in a gremlin traversal acts a filter. So when you say:
g.V().has(label,'employee').has('employeeId','emp123')
You first go to all the vertices with the label employee and then from the employee vertices you find emp123.
With g.V().has('employeeId','emp123') a composite index allows you to go directly to the correct vertex.
Edit:
As Daniel has pointed out in his answer, Titan is actually smart enough to not visit all employees and leverages the index immediately. So in this case it appears there is little difference between the traversals. I personally favour using direct global indices without labels (i.e. the first traversal) but that is just a preference when using Titan, I like to keep steps and filters to a minimum.

Multiple separated requests inside a single request

With OverPass API, I would like to make several different queries in a single one, and then keep the results separated by query in the output.
For example:
node( <some bounding box> )[amenity~"cafe"]->.my_cafes;
node( <some bounding box> )[amenity~"restaurant"]->.my_restaus;
.my_cafes out;
.my_restaus out;
In the XML output, is it possible to keep track of which sub-query a given result is answering to (i.e., "my_cafes" or "my_restaus")? This could avoid sending many API calls.
In my example, output resulting nodes can easily be filtered with something like tag[k=amenity,v=cafe]. But it's not always the case (let's imagine two similar requests, filtered in Overpass with two different around: clauses)
A similar question was already discussed on Github: https://github.com/drolbr/Overpass-API/issues/236
Short summary from the ticket:
Use the following workaround: simply put an out count; after each out; statement. This way you can find out where each query result ends and how many entries it includes.

Overpass relation railway segments

I want to query the Overpass Api to find out the distance of special relations (railways). The request is fine, and returns me all relation, way and node objects I'm interested in. Example for Hamburg:
[out:json];(rel(53.55224324163863, 10.006766589408304, 53.55314275836137, 10.008081410591696)["route"="train"];>;);out body;
In Overpass, each relation object has members defining this relation. For way objects you can resolve the lat/lon of its node attributes and calculate the distance for that way. If you sum up all the way distances it seems to be reasonable.
However, there are members from that relation of the type node (most of the time, they have a role of "stop") which seem to represent the right order of stops from that relation. But instead being in between the members, they are roughly at the end.
If I try to look the stops up inside the ways, they are not all present. How am I supposed to calculate the distance between two particular stops?
There seems to be a misconception about relations. Relation members don't necessarily have to be sorted. Consequently you might have to sort the members yourself, if necessary at all.
You can take a look at JOSM which has a neat sorting algorithm for various types of relations. But I don't think it is able to place members with the role stop at the correct position. This isn't always possible because a way doesn't necessarily have to be split at each node with the stop role. This also means a single way can contain more than one node with a stop role, making it impossible to sort the relation members correctly. Unless you do some pre-processing for splitting each way accordingly.
For calculating the distance between each stop it seems unnecessary to sort the elements. Just follow the way by iterating over all each nodes and check for each node if it has a stop role in the corresponding relation. When reaching the end of the way continue with the one which shares the same node at its start or end and which is also member of the relation.

How to search for multiple tags around one location?

I'm trying to figure out what's the best solution to find all nodes of certain types around a given GPS-Location.
Let's say I want to get all cafes, pubs, restaurant and parks around a given point X.xx,Y.yy.
[out:json];(node[amenity][leisure](around:500,52.2740711,10.5222147););out;
This returns nothing because I think it searches for nodes that are both, amenity and leisure which is not possible.
[out:json];(node[amenity or leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity,leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity;leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity|leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity]|[leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity],[leisure](around:500,52.2740711,10.5222147););out;
[out:json];(node[amenity];[leisure](around:500,52.2740711,10.5222147););out;
These solutions result in an error (400: Bad Request)
The only working solution I found is the following one which results in really long queries
[out:json];(node[amenity=cafe](around:500,52.2740711,10.5222147);node[leisure=park](around:500,52.2740711,10.5222147);node[amenity=pub](around:500,52.2740711,10.5222147);node[amenity=restaurant](around:500,52.2740711,10.5222147););out;
Isn't there an easier solution without multiple "around" statements?
EDIT:
Found This on which is a little bit shorter. But still multiple "around" statements.
[out:json];(node["leisure"~"park"](around:400,52.2784715,10.5249662);node["ameni‌​ty"~"cafe|pub|restaurant"](around:400,52.2784715,10.5249662););out;
What you're probably looking for is regular expression support for keys (not only values).
Here's an example based on your query above:
[out:json];
node[~"^(amenity|leisure)$"~"."](around:500,52.2740711,10.5222147);
out;
NB: Since version 0.7.54 (released in Q1/2017) Overpass API also supports filter criteria with 'or' conditions. See this example on how to use this new (if: ) filter.