[英]Why do I get different geometry value when using st_transform vs changing the table SRID?
I have a table "people" with SRID set to 4326 for the geometry column in the "geometry_columns" postgis view.对于“geometry_columns”postgis 视图中的几何列,我有一个表“人”,其 SRID 设置为 4326。 The value of the geometry column for my record X is:
我的记录 X 的几何列的值是:
"0101000020E6100000000000000080404000000000008040C0"
“0101000020E6100000000000000080404000000000008040C0”
I know I can change the SRID (eg from 4326 to 3003) of that geometry column by updating it in the mentioned view, as follows:我知道我可以通过在上述视图中更新该几何列的 SRID(例如,从 4326 到 3003)来更改它,如下所示:
ALTER TABLE people
ALTER COLUMN geometry_column TYPE geometry(POINT, 3003)
USING ST_SetSRID(geometry_column,3003);
The value of the geometry column for my record X is now:我的记录 X 的几何列的值现在是:
0101000020BB0B0000000000000080404000000000008040C0
0101000020BB0B0000000000000080404000000000008040C0
Why do I get a different value in the geometry column by doing so compared to extracting (with TS_TRANSFORM) the transformed geometry like in the query below while keeping SRID to 4326?与在下面的查询中提取(使用 TS_TRANSFORM)转换后的几何同时保持 SRID 为 4326 相比,为什么这样做会在几何列中获得不同的值?
SELECT St_transform(geometry_column,3003) FROM people;
The result is the following and it differs from the previous one while I expected it identical:结果如下,它与前一个不同,而我期望它相同:
0101000020BB0B0000328D4934B2BF4C413783531F94E74DC1
0101000020BB0B0000328D4934B2BF4C413783531F94E74DC1
In the ALTER TABLE
statement you have to transform the geometry, not just set another SRS.在
ALTER TABLE
语句中,您必须转换几何图形,而不仅仅是设置另一个 SRS。 In your code you're simply "changing" the SRID of the coordinate, which means that the coordinate pair itself remains unchanged.在您的代码中,您只是“更改”坐标的 SRID,这意味着坐标对本身保持不变。 The only way to transform coordinates from one SRS to another is to use
ST_Transform
:将坐标从一个 SRS 转换到另一个 SRS 的唯一方法是使用
ST_Transform
:
ALTER TABLE people
ALTER COLUMN geometry_column TYPE geometry(POINT, 3003)
USING ST_Transform(geometry_column,3003);
Demo: db<>fiddle
演示:
db<>fiddle
CREATE TABLE people (geometry_column geometry(point,4326));
INSERT INTO people VALUES ('SRID=4326;POINT(33 -33)');
ALTER TABLE people
ALTER COLUMN geometry_column TYPE geometry(POINT, 3003)
USING ST_Transform(geometry_column,3003);
SELECT ST_AsEWKT(geometry_column) FROM people;
st_asewkt
--------------------------------------------------------
SRID=3003;POINT(3768164.4084946155 -3919656.244736101)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.