1

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

4
  • As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please Edit your Question to only ask one question.
    – Vince
    Commented Aug 21, 2021 at 17:33
  • You don't say what GIS system you are using! In ArcMap this would be the spatial Join tool.
    – Hornbydd
    Commented Aug 21, 2021 at 17:43
  • Apologies, it's QGIS. Commented Aug 21, 2021 at 17:57
  • Look at this tutorial.
    – Hornbydd
    Commented Aug 21, 2021 at 19:16

1 Answer 1

1

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

4
  • Thanks - this answer works, however I will be doing this in two separate layers, and when I try this method the buffer ID begins at "1" for both layers, when in reality I need the buffer IDs from the second layer to begin at "58" (as there are 57 buffers in the first layer). Is there a way I can alter the ID of this second layer? Commented Aug 24, 2021 at 14:28
  • Yes. You can create a new field with field calculator, give it a name (let's say id_new) and use the expreesion $id+57 to create the values. $id 1 will get a value of 58, $id 2 a value of 59 etc. Than in the expression from above, at the end replace $id with the name of the new attribute (like id_new in my case).
    – Babel
    Commented Aug 24, 2021 at 14:38
  • Thanks so much! Out of curiosity, in the "array_first (overlay_nearest('buffer',$id))" expression, where does the "$id" come from? Does QGIS automatically generate this id for each buffer, or is it based on the row number, or something else? Commented Aug 24, 2021 at 15:21
  • Yes, $id is automatically created for each feature - it's kind of numbering the features for identification purpose.
    – Babel
    Commented Aug 24, 2021 at 15:22

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.