QGIS – How to Put End Points with Same Rows as Start Points Using Shortest Path Tool on Network Roads

batchNetworkqgisqgis-expressionshortest path

I have 2 point layers containing XY in qgis and I'm trying to get the shortest paths between each rows along a given network (row1 in first layer to row1 in second layer and so on). I used this expression which I added in the batch of the tool – autofill bar:

start point – aggregate ( 'first layer', 'array_agg', $geometry)

end point – aggregate ( 'second layer', 'array_agg', $geometry)

the problem is that it adds the end point as additional rows (see picture below).
How do I making it to put the end points in the correct rows?

1

Best Answer

If the feature id is the 1-1 relation between start and end points use this.

Use this expression to calculate the Start point column. Fill down with the Add Values by Expression… option.

aggregate(
    'first layer',
    'array_agg',
    $geometry,
    order_by:=$id
)

Then select the network layer in the Vector layer representing network column and use the Fill Down option to fill all the rows with the same layer.

Then calculate the End point column with this expression. Fill down using the Calculate by Expression… option.

aggregate(
    'first layer',
    'array_agg',
    $geometry,
    order_by:=$id
)[@row_number]