简体   繁体   English

为什么在使用 st_transform 与更改表 SRID 时会得到不同的几何值?

[英]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.

相关问题 输入几何具有 unkown(0) 几何(尽管使用了 st_transform) - input geometry has unkown(0) geometry (Although st_transform is used) ST_Transform和CoordTransform之间涉及预设的不同计算 - Different calculations between ST_Transform and CoordTransform that involves presition 在 PL/pgSQL function 中添加 ST_Transform - Adding ST_Transform in a PL/pgSQL function 使用 PostGIS / PostgreSQL 中的 st_transform 从质心创建带有坐标的新列 - Create new column with coordinates from centroids using st_transform in PostGIS / PostgreSQL 为什么在使用 UCT 值与时区名称时,我在 postgresql 中得到不同的值? - Why do I get different values in postgresql when using UCT values vs timezone names? Postgres(DBeaver)报告ST_Transform后0行已更改 - Postgres (DBeaver) reporting 0 changed rows after ST_Transform PosgtreSQL使用st_transform,st_makepoint和st_contains优化查询 - PosgtreSQL Optimize Query with st_transform, st_makepoint, and st_contains 将 ST_Intersects 与没有 SET_SRID 的 ST_MakePoint 一起使用 - Using ST_Intersects with ST_MakePoint with no SET_SRID 在 R 中使用 sf 包中的 st_read 时,如何从 Postgre 表中获得正确的编码 - How do I get correct encoding from my Postgre table when using st_read from the sf package in R 在 Postgres 中检查表的几何类型和 SRID 的有效方法 Function - Efficient way to check Geometry type and SRID of Table in Postgres Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM