4

I have a set of addresses defined by the green dot. I have also objects (poles) to which I would like to assign the address (3-4 data attribute columns) from the nearest address point (green).

enter image description here

I tried to use the Nearest Neighbour analysis but I had a problem with the hub layer attribute, as I have to pick up just one.

How can I transfer interesting columns from the nearest point (different layer) to my layer?

UPDATE:

Maybe a more accurate image is below. I would like to have the address of the nearest point included in the point shown (different layer).

enter image description here

5
  • 1
    Look at overlay_nearest : docs.qgis.org/3.22/en/docs/user_manual/expressions/… Feb 17, 2022 at 15:44
  • OK, so now can I use this expression as a selection right?
    – Geographos
    Feb 17, 2022 at 16:04
  • What do you mean by "3-4 data attribute columns"? Feb 17, 2022 at 17:02
  • I have address split by 3-4 columns: 1 - address line 1 2 address line 2, 3 - county, 4 postcode
    – Geographos
    Feb 17, 2022 at 17:04
  • so : overlay_nearest('your_address_layer_name', addr_fld1 || ' ' || addr_fld2)[0] Feb 17, 2022 at 17:16

2 Answers 2

7

Open Field Calculator for "poles" layer and use this expression:

overlay_nearest(
    layer:='poles',
    expression:="address line 1" || ' ' || "address line 2" || ' ' || "county" || ' ' || "postcode"
)[0]

enter image description here

3
  • Looks nice! Where can I place it? I used the "Select by expression" option and this formula seems to be not valid. Is it the right place?
    – Geographos
    Feb 17, 2022 at 17:25
  • Ok. I've edited the answer Feb 17, 2022 at 17:37
  • OK, many thanks. Now it makes sense. I think, that it applies to all expressions. Thet should go to the field calculator instead of the "Select by the expression" as I thought initially.
    – Geographos
    Feb 17, 2022 at 22:20
4

I think I found the solution, which is explained in this article:

https://opensourceoptions.com/blog/spatial-joins-with-qgis-using-the-join-attributes-by-nearest-tool/

For the situations such as this we can use: Processing Toolbox -> Vector general -> Join attributes by nearest

where we can clearly define the layer where we want to pick up our data (multiple columns) and the layer to which this data should be assigned.

By leaving the nearest neighbor as 1 we can get this data from the nearest item as requested. enter image description here enter image description here

and a new layer will include both Layer 1 attributes as well as assigned from the nearest object of the second layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.