<div dir="auto">Hi Felix,</div><div dir="auto"><br></div><div dir="auto">Appreciate your alternative solution. I could make some degree of performance improvement.</div><div dir="auto"><br></div><div dir="auto">Thanks a lot for your help, mate.</div><div dir="auto"><br></div><div dir="auto">Prem</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 31 Dec 2021 at 7:15 PM, flatoram <<a href="mailto:felix.vons@gmail.com">felix.vons@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="ltr"><div>Hi Prem,</div><div><br></div><div>I experienced those performance issues too.</div><div>When i process a lot of routing operations between points I will define an routing area first on the source network layer (e.g. osm_lines). </div><div>I create a tempory layer sometimes in this way with pyqgis:</div><div><br></div><div># define bounding box and make it a big larger (just an example)</div><div>rectangle = QgsRectangle(point_0, point_1)</div><div>rectangle = rectangle.scaled(2)   # depends on your use case<br></div><div><br></div><div># build request</div><div>request = QgsFeatureRequest().setFilterRect(rectangle)</div><div># request = request.setNoAttributes()  # when you do not need any attributes</div><div># request = request.setSubsetOfAttributes(["speed"], layer.fields())  # use only some fields</div><div># add conditions to request to use only features you need, e.g. ignore specific street types</div><div>new_layer = layer.materialize(request)  # create a memory copy of source layer</div><div><br></div><div>In my use cases the new_layer is definitive smaller and more perfomant than the main layer for those operations. Use the new layer for routing. But maybe you have not the full available path in your new layer, when your bbox was to small.</div><div><br></div><div>An other possibility for path finding is QgsTracer class, but it is different to classic dijsktra/shortestpath when dealing with vertices or line intersections</div><div><br></div><div># use qgis tracer, but it is a bit different from classic dijkstra<br>tracer = QgsTracer()<br>tracer.setLayers([network_layer])</div><div># maybe you have to define the destinationCrs<br>poly_line = tracer.findShortestPath(start_point, end_point)[0]<br></div><div><br></div><div><br></div><div>Depends on the use cases I saved a lot of calculation time.</div><div><br></div><div>- Felix</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Do., 30. Dez. 2021 um 21:01 Uhr schrieb <<a href="mailto:qgis-developer-request@lists.osgeo.org" target="_blank">qgis-developer-request@lists.osgeo.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Send QGIS-Developer mailing list submissions to<br>
        <a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:qgis-developer-request@lists.osgeo.org" target="_blank">qgis-developer-request@lists.osgeo.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:qgis-developer-owner@lists.osgeo.org" target="_blank">qgis-developer-owner@lists.osgeo.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of QGIS-Developer digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Reusing network graph (Prem Kumar)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 30 Dec 2021 19:16:41 +0530<br>
From: Prem Kumar <<a href="mailto:prem.netgis@gmail.com" target="_blank">prem.netgis@gmail.com</a>><br>
To: qgis-developer <<a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.org</a>><br>
Subject: [QGIS-Developer] Reusing network graph<br>
Message-ID:<br>
        <CAP2_p600CpiF=<a href="mailto:eJfRsCKby7yB1siX4vW7faWbCKSrROtB9cLUg@mail.gmail.com" target="_blank">eJfRsCKby7yB1siX4vW7faWbCKSrROtB9cLUg@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi Team,<br>
<br>
I have been trying to get the shortest path for a lot of pairs of start and<br>
end points for a given road layer. Although I'm able to achieve this by<br>
creating the *QgsVectorLayerDirector *and Graph object for every pair of<br>
start and end points.<br>
<br>
However, I could not reuse the graph object or director object for all the<br>
pairs of start and end points, eventually the code is as slow as executing<br>
the* 'native:shortestpathpointtopoint'* processing tool<br>
programmatically for each pair of start and end points.<br>
<br>
Essentially, I'm trying to improve the performance by reusing the graph<br>
objects. Can someone help me whether there is a possibility to reuse the<br>
graph object for large sets of pairs? Here is the code snippet I have used.<br>
<br>
vectorLayer = QgsVectorLayer('testdata/network.gpkg|layername=network_lines',<br>
'lines')director = QgsVectorLayerDirector(vectorLayer, -1, '', '', '',<br>
QgsVectorLayerDirector.DirectionBoth)strategy =<br>
QgsNetworkDistanceStrategy()director.addStrategy(strategy)builder =<br>
QgsGraphBuilder(vectorLayer.sourceCrs())startPoint =<br>
QgsPointXY(1179661.925139,5419188.074362)endPoint =<br>
QgsPointXY(1180942.970617,5420040.097560)tiedPoints =<br>
director.makeGraph(builder, [startPoint, endPoint])tStart, tStop =<br>
tiedPointsgraph = builder.graph()idxStart =<br>
graph.findVertex(tStart)idxEnd = graph.findVertex(tStop)(tree, costs)<br>
= QgsGraphAnalyzer.dijkstra(graph, idxStart, 0)<br>
<br>
-Prem<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.osgeo.org/pipermail/qgis-developer/attachments/20211230/acf709c0/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/qgis-developer/attachments/20211230/acf709c0/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
<br>
<br>
------------------------------<br>
<br>
End of QGIS-Developer Digest, Vol 194, Issue 18<br>
***********************************************<br>
</blockquote></div></div>
</blockquote></div></div>