Get nearest pixel(s) with value (not NODATA) to specified pixel.
1249 int extent[4] = {0};
1250 int max_extent[4] = {0};
1268 assert(NULL != band);
1269 assert(NULL != npixels);
1274 distance[0] = distancex;
1275 distance[1] = distancey;
1278 if (!distance[0] && !distance[1])
1282 RASTER_DEBUGF(4,
"Distances: %d x %d", distance[0], distance[1]);
1286 exclude_nodata_value && (
1287 (x < 0 || x > band->
width) ||
1288 (y < 0 || y > band->
height)
1295 else if (
x > band->
width)
1310 ((
x < 0 && abs(
x) > distance[0]) || (
x - band->
width >= distance[0])) ||
1311 ((
y < 0 && abs(
y) > distance[1]) || (
y - band->
height >= distance[1]))
1313 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1320 exclude_nodata_value =
FALSE;
1322 else if (exclude_nodata_value && band->
isnodata) {
1323 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1333 b = abs(
x - band->
width);
1348 RASTER_DEBUGF(4,
"Maximum distances: %d x %d", distance[0], distance[1]);
1361 max_extent[0] =
x - distance[0];
1362 max_extent[1] =
y - distance[1];
1363 max_extent[2] =
x + distance[0];
1364 max_extent[3] =
y + distance[1];
1366 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1374 extent[0] =
x - _d[0];
1375 extent[1] =
y - _d[1];
1376 extent[2] =
x + _d[0];
1377 extent[3] =
y + _d[1];
1379 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1381 extent[0], extent[1], extent[2], extent[3]);
1383 for (i = 0; i < 2; i++) {
1387 _max = extent[2] - extent[0] + 1;
1390 _max = extent[3] - extent[1] + 1;
1393 for (j = 0; j < 2; j++) {
1422 for (k = 0; k < _max; k++) {
1425 _x < max_extent[0] || _x > max_extent[2] ||
1426 _y < max_extent[1] || _y > max_extent[3]
1434 (_x < 0 || _x >= band->
width) ||
1435 (_y < 0 || _y >= band->
height)
1443 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y, pixval);
1454 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1458 RASTER_DEBUGF(4,
"Pixel: (x, y, val) = (%d, %d, %f)", _x, _y, pixval);
1463 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1465 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y, pixval);
1468 if (*npixels == NULL)
1472 if (*npixels == NULL) {
1473 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1477 npixel = &((*npixels)[count - 1]);
1495 if (_d[0] >= distance[0] && _d[1] >= distance[1])
1497 else if (d0 && count)
struct rt_pixel_t * rt_pixel
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
void * rtrealloc(void *mem, size_t size)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
#define RASTER_DEBUGF(level, msg,...)
Datum distance(PG_FUNCTION_ARGS)
void rtdealloc(void *mem)
#define RASTER_DEBUG(level, msg)
const char * rt_pixtype_name(rt_pixtype pixtype)