I am looking for the distance of the closest point (Layer 1) to my atlas object (Layer 2). I want to use the expression builder.
Example: I have a House, which is also the atlas_feature, on 'Layer A'. I have bus stations which are on 'Layer B'. I want to get the distances to the closest Bus Station on 'Layer B'.
For getting the Name of the closest Busstation on 'Layer B' I am using reffunctions geomnearest
. However, I also need the distance to the closest one.
distance($geometry, geomnearest('Busstation','$geometry'))
?geomnearest('other_layer_name','$geometry')
, it returns the geometry field / attribute of the other layer, so, geometry.geomnearest
returns the result as a WKT (string). So, just add the functiongeom_from_wkt
as :distance(geom_from_wkt(geomnearest('Haltestelle_KBS', '$geometry')), $geometry)
. It'll work.Preview
text : docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/…