How are the costs returned by pyQGIS implementation of Dijkstra (QgsGraphAnalyzer.dijkstra) calculated?

As far as I know, these costs correspond to the distance from the starting node to each of the other nodes in the graph, however the cost values I get are way too large to be the distances on the underlying road network.

For example: For a CRS EPSG:4326, the length of an edge in my road network, as returned by feature.geometry().length() is 36.769 metres, where feature.geometry().asPolyline() = [(10573, 5837), (10547, 5863)].

On the other hand, the following is the cost array returned by Dijkstra:

(tree, cost) = QgsGraphAnalyzer.dijkstra(graph, graph.findVertex((10547, 5863)), 0)

cost[graph.findVertex(QgsPoint(10573, 5837))] = 17176150.0812.

Again, from my understanding the cost value above should be 36.769 rather than 17176150.0812.

How can the above be explained?

  • Can you say what the spatial reference (CRS) that you are using is, what the units of that CRS are (e.g. metres, degrees, feet, whatever) and what the rough distance is for a simple edge (as reported by the graph analyser, and as measured by you)? – BradHards Oct 23 '15 at 6:18
  • Hi BradHards. Thanks for your comment. I have just added the details you asked for to my original question. – Victor Romero-Cano Oct 25 '15 at 22:35
  • Can you show your features? Are you sure that 36.769 is in metres? – BradHards Oct 26 '15 at 7:00
  • I have added an exemplar feature. Even if the length is not in metres, I would expect that feature.geometry().length() == ** cost[in_vertex_id] ** – Victor Romero-Cano Oct 27 '15 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.