2

I created buffers around the centroids of US counties and now I would like to save the information on which counties are included in the buffer.

One example: A 100 km buffer around the centroid of the county Los Angeles includes Los Angeles, Orange, San Bernadino, Riverside, Kern, and Ventura whereas the 100 km buffer around the centroid of the county San Bernadino only includes San Bernadino and Riverside.

I would like to save this information. Is that possible? I already tried it with "Intersection" but I always end up with a layer that exactly looks like the buffer and the attribute table does not include the name of all counties.

1
  • 1
    You want a spatial join, not an intersection.
    – Vince
    Commented Sep 5, 2022 at 12:29

2 Answers 2

1

You can create a new attribute with Field Calculator and this expression - change the buffer size in line 3 (20000) to the size you need. Be aware: distances are catesian distances in the CRS you use!

Polygon names in red; names of neighbouring polygons in black: enter image description here

with_variable(
    'buffer',
    buffer (centroid ($geometry), 20000),
    array_to_string(
        array_foreach (
            overlay_intersects (
                @layer,
                $id,
                limit:=10
            ),
            if (
                intersects (
                    geometry (get_feature_by_id (@layer, @element)),
                    @buffer
                ),
                attribute (get_feature_by_id (@layer, @element), 'NAME'), -- change NAME to the fieldname containing the information you want to get
                ''
            )
        )
    )
)
0

Join Attributes by Location feature can help you with this problem. Select overlap predicate and one-to-many join type. It will create separate rows for each matching feature. Refer to this answer for details.

2
  • I just realized that neighboring counties that are completely included by the buffer do not appear in the table. The table only creates a new row if the buffer zone touches the other county. Does anyone have a solution for that?
    – Julian H.
    Commented Sep 19, 2022 at 8:44
  • Did you try with 'are within' option checked in geometry predicate?
    – Abhijith
    Commented Sep 19, 2022 at 14:34

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.