1

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

0

1 Answer 1

1

Instead of batch you can iterate over each start point using a Vector Features input.

Create a model with three input parameters:

  1. Vector Features: Start points
  2. Vector Layer: End points
  3. Vector Layer: The line network

enter image description here

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:

enter image description here

5
  • 1
    This 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. Commented Apr 24, 2024 at 19:47
  • 1
    You have to merge them manually outside/after the model Commented Apr 25, 2024 at 5:35
  • 1
    You 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 named path that are added to the map. Commented Apr 25, 2024 at 5:48
  • 1
    Thanks a lot for all your help! Commented 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? Commented Jan 16 at 14:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.