Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created Postgres/PostGIS sequences before to assign unique gid values when a feature is created in QGIS but is it possible to create a sequence that will automatically populate an area column? Equally would it be possible for a sequence to be created to calculate the length of a line and even better the X Y values of a point?

share|improve this question
I believe it's not a sequence you are looking for. Sequence, create consequent numbers, what you want is to calculate values from your geometries, right? And If I understood well, you want to do it automaticly. I think for that you need to set triggers. – Alexandre Neto Jan 17 '13 at 9:52
I see, this is probably why I couldn't find anything on sequences and areas when doing a google search! – geosmiles Jan 17 '13 at 10:46
IF I'm reading the stuff on triggers correctly, then in theory I can create triggers to auto update fields for when a feature is created or edited? – geosmiles Jan 17 '13 at 10:50
exactly! See micha's example. – Alexandre Neto Jan 17 '13 at 19:07
up vote 4 down vote accepted

Here's a sample I use to update both lon/lat columns and x-y columns each time a point is added

CREATE OR REPLACE FUNCTION update_lonlat_coords()
  RETURNS trigger AS
DECLARE g integer;
    UPDATE rain_gauges 
        SET x_coord=ST_X(the_geom), y_coord=ST_Y(the_geom)    
        WHERE gauge_id=g;
    UPDATE rain_gauges 
        SET lon=ST_X(ST_TRANSFORM(the_geom,4326)), lat=ST_Y(ST_TRANSFORM(the_geom,4326))    
        WHERE gauge_id=g;
  COST 100;
share|improve this answer

A sequence isn't what you want here. You are looking for Triggers and Rules

Example coming

share|improve this answer

triggers can do that for you. Search for example, you have a plsql function that uses x y data to fill geometry column. Régis

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.