Database Reference
In-Depth Information
ALTER TABLE chp02.xwhyzed ADD COLUMN gid serial;
ALTER TABLE chp02.xwhyzed ADD PRIMARY KEY (gid);
Now let's populate this with data for testing using the following query:
INSERT INTO chp02.xwhyzed (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed (x, y, z)
VALUES (random()*5, random()*7, random()*106);
INSERT INTO chp02.xwhyzed (x, y, z)
VALUES (random()*5, random()*7, random()*106);
How to do it...
Now to create theview, we will use the following query:
-- Ensure we don't try to duplicate the view
DROP VIEW IF EXISTS chp02.xbecausezed;
-- Retain original attributes, but also create
a point attribute from x and y
CREATE VIEW chp02.xbecausezed AS
SELECT x, y, z, ST_MakePoint(x,y)
FROM chp02.xwhyzed;
How it works...
Our view is really a simple transformation of the existing data using PostGIS's
ST_MakePoint function.The ST_MakePoint functiontakestheinputoftwonum-
berstocreateaPostGISpoint;inthiscase,ourviewsimplyusesour x and y values
to populate the data. Any time there is an update to the table to add a new record
withxandyvalues,theviewwillpopulateapoint,whichisreallyusefulfordatathat
is constantly being updated.
Search WWH ::




Custom Search