I am using QGIS 3.24,
I have 2 polylines layers:
- First one is composed of 2 rivers, crossing. The two of them are named 1 and 2
- Second one is composed of parallel lines form this rivers. 5 and 6
Starting from my parallel layer (red), i would like to find the nearest entity in my layer river (blue), BUT with a filter. Indeed, i want to join parallel line with the same river they're from. So I DON'T want my parallel line 5 to be joined with my river 1, but i want it to be joined with my river 2.
I've tried this, with field_calculator, from my layer parallel:
array_to_string(overlay_nearest('river_layer',id,filter:=river_name='river_name',limit:=1))
id is id from river_layer
But nothing happens! If i write it like this:
array_to_string(overlay_nearest('river_layer',id,filter:=river_name='1',limit:=1))
It's working, but it's only pointing to entity from river 1, ofc.
I've read https://github.com/qgis/QGIS/issues/43146 but I don't get this formula: \'layer2\'
? Why \
? And this [0]
? I don't get it neither.
I think I've misled the first answerer. My river is 'segmented', so it may cause some trouble with that answer, even if it could work:
On this picture, lines 31, 32, 33 and 34 are from the same river (It's already stored in my tables, river and parallel lines). I have 4 parallel lines, and they are segmented too (I marked them with point at the middle of them). We can imagine a part of the attribute table like this:
If I put a buffer on my river (I can even do it BEFORE river is segmented), I fear that some parallel segmented lines might be associated with the wrong river, like on my picture, which shows some errors:
Maybe I could create a virtual layer, with something like this, considering P_para_line
as my point layer with points in the middle of parallel segmented lines:
SELECT
ST_startpoint(ST_ShortestLine(p.geometry, r.geometry)),
r.id AS id_of_the_segmented_portion_of_river,
ROUND(ST_Length(ST_ShortestLine(r.geometry, p.geometry)), 6) AS distance
FROM
P_para_line AS p, river_layer AS r
WHERE
p.river_name = r.river_name
After this, I get way too many points on the same coordinate! I wish I could keep only the point with the shortest distance. I can suppress other points manually, but I think i can change my virtual layer query.