<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hello,</div>
<div> </div>
<div>I wrote a while back a mail here and posted something on Stackexchange.</div>
<div> </div>
<div>https://gis.stackexchange.com/questions/308244/dijkstra-finding-shortest-path-gives-back-a-tree-with-only-1-in-it</div>
<div> </div>
<div>My main issue is, that in Qgis 2 there was a fairly simple way to perform a dijkstra analysis. I think you needed like 6 lines overall.</div>
<div>Migrating the same principle to Qgis 3 doesn't work, it always sees the path as not connected although it is. My guess is that the graph isn't created correctly, but I'm not an expert programmer.</div>
<div> </div>
<div>I know by now, that there is a workaround using the processing algorithm, but that gets way more complicated and as i mentioned earlier I'm not an expert and that is above my skill-level.</div>
<div> </div>
<div>I really would like to have a straightforward approach like there was in Qgis2, where you could create a graph from existing layers, define some properties and then perform the dijkstra on that graph.</div>
<div> </div>
<div>Here is the code that I migrated from Qgis2 that doesn't work but that would be great if it could work that way again:</div>
<div> </div>
<div>
<pre class="lang-py prettyprint prettyprinted" style=""><code><span class="pln">director </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsVectorLayerDirector</span><span class="pun">(</span><span class="pln">layer</span><span class="pun">,</span><span class="pln"> </span><span class="pun">-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="lit">3</span><span class="pun">)</span><span class="pln">
strategy </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsNetworkDistanceStrategy</span><span class="pun">()</span><span class="pln">
director</span><span class="pun">.</span><span class="pln">addStrategy</span><span class="pun">(</span><span class="pln">strategy</span><span class="pun">)</span><span class="pln">
builder </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsGraphBuilder</span><span class="pun">(</span><span class="pln">crs</span><span class="pun">)</span><span class="pln"> </span><span class="com">#crs = project.crs() which is in this case WGS84</span><span class="pln">
tiedPoints </span><span class="pun">=</span><span class="pln"> director</span><span class="pun">.</span><span class="pln">makeGraph</span><span class="pun">(</span><span class="pln">builder</span><span class="pun">,</span><span class="pln"> </span><span class="pun">[</span><span class="pln">startPt</span><span class="pun">,</span><span class="pln"> endPt</span><span class="pun">])</span><span class="pln">
graph </span><span class="pun">=</span><span class="pln"> builder</span><span class="pun">.</span><span class="pln">graph</span><span class="pun">()</span><span class="pln">
startVertex </span><span class="pun">=</span><span class="pln"> graph</span><span class="pun">.</span><span class="pln">findVertex</span><span class="pun">(</span><span class="pln">startPt</span><span class="pun">)</span><span class="pln">
</span><span class="pun">(</span><span class="pln">tree</span><span class="pun">,</span><span class="pln"> cost</span><span class="pun">)</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsGraphAnalyzer</span><span class="pun">.</span><span class="pln">dijkstra</span><span class="pun">(</span><span class="pln">graph</span><span class="pun">,</span><span class="pln"> startVertex</span><span class="pun">,</span><span class="lit">0</span><span class="pun">)</span></code></pre>
<div> </div>
<div><code><span class="pun">Sincerely</span></code></div>
<div><code><span class="pun">Christoph Dohm</span></code></div>
</div></div></body></html>