PostGIS  2.1.10dev-r@@SVN_REVISION@@
int rt_band_get_pixel_of_value ( rt_band  band,
int  exclude_nodata_value,
double *  searchset,
int  searchcount,
rt_pixel pixels 
)

Search band for pixel(s) with search values.

Parameters
band: the band to query for minimum and maximum pixel values
exclude_nodata_value: if non-zero, ignore nodata values
searchset: array of values to count
searchcount: the number of search values
pixels: pixels with the search value
Returns
-1 on error, otherwise number of pixels

Definition at line 2980 of file rt_api.c.

References genraster::count, rt_context_t::err, ES_NONE, FALSE, FLT_NEQ, rt_band_t::hasnodata, rt_band_t::height, rt_band_t::isnodata, rt_pixel_t::nodata, pixval::pixel, rt_band_t::pixtype, pixval::pixval, RASTER_DEBUG, rt_band_get_pixel(), rt_pixtype_compare_clamped_values(), rtalloc(), rterror(), rtrealloc(), rt_pixel_t::value, rt_band_t::width, pixval::x, rt_pixel_t::x, pixval::y, and rt_pixel_t::y.

Referenced by RASTER_pixelOfValue(), and test_band_get_pixel_of_value().

2984  {
2985  int x;
2986  int y;
2987  int i;
2988  double pixval;
2989  int err;
2990  int count = 0;
2991  int isnodata = 0;
2992  int isequal = 0;
2993 
2994  rt_pixel pixel = NULL;
2995 
2996  assert(NULL != band);
2997  assert(NULL != pixels);
2998  assert(NULL != searchset && searchcount > 0);
2999 
3000  if (!band->hasnodata)
3001  exclude_nodata_value = FALSE;
3002  /* band is NODATA and exclude_nodata_value = TRUE, nothing to search */
3003  else if (exclude_nodata_value && band->isnodata) {
3004  RASTER_DEBUG(4, "Pixels cannot be searched as band is NODATA and excluding NODATA values");
3005  return 0;
3006  }
3007 
3008  for (x = 0; x < band->width; x++) {
3009  for (y = 0; y < band->height; y++) {
3010  err = rt_band_get_pixel(band, x, y, &pixval, &isnodata);
3011  if (err != ES_NONE) {
3012  rterror("rt_band_get_pixel_of_value: Cannot get band pixel");
3013  return -1;
3014  }
3015  else if (exclude_nodata_value && isnodata)
3016  continue;
3017 
3018  for (i = 0; i < searchcount; i++) {
3019  if (rt_pixtype_compare_clamped_values(band->pixtype, searchset[i], pixval, &isequal) != ES_NONE) {
3020  continue;
3021  }
3022 
3023  if (FLT_NEQ(pixval, searchset[i]) || !isequal)
3024  continue;
3025 
3026  /* match found */
3027  count++;
3028  if (*pixels == NULL)
3029  *pixels = (rt_pixel) rtalloc(sizeof(struct rt_pixel_t) * count);
3030  else
3031  *pixels = (rt_pixel) rtrealloc(*pixels, sizeof(struct rt_pixel_t) * count);
3032  if (*pixels == NULL) {
3033  rterror("rt_band_get_pixel_of_value: Could not allocate memory for pixel(s)");
3034  return -1;
3035  }
3036 
3037  pixel = &((*pixels)[count - 1]);
3038  pixel->x = x;
3039  pixel->y = y;
3040  pixel->nodata = 0;
3041  pixel->value = pixval;
3042  }
3043  }
3044  }
3045 
3046  return count;
3047 }
#define FLT_NEQ(x, y)
Definition: rt_api.h:2158
rt_pixtype pixtype
Definition: rt_api.h:2239
uint16_t height
Definition: rt_api.h:2242
double value
Definition: rt_api.h:2263
struct rt_pixel_t * rt_pixel
Definition: rt_api.h:135
tuple pixval
Definition: pixval.py:93
#define RASTER_DEBUG(level, msg)
Definition: rt_api.h:281
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
int count
Definition: genraster.py:57
uint8_t nodata
Definition: rt_api.h:2262
uint16_t width
Definition: rt_api.h:2241
tuple x
Definition: pixval.py:53
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int32_t isnodata
Definition: rt_api.h:2244
#define FALSE
Definition: dbfopen.c:169
int32_t hasnodata
Definition: rt_api.h:2243
tuple pixel
Definition: pixval.py:90
rt_errorstate rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval, int *isequal)
Returns 1 if clamped values are equal, 0 if not equal, -1 if error.
Definition: rt_api.c:1258
tuple y
Definition: pixval.py:54
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875

Here is the call graph for this function:

Here is the caller graph for this function: