I'd like to know how to get nearest points of the layer "a" to another point layer "b", using fields calculator of QGIS.
Layer "a" has points with 2 different id (1,2) and i want to get the closest points for each id.
For example:

Any suggestions?
I'd like to know how to get nearest points of the layer "a" to another point layer "b", using fields calculator of QGIS.
Layer "a" has points with 2 different id (1,2) and i want to get the closest points for each id.
For example:

Any suggestions?
On layer b, use this expression to get the closest point on layer a with the same id. Use Geometry Generator or Geometry by expression (see here for details):
with_variable (
'id',
id,
eval (
'overlay_nearest (
''a'',
$geometry,
filter:= id = ' ||
@id ||
')[0]'
)
)
Sollution using Geometry generator: layer b = red points; layer a = blue points; red triangle = closest point on layer b from points of layer b with same id:

Open the field calculator in the b layer and paste this expression: overlay_nearest('a_layer_id', $id)[0]. Replace a_layer_id with the id of the a layer.
overlay_nearest must be a layer name. And: I'm not sure if that is what OP is looking for - if they look to create an id in the attribute table of if the geometry should be rendered.
– Babel
Jun 14 '22 at 14:57
overlay_nearest function, the first argument can be a name or an ID.
– Mayo
Jun 14 '22 at 15:08
join attributes by nearest? – Erik Jun 14 '22 at 14:26