3

I have a trigger set up in PostGIS/PostgreSQL which will show a RAISE WARNING when an inserted or updated polygon is within a certain distance of some predefined planning constraints. I want this warning to be sent to QGIS to alert a user to the proximity warning, but with a WARNING this does not occur. On the other hand, using RAISE EXCEPTION shows an error in the QGIS message bar but doesn't allow the insert/update to be committed (which I want - it should be a warning, not an error).

Example of the messages I want to be sent to QGIS:

CREATE TABLE input_table (
    id serial,
    geom geometry
             );

CREATE TABLE listed_buildings (
    id serial,
    geom geometry
             );

CREATE OR REPLACE FUNCTION check_constraint_proximity()
  RETURNS trigger AS
$BODY$
declare
dist_lb real;
begin
    dist_lb := (select st_distance(new.geom, st_collect(listed_buildings.geom)) from listed_buildings);

    if dist_lb <= 3 then
        RAISE WARNING 'Check planning boundary - it is within approx %m of a listed building', round(dist_lb);
    end if;
    if dist_lb <= 1 then
        RAISE EXCEPTION 'Check planning boundary - it is within approx %m of a listed building', round(dist_lb);
    end if;
    RETURN new;
end;
$BODY$
  LANGUAGE plpgsql;

CREATE TRIGGER check_constraint_proximity_trigger
  AFTER INSERT OR UPDATE
  ON input_table
  FOR EACH ROW
  EXECUTE PROCEDURE check_constraint_proximity();

insert into listed_buildings (geom) values (st_geomfromewkt('polygon((0 0, 0 1, 1 1, 1 0, 0 0))'));

insert into input_table (geom) values (st_geomfromewkt('polygon((2 2, 2 3, 3 3, 3 2, 2 2))'));
insert into input_table (geom) values (st_geomfromewkt('polygon((0 0, 0 1, 1 1, 1 0, 0 0))'));
  • These are asynchronous notifications. They get delivered to the client, but the client application has to know to read them. What client driver does qgis use? PgJDBC? nPgSQL? psqlODBC? Direct libpq? – Craig Ringer Mar 11 '14 at 11:59
  • It uses libpq directly: permalink.gmane.org/gmane.comp.gis.qgis.devel/4953 Hopefully a QGIS dev can help here then. – James N Mar 11 '14 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.