Skip to main content
added 423 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

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:

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:

added 451 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227
  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 (
                                 ''pt''''points'',  -- adapt the name of your points layer
                                 $geometry,
                                 filter:=value='  || @val  || ',
                                 limit:=@no-1
                             )'
                         )
                     ),
                     make_line (
                         $geometry, 
                         @element
                     )
                 )
             )
         )
     )
    
  2. DissolveApply Menu Vector > Geoprocessing tools > Dissolve to the result

  3. MultipartApply Menu Vector > Geometry tools > Multipart to Singleparts to Singlepartsthe 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

  1. Use Geometry by expression with this expression:

     convex_hull( 
         with_variable (
             'no',
             case
             when value = 12 then 8
             when value = 8 then 6
             when value = 2 then 4
             end,
             collect_geometries (
                 array_foreach (
                     with_variable(
                         'val',
                         value,
                         eval ('
                             overlay_nearest (
                                 ''pt'',
                                 $geometry,
                                 filter:=value='  || @val  || ',
                                 limit:=@no-1
                             )'
                         )
                     ),
                     make_line (
                         $geometry, 
                         @element
                     )
                 )
             )
         )
     )
    
  2. Dissolve result

  3. Multipart to Singleparts

  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

Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

  1. Use Geometry by expression with this expression:

     convex_hull( 
         with_variable (
             'no',
             case
             when value = 12 then 8
             when value = 8 then 6
             when value = 2 then 4
             end,
             collect_geometries (
                 array_foreach (
                     with_variable(
                         'val',
                         value,
                         eval ('
                             overlay_nearest (
                                 ''pt'',
                                 $geometry,
                                 filter:=value='  || @val  || ',
                                 limit:=@no-1
                             )'
                         )
                     ),
                     make_line (
                         $geometry, 
                         @element
                     )
                 )
             )
         )
     )
    
  2. Dissolve result

  3. Multipart to Singleparts