Message posté par : Nicolas Ribot
----------------------------------------
Il y a plusieurs façons de faire, par exemple:
• chercher s'il y a un candidat proche dans la table_point
• si data est null, chercher s'il y a un candidat proche dans la table_ligne
• Sinon, aucun candidat et NEW.data sera null:
-----------------
Code :
CREATE OR REPLACE FUNCTION monschema.TRIGGER3()
RETURNS "trigger" AS
$$
BEGIN
NEW.data := p.data
from table_point as p
where st_dwithin(st_startpoint(NEW.geom), (p.geom), 0.001);
if NEW.data is null then
NEW.data = m.data from table_ligne as m
where st_dwithin(ST_startpoint(NEW.geom), st_endPoint(m.geom), 0.001)
END IF;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql' VOLATILE;
-----------------
Vous pouvez inverser l'ordre des tests suivant la probabilité que NEW soit plutot
proche d'un point ou d'une ligne (pour éviter de faire un calcul inutile)
(pensez a virer les anciens triggers de la table !)
Nicolas
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=338169#p338169
Pour y répondre : geobd(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net