I'm new to NetworkX in Python. I have a directed graph and I'm using nx.edge_dfs to filter out nodes that have no upstream edges / links. It works but it's very slow. I just need to check that there are more than 3 upstream nodes. Is there a better way to do this?
(I've editted this as I initially pasted the wrong function)
Thanks
# if there are <x upstream nodes, return a fail code
elif len(list(nx.edge_dfs(G,dwnstr, orientation='reverse')))< 2: # 2 as a psuedo depth.
return (1)
Related
I am using one simulator and wanted to add my own maps. So I looked into this website https://mygeodata.cloud/ which can provide me with the wkt files of maps.
The problem is I am not able to get these to work, can someone provide some details on how to add a town's map with maybe bus routes etc to ONE Simulator?
The error I'm getting is "SimMap is not fully connected. Only 1057 out of 1113 map nodes can be reached from Nt2#(-1.15,52.95). E.g. Nt2#(-1.14,52.95) can't be reached"
The default roads.wtk files have linestrings like this
LINESTRING (2551683.6644129306 6674375.029443317, 2551528.069902012
6674337.650863852)
While my linestrings of Nottingham,England are this
LINESTRING (-1.1525824 52.9518235,-1.1524917 52.9517354,-1.1519975 >
52.9511418,-1.1517313 52.9508255)
It seems that your input map has around 50 nodes that can not be reached from other map nodes. The ONE Simulator needs to have the map fully connected (i.e., all nodes need to be reachable). Check out the map source (e.g., using OpenJUMP) and look for nodes or map segments that are not connected to each other and delete them or connect them with new line segments. The error message gives you a hint where to look at.
For an example on how to add bus routes, check out the Helsinki map and the tram/bus route files: https://github.com/akeranen/the-one/tree/master/data
that is because there is a broken node there should be a check again for the existing map input because some moves do not want any broken lines there can make messages from open strapmaps then edit using open jump
I was wondering if there is a way to get the highway direction of the route.
To be more specific, I am interested in routes on interstate highways in the United States only.
I'll give an example:
Interstate I45 is a north-south highway. When the route is returned, is there a way to know which "direction lane" the route is on?
The problem I'm trying to solve is accessing the rest ares like the one shown on the image here. As you can see, these are two rest areas, each accessible from one direction of the highway.
I would like to display only those accessible from the direction the user is on. I have all the data needed, including if the rest area is on the North/South/East/West direction and I only need the highway direction the route is on.
For obvious reasons, I would like to avoid manually checking if the route just appears to be going northwards.
I checked if this is possible via graphhopper, but it only gives the highway name, without direction. Is it possible to achieve this via Skobbler?
If you are using the TTS instructions (text-to-speech) then in the advice instructions & audio advices you will also receive the "orientation" (coded as a $orientation in the audio config files) - indicating the direction you are driving on a particular highway (south/north, etc.).
The trickier part is that you would have to parse the text instruction to get this information as it's not returned in a separate field (let me know in a comment if this was helpful).
I do not fully understand the original problem but as GraphHopper also returns the geometry for every instruction you should be able to calculate the orientation roughly but easily.
Another more complex approach would be to have a predefined name set associated with the geometry and use the map matching component to find out which highway parts are used in a route.
For obvious reasons,
which obvious reasons? That it is not really going norht south?
Or if something is not possible you always can modify in the code as it is open source or provide a pull request to merge it into the public release (if useful for others) and make it available for the Directions API too.
According to the OSM wiki page Highway Directions In The United States, directions of ways are supposed to be modeled as relation membership roles.
For example, I 75 way 173483918 is a member of the relation 332618 named "I 75 (TN northbound)" with role=north, so it's direction is "north".
The opposite way 173483897 is a member of the relation 332624 named "I 75 (TN southbound)" as role "south".
See more details on the wiki page. Don't know how well established that tagging scheme is, also don't know about router support (Telenav (Scout) seem to be involved in this who now own Skobbler).
I would like to get the distance between 2 markers but not as a direct line, more as a real path like it goes in this plugin -
https://github.com/perliedman/leaflet-routing-machine
I didn't find anything about using this plugin in the directive: angular-leaflet-directive,
if someone can guide how to make it done, it would be very appreciated.
thanks!
I am not sure if you specifically want to use leaflet routing machine to get distances... but if you do, maybe this info can get you started:
Set up a route on your map based on this example by the leaflet routing machine author:
https://www.liedman.net/leaflet-routing-machine/tutorials/interaction/
If you look at that example, there is an array called routes. Each route has some basic statistics associated with it, generated by OSRM. You can pull them by calling for example:
routes[0].summary.totalDistance
or
routes[0].summary.totalTime
Then you can do whatever you want with them. If you dig through the code on GitHub you can see more about how the data are moved around within the plugin and why the array is arranged that way:
https://unpkg.com/leaflet-routing-machine#3.2.12/dist/leaflet-routing-machine.js
Using neo4j 1.9 and neo4j spatial for 1.9.
Trying to get findGeometriesWithinDistance REST call working.
I can confirm that the install has worked and that the function exists BUT, using the http console I get a "Node 0 does not exist" error. The REST request I make is exactly as in the docs but instead of returning nodes I get this error.
What is going on that requires node 0 to exist and hence causes the error?
For info, the REST findGeometriesInBBox works fine.
On Further Investigation...
Using py2neo to interact with the DB. In particular, we make use of the GregorianCalendar functionality (see here). When removed from our logic the process of findGeometriesWithinDistance works fine.
Looking into it further, there are comments in the py2neo code that say #retain a handle to the root node (see the first code example here).
Does this "handle" do something with the node of index 0 so we can't use it?
Did you accidentally clean out your database?
I.e. remove node 0, which was the reference node that neo4j-spatial connected its root elements to (in 1.9)?
I have the following tree:
1-[HAS]->2-[HASSUBPAGE]->3-[HASSUBPAGE]->4
Now I want to traverse this tree starting at 4 and go up to 1 with this traverser (postng to /db/data/node/4/traverse/node):
{"order":"breadth_first","uniqueness":"node_path","relationships":[{"type":"HASSUBPAGE","direction":"in"},{"type":"HAS","direction":"in"}]}
But it stops at node 3 so all I get is node 3.
Any Ideas, why?
You must provide the max_depth parameter, as it defaults to 1 (to prevent infinite traversals).
Please try that and report if it worked for you.