I am now trying to get the length of a shortest path using
dijkstra(). I need it to find all the points in my sample, which are located more than 25 km away along roads from district centres. I will loop it, but before I do this I need to get the path's length.
When I enter the following code, it only shows me the shortest path highlighted in red, but not its length. How can I modify it in order to get length in km? (In case it is important, my crs is North_Pole_Lambert_Azimuthal_Equal_Area)
from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * from qgis.networkanalysis import * vl = qgis.utils.iface.mapCanvas().currentLayer() director = QgsLineVectorLayerDirector(vl, -1, '', '', '', 3) properter = QgsDistanceArcProperter() director.addProperter(properter) crs = qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs() builder = QgsGraphBuilder(crs) pStart = QgsPoint(2327292.145, -2732901.348) pStop = QgsPoint(2328327.741, -2732822.68) tiedPoints = director.makeGraph(builder, [pStart, pStop]) graph = builder.graph() tStart = tiedPoints tStop = tiedPoints idStart = graph.findVertex(tStart) idStop = graph.findVertex(tStop) (tree, cost) = QgsGraphAnalyzer.dijkstra(graph, idStart, 0) if tree[idStop] == -1: print ("Path not found") else: p =  curPos = idStop while curPos != idStart: p.append(graph.vertex(graph.arc(tree[curPos]).inVertex()).point()) curPos = graph.arc(tree[curPos]).outVertex(); p.append(tStart) rb = QgsRubberBand(qgis.utils.iface.mapCanvas()) rb.setColor(Qt.red) for pnt in p: rb.addPoint(pnt)