[Qgis-developer] RoadGraphPlugin and network-analysis annonce

Сергей Якушев yakushevs at gmail.com
Wed Sep 28 03:50:14 EDT 2011


Hello!

In my fork QGIS in the branch network-analysis is a new version RoadGraphPlugin.

Changes:
1. When the setting of "topological tolerance" value greater than zero
in the construction of the graph is almost as fast as with a parameter
equal to zero.

2. Reduced memory usage. If you are using big map of Moscow, then you
no longer need gigabytes of RAM. Only ~10 megabytes.

3. Core RoadGraph move into a separate library qgisnetworkanalysis.

4. Implemented a minimum set of python bindings. Now you can use
Python to find the shortest path.

To demonstrate the third and 4th items prepared (and well-commented) a
simple script (see attachment) and the screencast
(http://gis-lab.info/forum/download/file.php?id=3175).

What do you think? I think this is a good candidate for inclusion in
the master-branch qgis.

--
С уважением Якушев Сергей YakushevS at gmail.com
-------------- next part --------------
# Import the library network analysis
from qgis.networkanalysis import *

# Import gui library
from qgis.gui import *

# Create a new director. Shall determine from which to build a graph.
director = QgsLineVectorLayerDirector( qgis.utils.iface.mapCanvas().currentLayer(), -1, '', '', '', 3 )

# Create a strategy to use the properties of the edges of the graph. The strategy calculates the property edge, prompting the director of data.
# In this case, the length, Road Graph plugin I made a strategy that computes the motion of the edge.

properter = QgsDistanceArcProperter( );

# Inform the strategy director. Available any number of strategies.
director.addProperter( properter )

# Create builder. It determines what type of graph we construct. Currently available only built QgsGraph.
# You can create your own builder for such libraries as the Boost Graph library and networkX. 
builder = QgsGraphBuilder( qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs() )

# Introduce the coordinates of the point.
point = QgsPoint(66.6757,57.1742)

# The director gives the team builder. Builder creates a graph adn tie point "point" to the graph
# Return value in the coordinates of the corresponding point.
tiedPoint = director.makeGraph( builder, [point] )

# Get the graph suitable for analysis
graph = builder.graph()

# Get the index points on a graph
id = graph.findVertex( tiedPoint[0] )

# Get the shortest path tree rooted at point "point"
tree = QgsGraphAnalyzer.shortestTree( graph, id, 0 )
id = tree.findVertex( tiedPoint[0] )

# Draw the shortest path tree (be careful, the code is scary is not optimal). What to do with it is up to you

not_begin = [id]
rb = QgsRubberBand( qgis.utils.iface.mapCanvas() )
rb.setWidth( 3 )

while len(not_begin)>0:
  curId = not_begin[0]
  not_begin = not_begin[1:]
  rb.addPoint( tree.vertex(curId).point() )
  f = 1
  for i in tree.vertex(curId).outArc():
    if f==1:
      not_begin = [ tree.arc(i).inVertex() ] + not_begin
      f=0
    else:
      not_begin = not_begin + [ tree.arc(i).inVertex() ]
  
  
  if len( tree.vertex(curId).outArc() )==0 :
    rb = QgsRubberBand( qgis.utils.iface.mapCanvas() )
    rb.setWidth( 3 )
    if (len(not_begin)>0) and (len(tree.vertex(not_begin[0]).inArc())>0): 
      rb.addPoint( tree.vertex( tree.arc( tree.vertex(not_begin[0]).inArc()[0] ).outVertex() ).point() )




More information about the Qgis-developer mailing list