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?

  • 1
    Please decide which software you're going to use.
    – Erik
    Commented Jan 27, 2021 at 13:36
  • Thank you for your comment, Erik. Preferebly ArcGIS Pro (but QGIS is also alright). Commented 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
    Commented 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
    Commented 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
    Commented Jan 27, 2021 at 19:16

1 Answer 1


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 ( 
    array_first (
        overlay_nearest ( 

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

  • 1
    Hi Babel, though high quality and quick as usual, your answer doesn't suit the question (anymore).
    – Erik
    Commented Jan 27, 2021 at 14:18
  • OK, but if it helpful for OP, should I delete it?
    – Babel
    Commented 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
    Commented Jan 27, 2021 at 19:14

Your Answer

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

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