Database Reference
In-Depth Information
INSERT INTO chp02.xwhyzed1 (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed1 (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed1 (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed1 (x, y, z)
VALUES (random()*5, random()*7, random()*106);
How to do it...
Nowweneedageometrycolumntopopulate.Bydefault,thegeometrycolumnwill
be populated with null values. We populate a geometry column using the following
query:
SELECT AddGeometryColumn
('chp02','xwhyzed1','geom',3734,'POINT',2);
Wenowhaveacolumncalled
the_geom
withanSRIDof
3734
,thatis,apointgeo-
metrytypeintwodimensions.Sincewehavex,y,zdata,wecould,inprinciple,pop-
ulate a 3D point table using a similar approach.
Since all the geometry values are currently null, we will populate them using an
UPDATE
statement as follows:
UPDATE chp02.xwhyzed1
SET geom = ST_SetSRID(ST_MakePoint(x,y),
3734);
The query here is simple when broken down. We update the table
xwhyzed1
and
setthe
the_geom
columnusing
ST_MakePoint
,constructourpointusingthexand
ycolumns,andwrapitinan
ST_SetSRID
functioninordertoapplytheappropriate
spatialreferenceinformation.Sofarwehavejustsetthetableup.Nowweneedto
createatriggerinordertocontinuetopopulatethisinformationoncethetableisin