如何修改Postgresql中空间字段的SRID

因为倒入shp时没有指定相应的SRID,会造成入库数据中SRID取值为-1。当知道了空间对象的坐标系时,如何将空间几何体修改为新的坐标系ID呢。

首先,修改geometry_columns表中对应字段的SRID为新的坐标系ID;

其次,修改beijing_highway表的定义,将enforce_dims_the_geom的定义的(st_srid(the_geom) = (-1))删除(注:此处the_geom是空间字段);

然后,更新数据内容 update table_name set the_geom = st_geomfromtext(ST_AsText(the_geom),4326)(注:此处4326为数据的坐标系ID);

最后,将enforce_dims_the_geom的定义(st_srid(the_geom) = (4326))加回去就可以变更SRID了。

如果是从一个坐标系向另外一个坐标系调整,就需要进行坐标系的变换了。这时候你可能会意识到,字段是只能增加,也就是插入。

此处可以参考别人的一篇博文,http://hi.baidu.com/jrc520/blog/item/d070d84385987c0072f05daf.html

采用postgis函数将墨卡托投影变成4326并插入空间数据库

QuanGuo=# insert into test values(1,’hahaha’,st_transform(st_geomfromtext(‘POINT
(10070507.650288 4282901.6281314)’,900913),4326));
INSERT 0 1
QuanGuo=# select astext(location) from test;
                  astext
——————————————
 POINT(-104.987 39.739)
 POINT(-104.955 39.739)
 POINT(10 10)
 POINT(10070507.650288 4282901.6281314)
 POINT(90.4649094109628 35.8711162526031)
(5 rows)

QuanGuo=#

转载自:https://blog.csdn.net/cnhome/article/details/6990060

You may also like...