Find out if crossroad or 3-way-intersection - openstreetmap

I'm trying to find out the type of a crossroad / intersection in overpass by given coordinates (simple 4-way-crossroad or 3-way-intersection aka Y/T intersection).
Wanted to count the way-id's I'm getting via json later in program code (4 = simple crossroad, 3 = Y or T) using the following query:
http://overpass-turbo.eu/s/NyD
[out:json][timeout:15];
way["highway"](around:1,48.7986003,11.3759673);
foreach ->.w {
node(w.w);(way(bn);- .w;)->.wd;
out body geom;
};
Problem: This only works if a street ends at the crossroad / intersection or at least turns into another way-id.
In this example there's a street which reaches from north to south and east. The east way got another way-id so that's not a problem. But from north to south it's just one way (so only one id). Result: I'm counting 3 but it should be 4 for this type of crossroad.
How do I solve this problem or is there a better way to identify the type of a crossroad / intersection?
Thank you very much!

You have to look at the junction node, too.
Some examples:
If the node is part of two ways and..
these ways have other nodes before and after this node ID then you have a 4-way-junction.
only one way has other nodes before and after this node ID then you have a 3-way-junction
none of these ways have other nodes before and after this node ID then it is not a junction. Instead, the way continues with a different ID.
If the node is part of n ways and it is the last or first node of all these ways then you have a n-way-junction.
There will be some more cases than the ones mentioned above. Take a sheet of paper, draw some ways and their nodes onto it to get a better visualization of the data.
I'm not sure if this simple approach will work for all cases, though.

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.

Possible to do TSP with mongodb?

I'm working an a map app where I can add waypoints along specific routes. I need to pull my waypoints out in order obviously so I can get directions from A-D in the correct order.
I've read a bit about geoJSON in mongodb but I'm curious if theres a way to query my data so that my points come out ordered by how close they are together rather than the order I've put them in.
Basically what I'm asking...Is there a way to do a "Traveling Salesman query" so that my waypoints are ordered in the smartest order?
I think the short answer is no. You're going to need to add an order key to your waypoints. This is a pretty standard pattern for any nav system with waypoints. At the very least you need to know which point is first and which is last so that you can then solve the TSP.

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.

Get all information about a street in OpenStreetMap

I've been playing around with API, XAPI and Overpass of OSM. But I can not get some info a need: to get all information nodes of a street.
Here a example:
http://www.openstreetmap.org/browse/way/5671291
This gives information of a way called "Watts Street" (in NYC), but it's not all the street, just a part of it.
The other part:
http://www.openstreetmap.org/browse/way/46116390
This happens with some streets, that are split in different OSM "ways"
Is there a way to get all the nodes of a same street having more than "one way" to get all the coordinates across that street ?
Thank you
You could try to query the street name and get all ways with the same name. Then you could take all individual nodes and you should have what you want. I know Nominatim does that mapping but I'm not familiar with the api's you mentioned.
Another (maybe more cumbersome) method is to look at the nodes of your way and see in what ways they are involved. If you take your example, the node 42426060 is part of both ways you're looking for. If you could query the ways for that node and match them (according to name), you could merge them yourself.

Puzzle Solver - TreeNode Help

I'm trying to code a puzzle solver app.
I need to find out how many moves it takes, and how many solutions there are.
I would rather not give too many details on the puzzle.
but the player moves around a grid ( say 5 x 7 )
as they move, obstacles could be captured so the state of the board needs to be tracked.
( this could be done as a string or an array )
I understand I need to create a TreeNode, starting with a root ( the players start position )
and give each node children of the possible moves until all the possible moves are calculated.
The puzzle stats could then be collected.
Number of Possible solutions, minimum number of moves to solve, average number of moves to solve, etc.
I have the puzzle logic created that will return if moves are possible and such.
I'm having problems creating the TreeNode structure and making sure moves are not duplicated.
The puzzle app itself is on the iPhone, but I'm writing this solver/editor on the Mac.
Any help would be VERY much appreciated.
Perhaps you could do a variant of a tree recursion? Traverse the tree recursively, having each end node return a value of how hard it was to get there (if there are costs associated with different moves) and a description of how it got there. This of course requires the player to only move in one direction, otherwise the tree-structure doesn't describe the problem. A bit more info on what your exact problem looks like would be helpful.
It might be a heavy algorithm, but it gets the job done.
For detecting repeated states, you would put the states in a set as you went along, and then check every time you found new states to see if they already existed. Though if space is an issue, you will have to resort to only checking if the children are not the same as the parent, or some kind of limited version of this approach.
A node class is very simple. It just contains a pointer back to a parent (if it has one) and the variable it holds (such as a state). You will also probably want other variables depending on your application.
When you get to a node, you use a successor function to get all the child nodes from there (the states that can be reached in one move) and add them to a list. You pluck from the list to traverse the tree.