postgresql 中,geometry类型字段怎样插入操作

2025-03-31 11:34:05
推荐回答(1个)
回答1:

您好,很高兴为您解答。

首先,修改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了。

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

采用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=#