Skip to main content
changed within to intersects, updated with array functions and ordering
Source Link
she_weeds
  • 13k
  • 1
  • 32
  • 64

Assuming all your line features are on the same layer, try

aggregate('line_layer_name','concatenate',"line_name_field",withinintersects($geometry,buffer(geometry(@parent),10)),'\n')

in the label expression for your point feature.

Change 1010 to whatever distance you want to pick up features from, and \n\n to whatever you want to delimit each line name with (comma, full stop, comma+newline...)

Note however it comes in2020 update:

As of QGIS 3.8 you can order the resulting features by any order you want (alphabetically by line_name_field, or by id...) by adding it as an extra parameter (order_field below):

aggregate('line_layer_name','concatenate',"line_name_field",intersects($geometry,buffer(geometry(@parent),10)),'\n',"order_field")


As a bonus, another alternative for more complex list scenarios is to use array_agg and access the full suite of array functions to slice and dice the line featureidlist however you want. For example if you have a very long list and notwant it to:

  • show only distinct values
  • be in alphabetical order
  • showing just the first 3 and last items

You could use something like this:

array_to_string(
        with_variable('label_array',

                      array_sort(array_distinct(  
                                 aggregate('line_layer_name','array_agg',                                                       
                                 "line_name_field", intersects($geometry,
                                 buffer(geometry(@parent),10))))),

                      array_cat(array_slice(@label_array,0,2),
                                array('...',@label_array[-1]))),
        '\n' )`

You could then change array_slice(@label_array,0,2) to 0,5 or any range you want to easily change the valuenumber of "line_name_field"items displayed.

enter image description here

Assuming all your line features are on the same layer, try

aggregate('line_layer_name','concatenate',"line_name_field",within($geometry,buffer(geometry(@parent),10)),'\n')

in the label expression for your point feature.

Change 10 to whatever distance you want to pick up features from, and \n to whatever you want to delimit each line name with (comma, full stop, comma+newline...)

Note however it comes in order of the line featureid and not the value of "line_name_field".

Assuming all your line features are on the same layer, try

aggregate('line_layer_name','concatenate',"line_name_field",intersects($geometry,buffer(geometry(@parent),10)),'\n')

in the label expression for your point feature.

Change 10 to whatever distance you want to pick up features from, and \n to whatever you want to delimit each line name with (comma, full stop, comma+newline...)

2020 update:

As of QGIS 3.8 you can order the resulting features by any order you want (alphabetically by line_name_field, or by id...) by adding it as an extra parameter (order_field below):

aggregate('line_layer_name','concatenate',"line_name_field",intersects($geometry,buffer(geometry(@parent),10)),'\n',"order_field")


As a bonus, another alternative for more complex list scenarios is to use array_agg and access the full suite of array functions to slice and dice the list however you want. For example if you have a very long list and want it to:

  • show only distinct values
  • be in alphabetical order
  • showing just the first 3 and last items

You could use something like this:

array_to_string(
        with_variable('label_array',

                      array_sort(array_distinct(  
                                 aggregate('line_layer_name','array_agg',                                                       
                                 "line_name_field", intersects($geometry,
                                 buffer(geometry(@parent),10))))),

                      array_cat(array_slice(@label_array,0,2),
                                array('...',@label_array[-1]))),
        '\n' )`

You could then change array_slice(@label_array,0,2) to 0,5 or any range you want to easily change the number of items displayed.

enter image description here

Source Link
she_weeds
  • 13k
  • 1
  • 32
  • 64

Assuming all your line features are on the same layer, try

aggregate('line_layer_name','concatenate',"line_name_field",within($geometry,buffer(geometry(@parent),10)),'\n')

in the label expression for your point feature.

Change 10 to whatever distance you want to pick up features from, and \n to whatever you want to delimit each line name with (comma, full stop, comma+newline...)

Note however it comes in order of the line featureid and not the value of "line_name_field".