[GIS] Joining points with nearest polygon using QGIS

proximityqgisspatial-join

I have a points layer and polygons layer with attributes I want to join for each point. Not all points are exactly within a polygon, so I'm looking for a way to join attributes based on nearest polygon (so that if a point is located within a polygon it will just get its attributes).
I've tried using the NNJoin plugin, but I've noticed that for lots of points that are located within a polygon, it will joing attributes of a different polygon.

Best Answer

Try splitting your point data in two. First part would be the points that fall within a polygon and the second part would be points falling outside polygons. For the first part, perform a regular spatial join, and for the second part, use the NNJoin plugin. You can later merge the two resulting point layers into one. This way you can avoid the plugin performing an incorrect join on some of the points that fall within a polygon.

In order to select points that fall within the polygon layer, use the Spatial Query plugin (now a core QGIS plugin), then save the selection as a new layer. Invert the selection and save it as the second layer and perform the join using the NNJoin plugin.

Note that I have never used the NNJoin plugin.

Related Question