PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ rt_band_get_pixel_of_value()

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 1960 of file rt_band.c.

1964  {
1965  int x;
1966  int y;
1967  int i;
1968  double pixval;
1969  int err;
1970  int count = 0;
1971  int isnodata = 0;
1972  int isequal = 0;
1973 
1974  rt_pixel pixel = NULL;
1975 
1976  assert(NULL != band);
1977  assert(NULL != pixels);
1978  assert(NULL != searchset && searchcount > 0);
1979 
1980  if (!band->hasnodata)
1981  exclude_nodata_value = FALSE;
1982  /* band is NODATA and exclude_nodata_value = TRUE, nothing to search */
1983  else if (exclude_nodata_value && band->isnodata) {
1984  RASTER_DEBUG(4, "Pixels cannot be searched as band is NODATA and excluding NODATA values");
1985  return 0;
1986  }
1987 
1988  for (x = 0; x < band->width; x++) {
1989  for (y = 0; y < band->height; y++) {
1990  err = rt_band_get_pixel(band, x, y, &pixval, &isnodata);
1991  if (err != ES_NONE) {
1992  rterror("rt_band_get_pixel_of_value: Cannot get band pixel");
1993  return -1;
1994  }
1995  else if (exclude_nodata_value && isnodata)
1996  continue;
1997 
1998  for (i = 0; i < searchcount; i++) {
1999  if (rt_pixtype_compare_clamped_values(band->pixtype, searchset[i], pixval, &isequal) != ES_NONE) {
2000  continue;
2001  }
2002 
2003  if (FLT_NEQ(pixval, searchset[i]) || !isequal)
2004  continue;
2005 
2006  /* match found */
2007  count++;
2008  if (*pixels == NULL)
2009  *pixels = (rt_pixel) rtalloc(sizeof(struct rt_pixel_t) * count);
2010  else
2011  *pixels = (rt_pixel) rtrealloc(*pixels, sizeof(struct rt_pixel_t) * count);
2012  if (*pixels == NULL) {
2013  rterror("rt_band_get_pixel_of_value: Could not allocate memory for pixel(s)");
2014  return -1;
2015  }
2016 
2017  pixel = &((*pixels)[count - 1]);
2018  pixel->x = x;
2019  pixel->y = y;
2020  pixel->nodata = 0;
2021  pixel->value = pixval;
2022  }
2023  }
2024  }
2025 
2026  return count;
2027 }
#define FALSE
Definition: dbfopen.c:72
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
#define FLT_NEQ(x, y)
Definition: librtcore.h:2423
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:302
struct rt_pixel_t * rt_pixel
Definition: librtcore.h:148
rt_errorstate rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval, int *isequal)
Test to see if two values are equal when clamped.
Definition: rt_pixel.c:202
@ ES_NONE
Definition: librtcore.h:182
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:199
int count
Definition: genraster.py:57
band
Definition: ovdump.py:58
pixval
Definition: pixval.py:95
pixel
Definition: pixval.py:92
Definition: pixval.py:1
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1527

References ovdump::band, genraster::count, ES_NONE, FALSE, FLT_NEQ, pixval::pixel, pixval::pixval, RASTER_DEBUG, rt_band_get_pixel(), rt_pixtype_compare_clamped_values(), rtalloc(), rterror(), rtrealloc(), pixval::x, and pixval::y.

Referenced by RASTER_pixelOfValue(), and test_band_get_pixel_of_value().

Here is the call graph for this function:
Here is the caller graph for this function: