1. 首先创建一个多边形的表
CREATE
TABLE
shp_polygon
(
polygon_id serial NOT NULL ,
"name" character varying ( 40 ),
CONSTRAINT pk_shp_polygon PRIMARY KEY (polygon_id) USING INDEX TABLESPACE pg_default
) WITH (OIDS = FALSE)
TABLESPACE pg_default;
(
polygon_id serial NOT NULL ,
"name" character varying ( 40 ),
CONSTRAINT pk_shp_polygon PRIMARY KEY (polygon_id) USING INDEX TABLESPACE pg_default
) WITH (OIDS = FALSE)
TABLESPACE pg_default;
2. 使用Postgresql自带的“AddGeometryColumn”函数增加图形关系
AddGeometryColumn会自动为你所要的表增加一个代表坐标点的数据列,名为:the_geom,为geometry类型
AddGeometryColumn(数据库schema, 图形表名, 'the_geom', 投影坐标(eg: 4326), 图形类型(eg: POLYGON), 图形维数(eg: 2));
我们插入如下的代码:
SELECT
AddGeometryColumn(
'
public
'
,
'
shp_polygon
'
,
'
the_geom
'
,
4326
,
'
POLYGON
'
,
2
);
3. 检查geometry_columns表
select * from geometry_columns;
你会发现多了一行数据:
public shp_polygon the_geom 2 4326 POLYGON
4. 给图形表增加坐标数据
insert
into
shp_polygon(name, the_geom)
values ( ' Triangle ' , ST_GeomFromText( ' POLYGON((10 20, 20 40, 50 15, 10 20)) ' , 4326 ));
values ( ' Triangle ' , ST_GeomFromText( ' POLYGON((10 20, 20 40, 50 15, 10 20)) ' , 4326 ));