Using QGIS 3.30, I have a (line) layer of streams, each with a name attribute.
I am looking for a QGIS expression to find the distance to the nearest stream with the same name, or NULL if there is only the one stream with that name in the layer. For some names, there may be up to 11 streams with the same name.
It seems to me that this should be possible using overlay_nearest, using a filter of same name and different id, but have had no luck coming up with the right expression.
I'd thought something along these lines, but this returns nothing. In any case, it also needs to exclude the item with the same ID.
with_variable('parent_name',"name", with_variable('parent_id',@id, overlay_nearest(@layer, filter:=@parent_name="name", expression:=distance( @geometry,geometry(get_feature_by_id(@layer,@parent_id)) ) ) )) This question: Find nearest point with the same attribute appears similar, but the answers didn't seem to help, probably because the items with the same name are not necessarily nearby.
A copy of the dataset can be found at https://ozultimate.com/downloads/dcs_streams.gpkg


attribute(@parent, 'name') = "name".@parentdoesn't work inside an overlay function. It works for aggregate functions only - see the answers here: gis.stackexchange.com/q/391120/88814