I'm using QGIS 3.34.0, and making a litle model using Model Designer. I have lots of tractor roads and I need to calculate distances from each crossing of two roads to the highway road. I make points on those crossing points, and make a point on the crossing tractor road with the highway road.
I'm using (outside a Model Designer) Shortest Path (Point to layer) but Run as Batch Process and it gives me results.
Is there any way to use it in Model Designer?
I need a distace from each red point to the purple point on the road folowing blue line... enter image description here
And I am using Shortest path in Batch procesing - and I am trying to put this process in my model. enter image description here
1 Answer 1
Instead of batch you can iterate over each start point using a Vector Features input.
Create a model with three input parameters:
- Vector Features: Start points
- Vector Layer: End points
- Vector Layer: The line network
Set the start point in Shortest path (point to layer) to "Pre-calculated Value" with the expression:
concat( @vector_features_minx , ',', @vector_features_miny , '[EPSG:3006]')
Replace EPSG:3006
with the coordinate system of the input points.
The expression will create a string in the format: X start coordinate , Y start coordinate [EPSG:3006]
for each input start point feature.
When you execute the model, press "Iterate over this layer ... ": enter image description here
One shortest path layer is created for each input point, which you can merge into one layer if you want to:
-
1This helped a lot and gives the result I wanted. And now, can I have one more little help: Using your instructions and tips, I assembled the model and the result of the model is from several to several dozen temporary files -> how, i.e. with which command, to merge them all into one. I tried with Merge vector layers, but I didn't get the desired result, which is 1 file with all merged data. Thank you.sttipa– sttipa2024年04月24日 19:47:21 +00:00Commented Apr 24, 2024 at 19:47
-
1You have to merge them manually outside/after the modelBera– Bera2024年04月25日 05:35:57 +00:00Commented Apr 25, 2024 at 5:35
-
1You can use pyqgis for this.
processing.runAndLoadResults("native:mergevectorlayers", {'LAYERS':[x for x in QgsProject.instance().mapLayers().values() if x.name()=="path"],'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})
will merge all layers namedpath
that are added to the map.Bera– Bera2024年04月25日 05:48:51 +00:00Commented Apr 25, 2024 at 5:48 -
1Thanks a lot for all your help!sttipa– sttipa2024年04月25日 09:16:50 +00:00Commented Apr 25, 2024 at 9:16
-
I don't understand why it doesn't work for me... I want to solve exactly the same problem: I have many start and end points ... the model calculates all paths from the bottom left corner of the line_layer?Rii Pii– Rii Pii2025年01月16日 14:44:56 +00:00Commented Jan 16 at 14:44