Get nearest pixel(s) with value (not NODATA) to specified pixel.
1537 int extent[4] = {0};
1538 int max_extent[4] = {0};
1541 uint32_t _d[2] = {0};
1556 assert(NULL !=
band);
1557 assert(NULL != npixels);
1574 exclude_nodata_value && (
1575 (x < 0 || x >
band->width) ||
1576 (y < 0 || y >
band->height)
1583 else if (
x >
band->width)
1588 else if (
y >
band->height)
1601 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1607 if (!
band->hasnodata)
1608 exclude_nodata_value =
FALSE;
1610 else if (exclude_nodata_value &&
band->isnodata) {
1611 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1621 b = abs(
x -
band->width);
1630 b = abs(
y -
band->height);
1654 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1662 extent[0] =
x - (int)_d[0];
1663 extent[1] =
y - (int)_d[1];
1664 extent[2] =
x + (int)_d[0];
1665 extent[3] =
y + (int)_d[1];
1667 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1669 extent[0], extent[1], extent[2], extent[3]);
1671 for (i = 0; i < 2; i++) {
1675 _max = extent[2] - extent[0] + 1;
1678 _max = extent[3] - extent[1] + 1;
1681 for (j = 0; j < 2; j++) {
1710 for (k = 0; k < (uint32_t) _max; k++) {
1713 _x < max_extent[0] || _x > max_extent[2] ||
1714 _y < max_extent[1] || _y > max_extent[3]
1722 (_x < 0 || _x >=
band->width) ||
1723 (_y < 0 || _y >=
band->height)
1726 if (!
band->hasnodata)
1731 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1742 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1751 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1753 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1756 if (*npixels == NULL)
1760 if (*npixels == NULL) {
1761 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1765 npixel = &((*npixels)[
count - 1]);
1771 if (!inextent && !
band->hasnodata)
1785 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)
static double distance(double x1, double y1, double x2, double y2)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.