将普通Postgres数据库转换为PostGis数据库

时间:2013-02-24 06:57:35

标签: database postgresql postgis

我有一个普通的postgres数据库,里面有很多地理编码数据。这只是纬度和经度两列。

我想将此数据库转换为PostGIs数据库。任何人都可以建议我转换数据库的方法吗?我不想创建一个新的postgis tempalte数据库,然后逐个移动整个数据。

2 个答案:

答案 0 :(得分:9)

首先,将PostGIS 2.x安装到您的系统上。以下是psql或pgAdmin III的工作流程:

-- Spatially enable the database
CREATE EXTENSION postgis;

-- Spatially enable each table with a geometry column
--      [ also consider using "geog geography(Point,4326)" ]
ALTER TABLE mytable ADD COLUMN geom geometry(Point,4326);
UPDATE mytable SET geom = ST_SetSRID(ST_MakePoint(long, lat), 4326);

答案 1 :(得分:2)

我知道这已经过时了......但是我要添加一些内容来解决之前的问题:

@Cerin,请确保apt-get install postgresql-x.x-postgis-2.1,而不仅仅是apt-get install postgis。我之前也遇到过这个问题