Get nearest pixel(s) with value (not NODATA) to specified pixel.
- Parameters
-
band | : the band to get nearest pixel(s) from |
x | : pixel column (0-based) |
y | : pixel row (0-based) |
distancex | : the number of pixels around the specified pixel along the X axis |
distancey | : the number of pixels around the specified pixel along the Y axis |
exclude_nodata_value | : if non-zero, ignore nodata values to check for pixels with value |
npixels | : return set of rt_pixel object or NULL |
- Returns
- -1 on error, otherwise the number of rt_pixel objects in npixels
- Parameters
-
band | : the band to get nearest pixel(s) from |
x | : the column of the pixel (0-based) |
y | : the line of the pixel (0-based) |
distancex | : the number of pixels around the specified pixel along the X axis |
distancey | : the number of pixels around the specified pixel along the Y axis |
exclude_nodata_value | : if non-zero, ignore nodata values to check for pixels with value |
npixels | : return set of rt_pixel object or NULL |
- Returns
- -1 on error, otherwise the number of rt_pixel objects in npixels
Definition at line 1374 of file rt_band.c.
1382 int extent[4] = {0};
1383 int max_extent[4] = {0};
1401 assert(NULL !=
band);
1402 assert(NULL != npixels);
1419 exclude_nodata_value && (
1420 (x < 0 || x >
band->width) ||
1421 (y < 0 || y >
band->height)
1428 else if (
x >
band->width)
1433 else if (
y >
band->height)
1446 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1452 if (!
band->hasnodata)
1453 exclude_nodata_value =
FALSE;
1455 else if (exclude_nodata_value &&
band->isnodata) {
1456 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1466 b = abs(
x -
band->width);
1475 b = abs(
y -
band->height);
1499 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1507 extent[0] =
x - _d[0];
1508 extent[1] =
y - _d[1];
1509 extent[2] =
x + _d[0];
1510 extent[3] =
y + _d[1];
1512 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1514 extent[0], extent[1], extent[2], extent[3]);
1516 for (i = 0; i < 2; i++) {
1520 _max = extent[2] - extent[0] + 1;
1523 _max = extent[3] - extent[1] + 1;
1526 for (j = 0; j < 2; j++) {
1555 for (k = 0; k < (
uint32_t) _max; k++) {
1558 _x < max_extent[0] || _x > max_extent[2] ||
1559 _y < max_extent[1] || _y > max_extent[3]
1567 (_x < 0 || _x >=
band->width) ||
1568 (_y < 0 || _y >=
band->height)
1571 if (!
band->hasnodata)
1576 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1587 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1596 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1598 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1601 if (*npixels == NULL)
1605 if (*npixels == NULL) {
1606 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1610 npixel = &((*npixels)[
count - 1]);
1616 if (!inextent && !
band->hasnodata)
1630 else if (d0 &&
count)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
struct rt_pixel_t * rt_pixel
void * rtrealloc(void *mem, size_t size)
const char * rt_pixtype_name(rt_pixtype pixtype)
void rtdealloc(void *mem)
Datum distance(PG_FUNCTION_ARGS)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
References ovdump::band, genraster::count, distance(), ES_NONE, FALSE, rt_pixel_t::nodata, pixval::pixval, RASTER_DEBUG, RASTER_DEBUGF, rt_band_get_pixel(), rt_pixtype_get_min_value(), rt_pixtype_name(), rtalloc(), rtdealloc(), rterror(), rtrealloc(), rt_pixel_t::value, rt_pixel_t::x, pixval::x, rt_pixel_t::y, and pixval::y.
Referenced by RASTER_nearestValue(), RASTER_neighborhood(), rt_raster_iterator(), test_band_get_nearest_pixel(), and test_pixel_set_to_array().