Automating multiple route computation using batch processing
If you have multiple input point layers, you can use Processing's batch processing capabilities to speed up the process. In this recipe, we will compute routes for two input point layers at once, but the same approach can be applied to many more layers.
To follow this recipe, load network_pgr.shp and the two point layers, sample_pts_for_routing.shp and sample_pts_for_routing2.shp.
To get started, right-click on the point layer to route tool in the Processing Toolbox option and select Execute as batch process. Then perform the following steps:
- In the points column, click the … button and use the Select from open layers option to select
sample_pts_for_routing and sample_pts_for_routing2. - Select and remove the third line using the Delete row button at the bottom of the dialog.
- In the network column, click the … button and use the Select from open layers option to select
network_pgr. You can avoid having to pick the file twice by double-clicking on the table header entry (where it reads network). This will autofill all rows with the same network file path. - In the routes column, you need to pick a path for the resulting route files. In the Save file dialog, which opens when you click on the … button, you can specify one base filename and click on Save. The following Autofill settings dialog lets you specify if and how you want to have the rows filled. Use Autofill mode Fill with numbers and Processing will automatically append a running number to the filename that you specified. You can see an example in the following screenshot where we specified route as the base filename.
- Click on Run to execute the batch process. Both routes will be computed and loaded automatically: