2

I have a project that I am required to aggregate points inside polygons that have a common value. Basically having QGIS to create a buffer around those points.

enter image description here

The dark green arrows have a unique value of 12, and I need to fit 6 of them inside a polygon. The dark blue arrows have a unique value of 16, and I need to fit 4 of them inside a polygon.

The other arrows have other values but follow the same idea of the previous two.

I already used several tools: Concave hull, Attribute based clustering and other native tools from QGIS. None gave me the result I need.

From my understanding, I need a tool that checks the points that are in the neighborhood of other points (that share the same value) and then it creates a polygon around them (but never having more points than those I tell it).

1

1 Answer 1

1

Connect all points with a line to the n nearest points with the same attribute value, where n is the number of points you want to aggregate to a group. You can use different values for n for different attribute values (like based on your example n=6 for value=12).

Then create the convex hull of these lines, dissolve the result and convertt multipart to single part geometries. To do this, proceed as follows:

  1. Use Geometry by expression with this expression:

     convex_hull( 
         with_variable (
             'no',
             case
             when value = 12 then 8  -- define here how many points you want to cluster together for each value
             when value = 8 then 6
             when value = 2 then 4
             end,
             collect_geometries (
                 array_foreach (
                     with_variable(
                         'val',
                         value,
                         eval ('
                             overlay_nearest (
                                 ''points'',  -- adapt the name of your points layer
                                 $geometry,
                                 filter:=value='  || @val  || ',
                                 limit:=@no-1
                             )'
                         )
                     ),
                     make_line (
                         $geometry, 
                         @element
                     )
                 )
             )
         )
     )
    
  2. Apply Menu Vector > Geoprocessing tools > Dissolve to the result

  3. Apply Menu Vector > Geometry tools > Multipart to Singleparts to the output.

Result: Points with value 2 are grouped to groups of 4 , value 8 to groups of 6, value 12 to groups of 8: enter image description here

Result after step 1 with geometry generator:

enter image description here

2
  • Thanks, but that solution doesn't work. Using it creates overlapped polygons :/
    – Andre
    Commented Apr 4, 2022 at 16:04
  • This solution works based on what kind of data you have. Structured as in my test case, it produces the correct result, but that might not be the case for your data. So providing sample data would be a good idea.
    – Babel
    Commented Apr 4, 2022 at 17:01

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.