1

I'm using an SQLite trigger to add a buffer around another "POINT" layer based on entered values.

The buffers are being correctly added, but I'm encountering difficulty in preventing them from overlapping each other.

The primary concern is the final surface outcome, so the specific delineation of individual buffers is not critical.

I'm struggling to find a method to merge overlapping buffers.

This is my initial trigger:

CREATE TRIGGER add_geom
AFTER UPDATE OF delim, tampon ON ESPECES_HABITATS_ATTRIBUTS
FOR EACH ROW 
BEGIN
    INSERT INTO ESPECES_HABITATS_POLY (Visibilite, ESPECE, id_rel, geom, presence, COMPART, Dval, Tval, LIB_PHYSIO)
    SELECT 'Oui', '{' || EP.nom_simple || '}', EP.pkuid, 
           ST_Buffer(EP.geom, NEW.tampon) AS geom,
           'Avérée', NEW.compart, NEW.delim, NEW.tampon, '-'
    FROM ESPECES_PT EP
    WHERE NEW.tampon > 0 
      AND NEW.delim = 'Tampon' 
      AND EP.nom_simple = NEW.ESPECE
      AND NOT EXISTS (
          SELECT 1 
          FROM ESPECES_HABITATS_POLY EHP 
          WHERE EHP.id_rel = EP.pkuid
      );
END;

I tried different solutions (i. e.:

coalesce(
       ST_Union(
           ST_Buffer(EP.geom, NEW.tampon),
           (SELECT geom FROM ESPECES_HABITATS_POLY WHERE ST_Intersects(ST_Buffer(EP.geom, NEW.tampon), geom))
       ),ST_Buffer(EP.geom, NEW.tampon))


ST_Difference(
               ST_Buffer(EP.geom, NEW.tampon),
               (SELECT ST_Union(geom) 
                FROM ESPECES_HABITATS_POLY 
                WHERE ST_Intersects(ST_Buffer(EP.geom, NEW.tampon), geom))
           ) AS geom

)

0