[postgis-users] Convert x, y into geometry and update two geometries

Kevin Neufeld kneufeld at refractions.net
Wed Feb 6 08:55:42 PST 2008


Really? Your trigger seems to work for me.

CREATE SCHEMA test;

CREATE TABLE test.nodes (point_x int, point_y int, the_geom geometry);

CREATE OR REPLACE FUNCTION test.calc_point()
  RETURNS "trigger" AS
  $BODY$
  BEGIN
    NEW.the_geom:=SetSRID(MakePoint(new.point_x, new.point_y), -1) ;
  RETURN NEW;
  END
  $BODY$
  LANGUAGE 'plpgsql' VOLATILE;

CREATE TRIGGER insert_nodes_geom
  BEFORE INSERT OR UPDATE
  ON test.nodes
  FOR EACH ROW
  EXECUTE PROCEDURE test.calc_point();

INSERT INTO test.nodes (point_x, point_y) VALUES (1,2);

SELECT point_x,point_y,astext(the_geom) FROM test.nodes ;

 point_x | point_y |   astext  
---------+---------+------------
       1 |       2 | POINT(1 2)
(1 row)


Cheers,
Kevin


Broun Uganda wrote:
> When i use the code below, it is executed data is transferred to the 
> database but the geom is not inserted.
>
> CREATE OR REPLACE FUNCTION calc_point()
>
>   RETURNS "trigger" AS
>
> $BODY$BEGIN
>
> NEW.the_geom:=SetSRID(MakePoint(new.point_x, new.point_y), -1) ;
>
> RETURN NEW;
>
>  END$BODY$
>
>   LANGUAGE 'plpgsql' VOLATILE;
> CREATE TRIGGER insert_nodes_geom
>   BEFORE INSERT OR UPDATE
>   ON nodes
>   FOR EACH ROW
>   EXECUTE PROCEDURE calc_point();
>
> Broun Uganda
>
>
>
> ------------------------------------------------------------------------
> Express yourself instantly with MSN Messenger! MSN Messenger 
> <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>   



More information about the postgis-users mailing list