In the PostGIS documentation it says that there are two steps to creating a spatial table with SQL:
- Create a normal non-spatial table.
- Add a spatial column to the table using the OpenGIS "AddGeometryColumn" function.
If I followed the examples, I would create a table called terrain_points
like this:
CREATE TABLE terrain_points (
ogc_fid serial NOT NULL,
elevation double precision,
);
SELECT AddGeometryColumn('terrain_points', 'wkb_geometry', 3725, 'POINT', 3 );
Alternatively, if I look at existing tables in pgAdmin III, it seems like I could create the same table like this:
CREATE TABLE terrain_points
(
ogc_fid serial NOT NULL,
wkb_geometry geometry,
elevation double precision,
CONSTRAINT terrain_points_pk PRIMARY KEY (ogc_fid),
CONSTRAINT enforce_dims_wkb_geometry CHECK (st_ndims(wkb_geometry) = 3),
CONSTRAINT enforce_geotype_wkb_geometry CHECK (geometrytype(wkb_geometry) = 'POINT'::text OR wkb_geometry IS NULL),
CONSTRAINT enforce_srid_wkb_geometry CHECK (st_srid(wkb_geometry) = 3725)
)
WITH (
OIDS=FALSE
);
ALTER TABLE terrain_points OWNER TO postgres;
-- Index: terrain_points_geom_idx
-- DROP INDEX terrain_points_geom_idx;
CREATE INDEX terrain_points_geom_idx
ON terrain_points
USING gist
(wkb_geometry);
Do these two methods produce the same result? Is the version based on pgAdmin III simply more verbose, and doing things that AddGeometryColumn
would do by default?
Answer
No, they are not producing the same results.
With the second method you would still need to add a record in the GEOMETRY_COLUMNS table, and you would need to do it with an INSERT statement, or using the Populate_Geometry_Columns function as suggested in the other answer.
AddGeometryColumn will take care of doing this for you (together with creating the index and the constraints).
No comments:
Post a Comment