我想从多边形中找到包含纬度和经度数据的区域
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,但是我想获取几何值。我想我不知道查询将值视为真实世界的经度和纬度数据的方式。
答案 0 :(得分:1)
ST_AREA
返回以坐标系为单位的面积。在您的情况下,单位为度...,并且该单位对面积没有意义(1个纬度与1个经度的长度不同,以米为单位)。
要获取以m2(或km2或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;