QGIS – How to Attribute Each Data Point to a Specific Buffer ID in QGIS

bufferexportqgisunique id

I have many datapoints within 57 buffers in GIS (see picture for an example of a couple of the. buffers with datapoint inside). I need to be able to analyze each buffer separately, and therefore need a unique ID representing which data point comes from which buffer.

If I don't 'export by location' iteratively, and just have one layer with all the points extracted from the buffer, is there a way to make GIS attribute each datapoint with an ID that indicates which buffer that data point is within?

57 buffers

Best Answer

On your datapoints layer (red in the screenshot below), create a new attribute with field calculator using this expression:

array_first (overlay_nearest('buffer',$id))

Replace buffer with the name of your buffer layer. Where two buffers overlap, you'll get the id of the "closer" one: the one with the nearest centroid.

Red datapoints labeled with the id of the buffer: enter image description here

Related Question