Using only the QGIS expressions and "Select by Expression", the expression to use is:
/*Select the first 'n' points closest to the selected point*/
-- fid selection
with_variable (
'selected_fid',
array_find(
array_agg(geom_to_wkt($geometry, 6)),
array_agg(geom_to_wkt($geometry, 6), filter:=is_selected())[0]
),
-- selection circle
with_variable(
'circle',
make_circle(
$geometry,
aggregate(
layer:=@layer_name,
aggregate:='array_agg',
expression:=array_max(
array_foreach(
overlay_nearest(@layer_name, $geometry,limit:=10),
distance($geometry,@element)
)
)
)[@selected_fid]
),
-- verify
intersects(@circle, array_agg($geometry)[@selected_fid])
)
)
the selected_fid variable selects the index value of the selected geometry within the array;
the variable circle creates a circle with the center of the selected point and the radius equal to the furthest point within 10 points.
NB: the value of the limit:= argument depends on the provider:
- if shapefile:
limit:= value + 1
- if GeoPackage:
limit:= value
this is because $id starts from scratch in shapefiles
The value to be changed is the limit, for example if you want to select the first 1000 points you have to write limit:= 1000.
