名称

ST_NearestValue — 返回由 columnx 和 rowy 指定的给定带像素的最接近的非 NODATA 值或以与栅格相同的空间参考坐标系表示的几何点。

大纲

double precision ST_NearestValue(raster rast, integer bandnum, geometry pt, boolean exclude_nodata_value=true);

double precision ST_NearestValue(raster rast, geometry pt, boolean exclude_nodata_value=true);

double precision ST_NearestValue(raster rast, integer bandnum, integer columnx, integer rowy, boolean exclude_nodata_value=true);

double precision ST_NearestValue(raster rast, integer columnx, integer rowy, boolean exclude_nodata_value=true);

Description

返回给定列 x、行y像素或特定几何点中给定带的最接近的非 NODATA 值。 如果列x、行y像素或指定几何点处的像素为NODATA,则函数将查找距离列x、行y像素或值为非NODATA的几何点最近的像素。

Band 编号从 1 开始,如果未指定,则 bandnum 假定为 1。 如果 except_nodata_value 设置为 false,则所有包含 nodata 像素的像素都被视为相交并返回值。 如果exclude_nodata_value未传入,则从栅格的元数据中读取它。

可用性:2.1.0

[注意]

ST_NearestValue 是 ST_Value 的直接替代品。

示例

This example reads a value from pixel 2x2.

Code
WITH source AS (
    SELECT ST_SetValues(
        ST_AddBand(
            ST_MakeEmptyRaster(5, 5, -2, 2, 1, -1, 0, 0, 0),
            1, '8BUI', 1, 0
        ),
        1, 1, 1,
        ARRAY[
            [0, 1, 1, 1, 1],
            [1, 1, 1, 0, 1],
            [1, 0, 1, 1, 1],
            [1, 1, 1, 1, 0],
            [1, 1, 0, 1, 1]
        ]::double precision[][]
    ) AS rast
)
SELECT
    ST_Value(rast, 2, 2) AS value,
    ST_NearestValue(rast, 2, 2) AS nearestvalue
FROM source
栅格输出
value | nearestvalue
-------+--------------
     1 |            1

This example reads a NODATA value from pixel 2x3.

Code
WITH source AS (
    SELECT ST_SetValues(
        ST_AddBand(
            ST_MakeEmptyRaster(5, 5, -2, 2, 1, -1, 0, 0, 0),
            1, '8BUI', 1, 0
        ),
        1, 1, 1,
        ARRAY[
            [0, 1, 1, 1, 1],
            [1, 1, 1, 0, 1],
            [1, 0, 1, 1, 1],
            [1, 1, 1, 1, 0],
            [1, 1, 0, 1, 1]
        ]::double precision[][]
    ) AS rast
)
SELECT
    ST_Value(rast, 2, 3) AS value,
    ST_NearestValue(rast, 2, 3) AS nearestvalue
FROM source
栅格输出
value | nearestvalue
-------+--------------
       |            1

相关信息

ST_Neighborhood, ST_Value