PostGIS 坐标转换(SRID)的边界问题 - ST_Transform

标签

PostgreSQL , PostGIS , ST_Transform , SRID , 26986


背景

某个用户在使用PostgreSQL ST_Transform转换坐标时,遇到一个边界问题(暂时不清楚是不是BUG,因为对SRID还不算太了解),导致距离计算不准确。

例子

下面两个4326坐标系的坐标,只相差了一点点,但是转换为26986坐标系时,出现了翻转。

postgres=# select ST_AsEWKT(ST_Transform(ST_GeomFromText('POINT(108.50000000001 22.8)', 4326), 26986));  
                      st_asewkt                        
-----------------------------------------------------  
 SRID=26986;POINT(8123333.59043839 12671815.6459695)  
(1 row)  
  
postgres=# select ST_AsEWKT(ST_Transform(ST_GeomFromText('POINT(108.5000000001 22.8)', 4326), 26986));  
                      st_asewkt                         
------------------------------------------------------  
 SRID=26986;POINT(-7723333.59044452 12671815.6459593)  
(1 row)  

使用转换后的坐标,计算距离,导致数据不准确。

解决方法,不要转换为26986坐标系统坐标

http://postgis.net/docs/manual-2.0/ST_Distance.html

try this:  
  
postgres=# select ST_Distance(ST_GeographyFromText('SRID=4326;POINT(108.51 22.8)'), ST_GeographyFromText('SRID=4326;POINT(108.499999999999999 22.79)'));  
-[ RECORD 1 ]--------------------  
st_distance | 1510.16913796499989  
  
-- Geography example -- same but note units in meters - use sphere for slightly faster less accurate  
  
-- Geometry example - units in meters (SRID: 26986 Massachusetts state plane meters) (most accurate for Massachusetts)  

你可能感兴趣的:(PostGIS 坐标转换(SRID)的边界问题 - ST_Transform)