Does not show shortest path in networkx (in QGIS)

98 views
Skip to first unread message

Kasun Ramanayake

unread,
May 30, 2014, 11:45:11 PM5/30/14
to inasaf...@googlegroups.com

I used the following commands (in qgis console) to get the shortest path with astar algorithm. But the result shows just '[]' every time. Why was that? Please help me to find a solution to this problem.

>>> import networkx as nx
>>> G = nx.read_shp(str(iface.mapCanvas().currentLayer().source()))
>>> route = nx.shortest_path(G, G.nodes()[1], G.nodes()[10])
[]
>>> route = nx.shortest_path(G, G.nodes()[20], G.nodes()[30])
[]

Tim Sutton

unread,
May 31, 2014, 3:18:32 AM5/31/14
to inasaf...@googlegroups.com
Hi

Have you tried working through the tutorial here?


Are you trying to implement your own director pattern implementation?


Regards

Tim


--
Visit the InaSAFE project page at http://inasafe.org
Let us know of any issues you encounter at: https://github.com/AIFDR/inasafe/issues
---
You received this message because you are subscribed to the Google Groups "inasafe-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inasafe-user...@googlegroups.com.
To post to this group, send email to inasaf...@googlegroups.com.
Visit this group at http://groups.google.com/group/inasafe-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/inasafe-users/b33795da-abe8-45ee-b464-8ed330f1b619%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Tim Sutton
-------------------------------------------------------------------------------------------

Visit http://linfiniti.com to find out about:
 * QGIS programming services
 * GeoDjango web development
 * QGIS Training
 * FOSS Consulting Services
Skype: timlinux Irc: timlinux on #qgis at freenode.net
Tim is a member of the QGIS Project Steering Committee
-------------------------------------------------------------------------------------------

Kasun Ramanayake

unread,
May 31, 2014, 5:30:25 AM5/31/14
to inasaf...@googlegroups.com
Hi,
   I tried that tutorial.Here I wanted to use the A* algorithm since it finds the shortest path avoiding obstacles. I coded the algorithm (without using the direct command-shortest_path/astar_path) but it always shows, 'no path found' for me. Then I tried using networkx (in qgis console and in code too), and found that it returns nothing. Why is that ? Is that a problem with networkx or my layer?

Thank You

Tim Sutton

unread,
May 31, 2014, 6:23:10 AM5/31/14
to inasaf...@googlegroups.com
Hi


On Sat, May 31, 2014 at 11:30 AM, Kasun Ramanayake <kasun.ra...@gmail.com> wrote:
Hi,
   I tried that tutorial.Here I wanted to use the A* algorithm since it finds the shortest path avoiding obstacles. I coded the algorithm (without using the direct command-shortest_path/astar_path) but it always shows, 'no path found' for me. Then I tried using networkx (in qgis console and in code too), and found that it returns nothing. Why is that ? Is that a problem with networkx or my layer?

Hmm I havent tried using networkx before. Can you share your layer? Did you try using a layer imported using the InaSAFE OSM downloader tool?

Regards

Tim
 

Thank You


On Saturday, May 31, 2014 9:15:11 AM UTC+5:30, Kasun Ramanayake wrote:

I used the following commands (in qgis console) to get the shortest path with astar algorithm. But the result shows just '[]' every time. Why was that? Please help me to find a solution to this problem.

>>> import networkx as nx
>>> G = nx.read_shp(str(iface.mapCanvas().currentLayer().source()))
>>> route = nx.shortest_path(G, G.nodes()[1], G.nodes()[10])
[]
>>> route = nx.shortest_path(G, G.nodes()[20], G.nodes()[30])
[]

--
Visit the InaSAFE project page at http://inasafe.org
Let us know of any issues you encounter at: https://github.com/AIFDR/inasafe/issues
---
You received this message because you are subscribed to the Google Groups "inasafe-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inasafe-user...@googlegroups.com.
To post to this group, send email to inasaf...@googlegroups.com.
Visit this group at http://groups.google.com/group/inasafe-users.

For more options, visit https://groups.google.com/d/optout.

Kasun Ramanayake

unread,
May 31, 2014, 6:35:38 AM5/31/14
to inasaf...@googlegroups.com
No, I jsut checked. It doesn't work for any layer. I used that popular 'jakarta jalan' layer. By the way, is there any other method I can use for this purpose?
Thank You
(I attached the layer.Can you please check whether it's working..)

On Saturday, May 31, 2014 9:15:11 AM UTC+5:30, Kasun Ramanayake wrote:
jakarta jalan.tar.gz

Tim Sutton

unread,
Jun 2, 2014, 6:47:54 AM6/2/14
to inasaf...@googlegroups.com
Hi


So I made the a simple script (using Dijkstra) which I have attached which successfully routes across the network.

Can you confirm if this works for you? (it works for me)

If it does work, do you still need to use networkx?

Inline image 1


Regards

Tim


--
Visit the InaSAFE project page at http://inasafe.org
Let us know of any issues you encounter at: https://github.com/AIFDR/inasafe/issues
---
You received this message because you are subscribed to the Google Groups "inasafe-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inasafe-user...@googlegroups.com.
To post to this group, send email to inasaf...@googlegroups.com.
Visit this group at http://groups.google.com/group/inasafe-users.

For more options, visit https://groups.google.com/d/optout.
graph.py

Dil

unread,
Jun 2, 2014, 7:08:26 AM6/2/14
to inasaf...@googlegroups.com
Hi,
     I used that code earlier. It worked for me too. But I wanted to use astar algorithm, which finds path by avoiding obstacles.That's why I thought to use networkx. By the way, I found that I can make a new layer by using Geoprocessing tools->difference option. So that I can remove the obstacles or impassable ares on map.Then I could use these algorithms to find a path on new layer. Is there a way to access those Geoprocessing tools in my code?
Thank you

Tim Sutton

unread,
Jun 2, 2014, 12:52:08 PM6/2/14
to inasaf...@googlegroups.com
Hi


On Mon, Jun 2, 2014 at 6:08 PM, Dil <dilvit...@gmail.com> wrote:
Hi,
     I used that code earlier. It worked for me too. But I wanted to use astar algorithm, which finds path by avoiding obstacles.That's why I thought to use networkx. By the way, I found that I can make a new layer by using Geoprocessing tools->difference option. So that I can remove the obstacles or impassable ares on map.Then I could use these algorithms to find a path on new layer. Is there a way to access those Geoprocessing tools in my code?

Yes - see my reply to this thread:


May I again cordially request that you do not post the same question to multiple lists at once - it wastes effort as multiple people end up answering the same question and threads become very hard to follow as they are spread across different lists.

Thanks!

Tim
 

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages