POSTGIS:触发器插入相应的最大区域

POSTGIS: TRIGGER insert into according max area

我没有成功使用以下代码。 我正在我的数据库中编辑多边形。这将是伟大的,如果 我的新多边形从背景层 "polya" 获取特定值。 不幸的是,我的新层可能不关心背景层的边界。在这种情况下,它应该取值 我编辑的大部分内容与背景层相交。 我希望你能帮助我。

Overview_QGIS

BEGIN
    SELECT string_agg(polya."FOO1",', '))
    INTO NEW."FOO2"
    FROM "xyz" as polya
    WHERE                                       
   ST_AREA(ST_Intersection(NEW.the_geom,polya.the_geom))=GREATEST(ST_AREA(ST_Intersection(NEW.the_geom,polya.the_geom)));
    RETURN NEW;
   END;

按面积降序排列相交多边形,并将结果集限制为 1。

BEGIN

    SELECT polya.FOO1
    INTO   NEW.FOO2
    FROM   yxz as polya
    WHERE  ST_Intersects(NEW.the_geom,polya.the_geom)
    ORDER BY ST_Area(ST_Intersection(NEW.the_geom,polya.the_geom)) desc
    LIMIT 1;

    RETURN NEW;
END;