如果使用PostGIS的ST_Area函數計算多邊形面積

問題

最近遇到了一個很奇怪的問題,是使用ST_Area計算出的面積特別小。

 

select st_area(
ST_SetSRID(ST_GeomFromText(
'POLYGON ((115.440261 33.8547281, 115.4400647 33.8548702, 
115.4403265 33.8549768, 115.4404674 33.8549267, 115.4404397 33.8547365, 
115.440261 33.8547281))'),4326))
  • 計算結果

     

     

    發現計算出的結果是一個特備小的值,明顯是不正確的。

原因

最後查看官方文檔

Synopsis
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必須在以米爲單位的座標系中才能計算中準確的面積,WGS84(4326)是以度爲單位,所以這個函數計算出來的面積纔會特別小,需要使用st_transform將幾何體轉換到以米爲單位的座標系中,這裏我準備使用2000座標系,因爲在我國的平面計算精準還比較精準

改進後計算方法

 

select st_area(st_transform(
ST_SetSRID(ST_GeomFromText(
'POLYGON ((115.440261 33.8547281, 115.4400647 33.8548702, 
115.4403265 33.8549768, 115.4404674 33.8549267, 115.4404397 33.8547365, 
115.440261 33.8547281))'),4326),4527))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章