1

I have a shapefile with 1000 points and a layer with 30 000 polygons. Not all of the points overlap with the polygons. For all of these points, which are not overlapping with a polygons, I need to find a polygon, which is closest to the point.

How can I do this spatial join using QGIS?

5
  • 1
    Please decide which software you're going to use.
    – Erik
    Jan 27, 2021 at 13:36
  • Thank you for your comment, Erik. Preferebly ArcGIS Pro (but QGIS is also alright). Jan 27, 2021 at 13:50
  • 1
    Please remove a tag, otherwise your question will be closed as "needs more focus", since two softwares allow for two correct answers and you can't state, which is more correct. Also, you could add what you already tried.
    – Erik
    Jan 27, 2021 at 13:54
  • 1
    You can't do a spatial join if there is no spatial relationship. You can use a spatial search with a distance to find potential matches, encode the closest matching ID in a column, then attribute join by that.
    – Vince
    Jan 27, 2021 at 14:04
  • Since we already have a QGIS answer I’m retrofitting the question to that. If you still want an ArcGIS Pro answer then please ask fir that in a separate question.
    – PolyGeo
    Jan 27, 2021 at 19:16

1 Answer 1

2

Use overlay functions (available in QGIS 3.16+): create a new attribute with Field calculator on the point layer, using the following expression. You get a field that contains for each point the value of the nearest polygon's fid or an empty value if the current point is inside a polygon. Replace polygon (lines 3 and 7) with the name of your polygon layer:

if ( 
    overlay_disjoint( 
        'polygon'
    ),
    array_first (
        overlay_nearest ( 
            'polygon', 
            $id
        )
    )
    ,''
)

Screenshot: labels show the value of the created field, corresponding to the id of the nearest polygon. Points inside a polygon don't show a label as the content is empty: enter image description here

3
  • 1
    Hi Babel, though high quality and quick as usual, your answer doesn't suit the question (anymore).
    – Erik
    Jan 27, 2021 at 14:18
  • OK, but if it helpful for OP, should I delete it?
    – Babel
    Jan 27, 2021 at 14:18
  • 1
    We can retrofit the question to the answer by editing it and asking the asker to ask a separate question about ArcGIS Pro.
    – PolyGeo
    Jan 27, 2021 at 19:14

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.