this seems like it should be a simple task but so far I've not had any luck. I have a points shapefile (showing where manholes are on public roads), and a polygon shapefile showing where building foot prints are. I want to take the attributes of the closest building footprint polygon to a manhole point - using a nearest distance algorithm. Is there any simple way to achieve this in QGIS?
2 Answers
My suggestion is refFunctions plugin, which will add geomnearest()
function to your Field Calculator
.
Then open the attribute table of your manhole
point layer and create a new field with an expression geomnearest('buildings', 'owner')
(if the layer name of your buildings is buildings
and you want to extract its owner
field. (Please note the single quotation marks, not double).
It will take the owner
field and add the information to your manhole
point layer.
-
Thanks Kazuhito! Your steps solved the issue perfectly. Appreciate the help!!! Commented Jun 6, 2018 at 22:56
-
refFunctions was integrated into QGIS 3.16 in 2020. As of QGIS 3.34 (2024) the functionality's accessed through
overlay_*()
in the field calculator. Commented May 9 at 21:20
If you want a simple tool to do the task, you could consider the NNJoin plugin. For each feature in the input layer (point, line, polygon), it finds the closest feature in the join layer (point, line, polygon). The resulting layer will for each input feature contain the distance to the closest join feature in addition to all the attributes of the input feature and the join feature.
-
Note for subsequent readers: NNJoin hasn't been updated since September 2019. As of QGIS 3.34.6 (May 2024), Vector -> NNJoin -> NNJoin fails with
TypeError: setValue(self, value: int): argument 1 has unexpected type 'float'
. Commented May 9 at 20:59