QGIS Geometry Generator – Applying Geometry Generator for MultiPoint Features

expressiongeometry-generatormultipointpolygon-creationqgis

I have used the Geometry Generator in QGIS to successfully create a polygon around a point that represents the canopy of a tree based on the cardinal direction recordings.

What I cannot figure out or find any information on is how to make this work for a multi-point feature. The code below works on a single-point feature or the first part of a multi-point feature geometry but I want it to create the same 'canopy' polygon over each point in the multi-point feature.

collect_geometries( 
  geometries_to_array(
    convex_hull(
      combine(
          buffer(
            make_point($x-("TreeInfo_Canopy W"/2), $y),
            "TreeInfo_Canopy W"/2),
        combine(
          buffer(
            make_point($x+("TreeInfo_Canopy E"/2), $y),
            "TreeInfo_Canopy E"/2),
          combine(
            buffer(
              make_point($x, $y+("TreeInfo_Canopy N"/2)),
              "TreeInfo_Canopy N"/2),
            buffer(
              make_point($x, $y-("TreeInfo_Canopy S"/2)),
              "TreeInfo_Canopy S"/2)
          )
        )
      )
    )
  )
)

Best Answer

You need to make an array from MultiPoint geometry, but you try to make it from the Convex Hull (which is already one element, not multiple).

collect_geometries(
  array_foreach(
    geometries_to_array($geometry), -- make array from multipoint
    -- make convex_hull for each point
    convex_hull(
      combine(  -- combine(combined, combined)
        combine(  -- combine(buffer, buffer)
          buffer(
            make_point(
              x(@element)-("TreeInfo_Canopy W"/2),
              y(@element)),
            "TreeInfo_Canopy W"/2
          ),
          buffer(
            make_point(
              x(@element)+("TreeInfo_Canopy E"/2), 
              y(@element)),
            "TreeInfo_Canopy E"/2
          )
        ),
        combine(  -- combine(buffer, buffer)
          buffer(
            make_point(
              x(@element), 
              y(@element)+("TreeInfo_Canopy N"/2)),
            "TreeInfo_Canopy N"/2
          ),
          buffer(
            make_point(
              x(@element), 
              y(@element)-("TreeInfo_Canopy S"/2)),
            "TreeInfo_Canopy S"/2
          )
        )
      )
    )
  )
)

enter image description here

Move convex_hull( line to top line if you need the convex hull for the buffers of all points in the multipoint.

convex_hull(
  collect_geometries(
    ...
    ...

enter image description here

Related Question