| 143 | }}} |
| 144 | (if using Windows can use the Query Editor that comes with pgAdmin III) |
| 145 | |
| 146 | Populate existing entries: |
| 147 | {{{ |
| 148 | su postgres |
| 149 | psql |
| 150 | \d sahana |
| 151 | UPDATE public.gis_location SET the_geom = ST_SetSRID(ST_GeomFromText(wkt), 4326); |
| 152 | exit |
| 153 | }}} |
| 154 | |
| 155 | Ensure that future entries auto-populate properly: |
| 156 | {{{ |
| 157 | su postgres |
| 158 | psql |
| 159 | \d sahana |
| 160 | CREATE OR REPLACE FUNCTION s3_update_geometry() |
| 161 | RETURNS "trigger" AS |
| 162 | $BODY$ |
| 163 | DECLARE |
| 164 | BEGIN |
| 165 | |
| 166 | if (NEW.wkt != '') then |
| 167 | NEW.the_geom = SetSRID(GeomFromText(NEW.wkt), 4326); |
| 168 | end if; |
| 169 | |
| 170 | RETURN NEW; |
| 171 | END; |
| 172 | $BODY$ |
| 173 | LANGUAGE 'plpgsql' VOLATILE; |
| 174 | ALTER FUNCTION s3_update_geometry() OWNER TO sahana; |
| 175 | CREATE TRIGGER s3_locations_update |
| 176 | BEFORE INSERT |
| 177 | ON gis_location |
| 178 | FOR EACH ROW |
| 179 | EXECUTE PROCEDURE s3_update_geometry(); |
| 180 | |
| 181 | exit |
| 182 | }}} |
| 183 | |
| 184 | Tell Sahana that the DB is spatially-enabled so that routines can make use of this: |
| 185 | {{{ |