ST_PixelOfValue — 获取值等于搜索值的像素的列x、行y坐标。
setof record ST_PixelOfValue( raster rast , integer nband , double precision[] search , boolean exclude_nodata_value=true );
setof record ST_PixelOfValue( raster rast , double precision[] search , boolean exclude_nodata_value=true );
setof record ST_PixelOfValue( raster rast , integer nband , double precision search , boolean exclude_nodata_value=true );
setof record ST_PixelOfValue( raster rast , double precision search , boolean exclude_nodata_value=true );
获取值等于搜索值的像素的列x、行y坐标。 如果未指定波段,则假定为波段 1。
可用性:2.1.0
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, 255],
[1, 1, 0, 1, 1]
]::double precision[][]
) AS rast
)
SELECT (ST_PixelOfValue(rast, 1, ARRAY[1, 255])).*
FROM source
val | x | y -----+---+--- 1 | 1 | 2 1 | 1 | 3 1 | 1 | 4 1 | 1 | 5 1 | 2 | 1 1 | 2 | 2 1 | 2 | 4 1 | 2 | 5 1 | 3 | 1 1 | 3 | 2 1 | 3 | 3 1 | 3 | 4 1 | 4 | 1 1 | 4 | 3 1 | 4 | 4 1 | 4 | 5 1 | 5 | 1 1 | 5 | 2 1 | 5 | 3 255 | 5 | 4 1 | 5 | 5