Bonjour,
J'aurais besoin d'aide, je souhaiterais mettre en place un trigger qui me permette, au moment de placer un point A parmi pleins de points B sous QGIS, de récupérer la valeur du champ "numero" de ma couche PointsB pour remplir mon champ "numeroB" de ma couche PointsA.
Je souhaiterais que ce trigger soit basé sur la condition du plus proche point B de mon point A.
J'ai essayé ça, mais ça ne fonctionne pas hmm
J'ai donc un schéma que l'on appellera "SchemaPoint" avec 2 couches :
PointsA
-numeroB (à remplir)
PointsB
-numero
puis
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 CREATE OR REPLACE FUNCTION "SchemaPoint".voisins() RETURNS trigger LANGUAGE 'plpgsql' COST 100 VOLATILE NOT LEAKPROOF AS $BODY$ BEGIN select into new.numeroB numero, ST_distance(new.geom, PointsB.geom) AS voisin FROM "SchemaPoint"."PointsA","SchemaPoint"."PointsB" order by voisin LIMIT 1; return new ; END; $BODY$;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 CREATE TRIGGER update_numero BEFORE INSERT OR UPDATE ON "SchemaPoint"."PointsA" FOR EACH ROW EXECUTE FUNCTION "SchemaPoint".voisins();
Partager