You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnf"""CREATE OR REPLACE FUNCTION {self.layer}___length___{str(minimum).replace(".", "d")}_{str(maximum).replace(".", "d")}() RETURNS trigger AS $$ DECLARE length numeric; BEGIN SELECT ST_LENGTH(NEW.geom::geography) INTO length; IF length > {maximum} THEN RAISE EXCEPTION '{self.layer} is longer than {maximum}'; ELSE IF length < {minimum} THEN RAISE EXCEPTION '{self.layer} is shorter than {minimum}'; END IF; END IF; RETURN NEW; END; $$ LANGUAGE 'plpgsql'; CREATE CONSTRAINT TRIGGER {self.layer}___length___{str(minimum).replace(".", "d")}_{str(maximum).replace(".", "d")} AFTER INSERT OR UPDATE ON {self.layer} FOR EACH ROW EXECUTE FUNCTION {self.layer}___length___{str(minimum).replace(".", "d")}_{str(maximum).replace(".", "d")}();"""
28
+
returnf"""CREATE OR REPLACE FUNCTION {self.layer}___length___{str(minimum).replace(".", "d")}__{str(maximum).replace(".", "d")}() RETURNS trigger AS $$ DECLARE length numeric; BEGIN SELECT ST_LENGTH(NEW.geom::geography) INTO length; IF length > {maximum} THEN RAISE EXCEPTION '{self.layer} is longer than {maximum}'; ELSE IF length < {minimum} THEN RAISE EXCEPTION '{self.layer} is shorter than {minimum}'; END IF; END IF; RETURN NEW; END; $$ LANGUAGE 'plpgsql'; CREATE CONSTRAINT TRIGGER {self.layer}___length___{str(minimum).replace(".", "d")}_{str(maximum).replace(".", "d")} AFTER INSERT OR UPDATE ON {self.layer} FOR EACH ROW EXECUTE FUNCTION {self.layer}___length___{str(minimum).replace(".", "d")}_{str(maximum).replace(".", "d")}();"""
29
+
30
+
31
+
defnear(self, distance: float, other_layer: str):
32
+
returnf"""CREATE OR REPLACE FUNCTION {self.layer}___near___{other_layer}__{str(distance).replace(".", "d")}() RETURNS trigger AS $$ DECLARE within boolean; BEGIN SELECT Count(*) INTO within FROM {other_layer} WHERE ST_DWithin({other_layer}.geom, NEW.geom, {distance}); IF NOT within THEN RAISE EXCEPTION '{self.layer} is too far from {other_layer}'; END IF; RETURN NEW; END; $$ LANGUAGE 'plpgsql'; CREATE CONSTRAINT TRIGGER {self.layer}___near___{other_layer}__{str(distance).replace(".", "d")} AFTER INSERT OR UPDATE ON {self.layer} FOR EACH ROW EXECUTE FUNCTION {self.layer}___near___{other_layer}__{str(distance).replace(".", "d")}();"""
29
33
30
34
31
35
defas_dict(self) ->dict:
@@ -63,6 +67,21 @@ def __str__(self) -> str:
63
67
64
68
returnself.length(maximum, minimum)
65
69
70
+
ifself.constraint_type.type=="near":
71
+
try:
72
+
layer=self.constraint["layer"]
73
+
exceptKeyError:
74
+
raiseException("Constraint 'near' needs a relative layer value")
75
+
76
+
if"distance"inself.constraint:
77
+
distance=self.constraint["distance"]
78
+
try:
79
+
float(distance)
80
+
exceptValueError:
81
+
raiseException(f"Value '{distance}' is not a numeric value")
0 commit comments