簡體   English   中英

如何從Postgres中的多邊形值中找到面積?

[英]How can I find the area from polygon values in postgres?

我想從多邊形中找到包含緯度和經度數據的區域

select ST_Area(l.polygon) from  dwh_il_fo.v1_dim_location l
where location_id  = '4136'
limit 10

在這種情況下,面值為:

MULTIPOLYGON (((103.867936362042 1.34178614086727, 103.867778465463 1.34071624615614, 103.867304775725 1.34017252899258, 103.866497748765 1.33999713633343, 103.865234576132 1.34047069648432, 103.865234576132 1.3411547276517, 103.86567317774 1.3419439941457, 103.865918794641 1.34124242394138, 103.866778453795 1.34103195284086, 103.867936362042 1.34178614086727)))

但是結果返回到0.000002908012571383107,但是我想獲取幾何值。我想我不知道查詢將值視為真實世界的經度和緯度數據的方式。

幾何體上的ST_AREA返回以坐標系為單位的面積。 在您的情況下,單位為度...並且此單位對面積沒有意義(1個緯度與1個經度的長度不同,以米為單位)。

要獲得M2(miles2或平方公里,或等)的區域,你將需要要么改變你的幾何形狀的坐標系統,它的單位是米,不然你就需要使用geography數據類型。

WITH a as (SELECT ST_GEOMFROMTEXT('MULTIPOLYGON(((103.867936362042 1.34178614086727, 103.867778465463 1.34071624615614, 103.867304775725 1.34017252899258, 103.866497748765 1.33999713633343, 103.865234576132 1.34047069648432, 103.865234576132 1.3411547276517, 103.86567317774 1.3419439941457, 103.865918794641 1.34124242394138, 103.866778453795 1.34103195284086, 103.867936362042 1.34178614086727)))') geom)
SELECT st_area(geom::geography) m2 from a;
        m2
------------------
 35785.3981593922
(1 row)

原始查詢變為

select ST_Area(l.polygon::geography) 
from  dwh_il_fo.v1_dim_location l
where location_id  = '4136'
limit 10;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM