postgresql 如何更改几何列的 SRID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3012723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:34:37  来源:igfitidea点击:

How to change SRID of geometry column?

postgresqlpostgis

提问by Z77

I have a table where one of the columns is a geometry column the_geomfor polygons with an SRID. I added a new column in the same table with exactly the same geometry data as the_geom.

我有一个表,其中一列是the_geom具有 SRID 的多边形的几何列。我在同一个表中添加了一个新列,其几何数据与the_geom.

This new column has the name the_geom4258because I want to set its SRID to 4258. What is the procedure to change the geometry's SRID to another coordinate system? Is it enough to apply the following query:

这个新列的名称the_geom4258是因为我想将其 SRID 设置为 4258。将几何的 SRID 更改为另一个坐标系的过程是什么?是否足以应用以下查询:

UPDATE table SET the_geom4258=ST_SetSRID(the_geom4258,4258);

回答by amercader

You should use the ST_Transformfunction. Also use the function AddGeometryColumnto create your new column, to ensure all the necessary constraints are also created:

您应该使用ST_Transform函数。还可以使用函数AddGeometryColumn创建新列,以确保还创建了所有必要的约束:

SELECT AddGeometryColumn('table','the_geom4258',4258, 'POLYGON', 2);

UPDATE table SET the_geom4258 = ST_Transform(the_geom,4258);

ST_SetSRIDjust sets the projection identifier, but does not actually transform the geometries.

ST_SetSRID只是设置投影标识符,但实际上并不转换几何。