Given a OSM node id, how do I find the previous x points in all directions? - openstreetmap

I have a OSM node Id/ latitude-longitude for a point in the road(say point Z). How do I find the previous x points that I need to travel to reach Z in all directions? I was thinking overpass API could help me. But it is able to return points only with tags. I am not able to get it return the node Ids on the road/way.
Can you please suggest any API/tutorial that could help?

if i'm not wrong what you are asking is: given a osm node id with coordinate x and y what are all points to do in order to arrive there from a starting point?
if this is the question well this is a graph oriented question; you should create a grah and then use some algorithm in order to find all the routes between starting point and end point; you should use some graph oriented software.. something like neo4j and spatial contrib (https://github.com/neo4j-contrib/spatial)
In past i built a project where i read an osmfile, create a graph and used A* algorithm; you may give to it a look https://github.com/angeloimm/neo4jAstarTest

I suggest to get started by reading about OSM elements, especially nodes and ways. Afterwards take a look at OSM XML format. It might also help to open an OSM editor (e.g. iD) and to take a look at the raw data.
Nodes don't have any order or "next node" themselves. Nodes can be part of one or multiple ways. Each way references a list of ordered nodes. So you have to look at all ways a node belongs to, then look at the way's node list to determine the previous and next nodes. If the node is at the start or end of a way then you have to look if there are one or more consecutive ways. Consecutive ways share the same node at their start/end.

Related

pgRouting with custom network?

I have a cost network, but it's not a street mapping network. I know the nodes and edges as I defined them. pgRouting looks like a good choice, but every single example I can find uses Open Street Map as the data. I don't have GPS coordinates. The x1,y1 for nodes makes no sense in my graphs, my nodes have specific ids, not coordinates. The costs aren't calculated from the coordinates, they're assigned by me on the various edges based on domain knowledge specific to my domain.
Are there any examples of how to create a custom network in pgRouting? I'm really struggling because the examples are "and then you use this tool to import OSM data"...which doesn't help me at all.
#Chris Kessel
I don't know if this is still relevant, but it may help others:
Basically, what you need to have is a table with edges, where in column 'source' is the id of a node on one end of the edge and in column 'target' - id of the node on the other end. You also have to have a defined cost for the edge, I'm not sure what this will be for you - usually it's distance or time units.
Ususally this is done with geo info using pgr_createTopology function, but in your case you will need to just create this yourself, I suppose.
I think this link can help you:
https://anitagraser.com/2011/02/07/a-beginners-guide-to-pgrouting/
The answer to the question "Are there any examples of how to create a custom network in pgRouting?" is Yes there are.

pgr_drivingDistance with flexible distance value on each route

I would like to calculate a graph similiar to an isochrone using pgsql. Therefore, I already used the algorithm pgr_drivingDistance. You provide a starting point and a distance value and receives an isochrone.
The output using the algorithm is received with code which looks something like:
SELECT * FROM pgr_drivingDistance(
'SELECT id, source, target, cost FROM edge_table',
2, 2, false -- starting point, distance, directed
);
The red star represents the starting point.
Now, I want a graph which works the same way, like starting at one point and get routes in all directions. The difference is, that I don't want to provide a travel distance, but a list with point coordinates, which are lying on the road network. The route in every direction has to stop at the first reached point lying on each route. The distance on every route is different and I don't know which points are the closest ones.
The desired output using the "stopping" points, which are visualized in green, is supposed to look like this.
I tried already:
Using the given algorithm pgr_drivingDistance and raising the distance value every time no point is reached -> problem here: the distance is equal for all directions and not individual for each route.
Using the algorithm pgr_dijkstra for each route -> problem here: because you don't know which point is affected you don't know which end point to choose for the calculation. You also cannot take the closest one in the immediate vicinity because you need the closest one on the specific route.
I know that I have to build an almost complete new algorithm, but maybe someone has an idea how to start or even experience with this kind of problem.
Thank you in advance!
This is a one to many routing problem. You have to compute the route to each end point to find the shortest one. I have not looked at the pgRouting function recently, but I believe there is a one to many, many to one and many to many Dijkstra function(s). You should be able to use the one to many to compute all the routs in one go and then you can sort the routs based on length to find the shortest one.

How can I write a logical process for finding the area of a point on a graph?

I have the following graph with 2 different parameters called p and t. 
Their relationship is experimentally found. Manually by knowing (t,p), you can simply find the area number (group) of the point based on where it is located. For example, point M(t,p), locates in area 3 and belongs to group number 3. However, I would like to write a code/logical approach which automatically finds the group numbers. therefore when it reads (t,p) it will find the location of the point and give the group/Area number it belongs.
Is there any solution in Matlab for this scope?  Graph
If you have the Image Processing Toolbox and your contours are closed, you can use imfill to fill them up (a bit like the bucket tool in Paint) and assign different values to each filled up region. Does this make sense to you? Let me know if you would like more detail.
Marta

Using node similarities in a graph or clustering viaualization

Use case:
nodes are documents
Links are links between documents that have an associated correlation (e.g., 0 to 1)
Being new, it is not clear how to apply those correlations or "weights' so that the document cluster in a logical manner.
Can anyone point me to an existing example?
Thanks in advance.
Positioning nodes is done by the layout. Use any force-directed (physics) layout, like CoSE or Cola. Those layouts allow your to specify how strongly nodes should be pulled towards one another on a per-edge basis.
Try some of the force-directed layouts to see which one gives results that you like. Each one has different trade-offs (speed, aesthetics, etc.).
Just make sure to set the edge force for whatever layout, e.g. edgeElasticity for CoSE, to be proportional to edge.data('weight').
Example: http://js.cytoscape.org/demos/7b511e1f48ffd044ad66/

Personalized Page Rank

I have been trying to wrap me head around the personalized page rank algorithm and how it works. I came across this paper which gives this graph:see link to image below with weights calculated by PPR. I am have trouble reproducing the calculations with the models they give.
Can anyone break it down for me to help me wrap me head around the concept?
Thanks!
The paper is a good reference to personalized page rank. Basically my understanding, ppr scores tell you the probability from the source node move to the target node. It is a specific score describe the relationship between specific source and target nodes in the graph.
If you have problem to reproduce the results, you can use networkx in python, load a graph and compute ppr using
networkx.pagerank(graph, personalization={'a':0, 's':1, 'b':0....})
Networkx use power iteration approach to compute ppr, you can get exact result as what shown in the example.
The author of this thesis have c++ code here https://github.com/snap-stanford/snap/blob/master/snap-core/randwalk.h Since this method is random walk based approach, you could not get exactly same results as what shown in the example, but the rank is correct.
Hope that helps.