So I'm trying to implement a routing algorithm in my QGIS 3 plugin that I'm writing using Python.

I think I could resolve all the problems concerning the break between QGIS 2 and 3, but my resulting tree gives me for all nodes in it just a -1 value which is for not connected nodes.

If I have for example a project that looks like this:

enter image description here

Where the red Square is my start point and the yellow circle my end point I get back a tree that looks like this [-1,-1,-1]

the code I use is the following:

First I select the Line layer and the startPt and endPt

director = QgsVectorLayerDirector(layer, -1, '', '', '', 3) 

strategy = QgsNetworkDistanceStrategy()


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)

I just don't know where it goes wrong.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.