【问题标题】:Postgres/Postgis - Querying all values in clipped rasterPostgres/Postgis - 查询裁剪栅格中的所有值
【发布时间】:2013-11-27 16:26:44
【问题描述】:

我目前使用的是 Postgres 9.1

我的目标是用多边形裁剪 PostGIS 栅格。然后我想要一个 postgres 数组或包含在该多边形中的每个光栅像素的分隔值集。这是我到目前为止得到的查询:

SELECT  p.gid, (ST_ValueCount(ST_Clip(r.rast, p.geom))).value AS fval
FROM temp_raster AS r, temp_shapefile AS p
WHERE (r.start_time = 1384516800) 
GROUP BY gid, fval;

这将输出:

 gid | fcstval 
-----+---------
   1 |       0
   1 |       2
   2 |       0
   2 |       2
   3 |       5
   4 |       0
   4 |       1
   4 |       2
   4 |       3
   4 |       5

这个数据很好,但我想为每个 gid 设置一组值,如下所示:

 gid |  fcstval 
-----+----------
   1 |       0,2
   2 |       0,2
   3 |         5
   4 | 0,1,2,3,5

我遇到的麻烦是尝试将这些值聚合到数组或分隔字符串中。这是我对数组的尝试:

SELECT  p.gid, array_agg((ST_ValueCount(ST_Clip(r.rast, p.geom))).value) AS fval
FROM temp_raster AS r, temp_shapefile AS p
WHERE (r.start_time = 1384516800)
GROUP BY gid;

这不起作用,并提供错误:

ERROR:  set-valued function called in context that cannot accept a set

我猜这是因为我不能以这种方式调用array_agg。我很难弄清楚如何做到这一点。也许是一个子查询?我还没有想出任何办法来让它发挥作用。

感谢您的帮助!

【问题讨论】:

    标签: sql postgresql postgresql-9.1 postgis


    【解决方案1】:

    好的,我想我想出了数组。如果我想要它在一个字符串中,我可以将我的数组转换为一个字符串。但是,如果有人对清理有任何建议,我将不胜感激,因为这似乎不是最简单的标记

    SELECT p.gid, array_agg((subquery).tempval) as fcstval 
    FROM pih_raster AS r, hwy_pih_vertex_buf AS p, 
    ( 
        SELECT p.gid AS tempgid, (ST_ValueCount(ST_Clip(r.rast, p.geom))).value AS tempval 
        FROM pih_raster AS r, hwy_pih_vertex_buf AS p 
        WHERE (r.start_time <= 1384624800) GROUP BY tempgid, tempval
    ) AS subquery
    WHERE (r.start_time <= 1384624800) AND ((subquery).tempgid = gid) GROUP BY p.gid;
    

    这是输出:

     gid |   fcstval   
    -----+-------------
       1 | {0,2}
       2 | {0,2}
       3 | {5}
       4 | {0,1,2,3,5}
    

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 1970-01-01
      • 2016-03-27
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 2017-12-14
      相关资源
      最近更新 更多