Count the number of times provided value(s) occur in the band.
1630 int vcnts_count = 0;
1631 int new_valuecount = 0;
1633 #if POSTGIS_DEBUG_LEVEL > 0 1634 clock_t start, stop;
1639 #if POSTGIS_DEBUG_LEVEL > 0 1643 assert(NULL != band);
1644 assert(NULL != rtn_count);
1648 rterror(
"rt_band_get_summary_stats: Cannot get band data");
1659 exclude_nodata_value = 0;
1663 RASTER_DEBUGF(3,
"exclude_nodata_value = %d", exclude_nodata_value);
1666 if (roundto < 0 ||
FLT_EQ(roundto, 0.0)) {
1671 else if (roundto < 1) {
1688 for (scale = 0; scale <= 20; scale++) {
1689 tmpd = roundto * pow(10, scale);
1690 if (
FLT_EQ((tmpd - ((
int) tmpd)), 0.0))
break;
1699 for (scale = 0; scale >= -20; scale--) {
1700 tmpd = roundto * pow(10, scale);
1701 if (tmpd < 1 ||
FLT_EQ(tmpd, 1.0)) {
1702 if (scale == 0) doround = 1;
1708 if (scale != 0 || doround)
1716 if (search_values_count > 0 && NULL != search_values) {
1718 if (NULL == vcnts) {
1719 rterror(
"rt_band_get_count_of_values: Could not allocate memory for value counts");
1724 for (i = 0; i < search_values_count; i++) {
1728 vcnts[i].
value = search_values[i];
1730 vcnts[i].
value =
ROUND(search_values[i], scale);
1735 search_values_count = 0;
1736 RASTER_DEBUGF(3,
"search_values_count = %d", search_values_count);
1740 if (exclude_nodata_value) {
1741 rtwarn(
"All pixels of band have the NODATA value");
1745 if (search_values_count > 0) {
1747 for (i = 0; i < search_values_count; i++) {
1751 tmpd =
ROUND(nodata, scale);
1757 if (NULL != rtn_total) *rtn_total = vcnts[i].
count;
1761 *rtn_count = vcnts_count;
1766 if (NULL == vcnts) {
1767 rterror(
"rt_band_get_count_of_values: Could not allocate memory for value counts");
1772 vcnts->
value = nodata;
1774 if (NULL != rtn_total) *rtn_total = vcnts[i].
count;
1784 for (x = 0; x < band->
width; x++) {
1785 for (y = 0; y < band->
height; y++) {
1792 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1795 rpxlval =
ROUND(pxlval, scale);
1799 RASTER_DEBUGF(5,
"(pxlval, rpxlval) => (%0.6f, %0.6f)", pxlval, rpxlval);
1803 for (i = 0; i < vcnts_count; i++) {
1818 if (!new_valuecount || search_values_count > 0)
continue;
1822 if (NULL == vcnts) {
1823 rterror(
"rt_band_get_count_of_values: Could not allocate memory for value counts");
1828 vcnts[vcnts_count].
value = rpxlval;
1829 vcnts[vcnts_count].
count = 1;
1830 vcnts[vcnts_count].
percent = 0;
1837 #if POSTGIS_DEBUG_LEVEL > 0 1839 elapsed = ((double) (stop - start)) / CLOCKS_PER_SEC;
1843 for (i = 0; i < vcnts_count; i++) {
1849 if (NULL != rtn_total) *rtn_total = total;
1850 *rtn_count = vcnts_count;
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_nodata(rt_band band, double *nodata)
Get NODATA value.
void rtwarn(const char *fmt,...)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
#define RASTER_DEBUGF(level, msg,...)
struct rt_valuecount_t * rt_valuecount
#define RASTER_DEBUG(level, msg)
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.