1. 问题描述
Postgres 数据库中存储了一张 Polygon 类型的空间数据表,投影类型为 WGS 4326。想计算每个多边形的面积。但使用PostGIS提供的 ST_Area 函数返回结果非常小,明显不对。
SELECT
ST_Area(
ST_SetSRID(
ST_GeomFromText('POLYGON((
106.06615188500007 29.25636267300007,
106.06616592500006 29.25771628100007,
106.06770954400008 29.25770396000007,
106.06769548400007 29.25635035300007,
106.06615188500007 29.25636267300007))'
),
4326
)
);
# 返回结果
-----------------------
2.089613822508709e-06
(1 row)
2. 问题原因
-
2.1 先查询ST_Area官方文档,说明如下:
float ST_Area(geometry g1);
float ST_Area(geography geog, boolean use_spheroid = true);
Description: Returns the area of a polygonal geometry. For geometry types a 2D Cartesian (planar) area is computed, with units specified by the SRID. For geography types by default area is determined on a spheroid with units in square meters. To compute the area using the faster but less accurate spherical model use ST_Area(geog,false).返回多边形几何的面积。对于几何类型,计算二维笛卡尔(平面)面积,其单位由SRID指定。对于地理类型,默认情况下,区域是在以平方米为单位的球体上确定的。要使用更快但精度较低的球面模型计算面积,请使用ST_Area(geog,false)。
-
2.2 查询确认数据的空间参考( Spatial Reference ) 类型所使用的单位如下
SELECT srtext FROM spatial_ref_sys WHERE srid = ( SELECT st_srid(geom) FROM my_data_tab
Postgres数据库多边形面积计算问题及解决

博客围绕Postgres数据库中Polygon类型空间数据表的面积计算问题展开。使用ST_Area函数结果异常,原因是EPSG:4326空间参考系单位为度而非米。解决方案是将空间数据参考系转换为以米为单位的EPSG:4527,计算结果更符合实际,不同过渡参考系会影响结果。
最低0.47元/天 解锁文章
2585

被折叠的 条评论
为什么被折叠?



