[QGIS-Developer] Dijkstra not getting the correct results

Nyall Dawson nyall.dawson at gmail.com
Thu Jan 31 14:45:42 PST 2019


On Wed, 30 Jan 2019 at 19:52, Christoph Dohm <cdohm at gmx.de> wrote:
>
> Hi,
>
> I'm trying to work on a routing problem for my Python plugin and I wanted to use the Dijksta algorithm for that. I used QGIS 3.0 Girona first, but upgraded to 3.4 Madeira recently but getting the same result.
>
> I tried to work along the Code from the Cookbook and also used the book "Building Mapping Applications with QGIS" from Erik Westra, which is basically the same Code as in the Cookbook.
>
> Since those sources are from QGIS 2 I had to make some adaptions (import from qgis.analysis library instead qgis.networkanalysis and some others) My Code seems to be working now, but the results aren't usful as it no matter what I do only gives me a -1 for every vertex in the tree.
>
> I posted my problem on stackexchange with the Code that I'm using.
>
> https://gis.stackexchange.com/questions/308244/dijkstra-finding-shortest-path-gives-back-a-tree-with-only-1-in-it
>
> I'm a little lost. I don't understand why it is not working.

There was a bug fixed recently which mostly impacted network routing
when geographic coordinate systems were used. Could this apply to you?

Nyall


>
> Sincerely
>
> Chris
>
>
>
>
> Here is a part of the Code I'm using
>
>
> director = QgsVectorLayerDirector(layer, -1, '', '', '', 3)
>
> strategy = QgsNetworkDistanceStrategy()
>
> director.addStrategy(strategy)
>
> builder = QgsGraphBuilder(crs) #crs = project.crs() which is in this case WGS84
>
> tiedPoints = director.makeGraph(builder, [startPt, endPt])
> graph = builder.graph()
>
> startVertex = graph.findVertex(startPt)
>
> (tree, cost) = QgsGraphAnalyzer.dijkstra(graph, startVertex,0)
>
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list