## Name

ST_Neighborhood — 返回给定波段像素周围非 `NODATA` 值的二维双精度数组，该给定波段像素由 columnX 和 rowY 或以与栅格相同的空间参考坐标系表示的几何点指定。

## Synopsis

`double precision[][] ST_Neighborhood(`raster rast, integer bandnum, integer columnX, integer rowY, integer distanceX, integer distanceY, boolean exclude_nodata_value=true`)`;

`double precision[][] ST_Neighborhood(`raster rast, integer columnX, integer rowY, integer distanceX, integer distanceY, boolean exclude_nodata_value=true`)`;

`double precision[][] ST_Neighborhood(`raster rast, integer bandnum, geometry pt, integer distanceX, integer distanceY, boolean exclude_nodata_value=true`)`;

`double precision[][] ST_Neighborhood(`raster rast, geometry pt, integer distanceX, integer distanceY, boolean exclude_nodata_value=true`)`;

## 描述

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

 返回的二维数组沿每个轴的元素数量为 2 * (`distanceX`|`distanceY`) 1。因此，对于 `distanceX `和 `distanceY `为 1，返回的数组将为 3x3。
 二维数组输出可以传递给任何栅格处理内置函数，例如 ST_Min4ma、ST_Sum4ma、ST_Mean4ma。

## 示例

```-- pixel 2x2 has value
SELECT
ST_Neighborhood(rast, 2, 2, 1, 1)
FROM (
SELECT
ST_SetValues(
ST_MakeEmptyRaster(5, 5, -2, 2, 1, -1, 0, 0, 0),
'8BUI'::text, 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[],
1
) AS rast
) AS foo

st_neighborhood
---------------------------------
{{NULL,1,1},{1,1,1},{1,NULL,1}}
```
```-- pixel 2x3 is NODATA
SELECT
ST_Neighborhood(rast, 2, 3, 1, 1)
FROM (
SELECT
ST_SetValues(
ST_MakeEmptyRaster(5, 5, -2, 2, 1, -1, 0, 0, 0),
'8BUI'::text, 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[],
1
) AS rast
) AS foo

st_neighborhood
------------------------------
{{1,1,1},{1,NULL,1},{1,1,1}}
```
```-- pixel 3x3 has value
-- exclude_nodata_value = FALSE
SELECT
ST_Neighborhood(rast, 3, 3, 1, 1, false)
FROM ST_SetValues(
ST_MakeEmptyRaster(5, 5, -2, 2, 1, -1, 0, 0, 0),
'8BUI'::text, 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[],
1
) AS rast

st_neighborhood
---------------------------
{{1,1,0},{0,1,1},{1,1,1}}
```