How to get attribute values of another layer with QGIS expressions

To get an array of all your values of a different layer with condition you can use




to get the feature IDs. You could also apply $currentfeature to get the features or $geometry for their geometries instead of $id.

So to reproduce your result at 3 with delimiters you could use array_to_string(aggregate('layer','array_agg',$id,"fieldname">50),',') for example, but this is of course a string again.

Also you can access the attributes as stated in "The Problem" via attribute(get_feature_by_id('layer',feature_id),'field') or attributes(get_feature_by_id('layer',feature_id)).

So seeing your screenshot I get what you are trying to do. This reminds somehow on Displaying vertex coordinates of a polygon or line without creating a new layer. We have quite the same issue here. If you wish to draw several lines from one feature to several destinations, one somehow would need the ability to iterate. Not sure how this could be done. Yet...

Instead of collecting the values and selecting back the geometry using this value, you can directly collect the geometries.

collect_geometries (
    array_foreach (
        aggregate (
        ) ,

enter image description here