PostGIS中使用ST_Area计算面积的单位问题

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

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
ST_AREA函数是PostGIS中的一个函数,用于计算几何对象的面积。在MySQL中并没有内置的ST_AREA函数,因为这个函数是PostGIS特有的。在MySQL中,如果你想计算几何对象的面积,可以使用MySQL的内置函数ST_Area。该函数需要传入一个几何对象作为参数,并返回该几何对象的面积值。使用方法如下: SELECT ST_Area(geometry) as area FROM table; 其中,geometry是你要计算面积的几何对象的列名,table是包含这个列的表名。这样就可以通过ST_Area函数计算几何对象的面积了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [PostGISST_AREA面积计算](https://blog.youkuaiyun.com/weixin_43524214/article/details/128763710)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [mysql-ST_Area()用于纬度和经度](https://blog.youkuaiyun.com/weixin_28679635/article/details/114886353)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值