【问题标题】:How can I find the area from polygon values in postgres?如何从 postgres 中的多边形值中找到该区域?
【发布时间】:2019-01-14 07:31:21
【问题描述】:

我想从多边形中找到包含经纬度数据的区域

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 但我想获取几何值。我想我不知道查询将值视为真实世界纬度和经度数据的方式。

【问题讨论】:

    标签: postgresql geometry postgis


    【解决方案1】:

    几何上的ST_AREA 返回坐标系单位中的区域。在你的情况下,它以度为单位......并且这个单位对于面积来说是没有意义的(1度纬度与长度不同 - 以米为单位 - 1度经度)。

    要获得以 m2(或 km2 或英里 2 等)为单位的面积,您需要将几何图形转换为以米为单位的坐标系,或者您需要使用 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;
    

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多