简体   繁体   English

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

[英]Convert a Normal Postgres Database to PostGis Database

I have a normal postgres database with lots of geo coded data.我有一个包含大量地理编码数据的普通 postgres 数据库。 This is just present two columns as latitude and longitude.这只是呈现两列作为纬度和经度。

I want to convert this database to PostGIs database.我想将此数据库转换为 PostGIs 数据库。 Can anyone suggest me a way to convert the database i have?任何人都可以建议我转换我拥有的数据库的方法吗? I don't want to create a new postgis tempalte based database and then move the whole data one by one.我不想创建一个新的基于 postgis 模板的数据库,然后一个一个移动整个数据。

First, make sure PostGIS is installed on the system, then create a PostGIS extension for the database using:首先,确保系统上安装了 PostGIS,然后使用以下命令为数据库创建PostGIS 扩展:

CREATE EXTENSION postgis;

Next, spatially enable each table with a geometry column and populate the column with the long/lat data points:接下来,使用几何列在空间上启用每个表,并使用长/纬度数据点填充该列:

ALTER TABLE mytable ADD COLUMN geom geometry(Point,4326);
UPDATE mytable SET geom = ST_SetSRID(ST_MakePoint(long, lat), 4326);

Also consider using the geography type:还可以考虑使用geography类型:

ALTER TABLE mytable ADD COLUMN geog geography(Point,4326);
UPDATE mytable SET geog = ST_MakePoint(long, lat)::geography;

I know this is older... but I'd add something to address a previous issue:我知道这是旧的......但我会添加一些东西来解决以前的问题:

@Cerin, make sure you apt-get install postgresql-xx-postgis-2.1, not just apt-get install postgis. @Cerin,确保您 apt-get install postgresql-xx-postgis-2.1,而不仅仅是 apt-get install postgis。 I had that issue before as well我之前也有这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM