Count the distribution of data.
428 #if POSTGIS_DEBUG_LEVEL > 0
434 #if POSTGIS_DEBUG_LEVEL > 0
438 assert(NULL != stats);
439 assert(NULL != rtn_count);
442 rterror(
"rt_util_get_histogram: rt_bandstats object has no value");
447 if (NULL != bin_width && bin_width_count > 0) {
448 for (i = 0; i < bin_width_count; i++) {
449 if (bin_width[i] < 0 ||
FLT_EQ(bin_width[i], 0.0)) {
450 rterror(
"rt_util_get_histogram: bin_width element is less than or equal to zero");
471 if (bin_count <= 0) {
479 if (stats->
count < 30)
480 bin_count = ceil(sqrt(stats->
count));
483 bin_count = ceil(log2((
double) stats->
count) + 1.);
486 if (bin_width_count > 0 && NULL != bin_width) {
488 if (bin_width_count > bin_count)
489 bin_count = bin_width_count;
490 else if (bin_width_count > 1) {
492 for (i = 0; i < bin_width_count; i++) tmp += bin_width[i];
493 bin_count = ceil((qmax - qmin) / tmp) * bin_width_count;
496 bin_count = ceil((qmax - qmin) / bin_width[0]);
505 if (
FLT_EQ(qmax, qmin)) bin_count = 1;
513 rterror(
"rt_util_get_histogram: Could not allocate memory for histogram");
523 *rtn_count = bin_count;
528 if (bin_width_count == 0) {
532 if (NULL == bin_width) {
533 bin_width =
rtalloc(
sizeof(
double));
534 if (NULL == bin_width) {
535 rterror(
"rt_util_get_histogram: Could not allocate memory for bin widths");
541 bin_width[0] = (qmax - qmin) / bin_count;
547 rterror(
"rt_util_get_histogram: Could not allocate memory for histogram");
555 for (i = 0; i < bin_count;) {
556 for (j = 0; j < bin_width_count; j++) {
581 bins[bin_count - 1].
inc_max = 1;
584 if (bins[bin_count - 1].max < qmax)
585 bins[bin_count - 1].
max = qmax;
588 bins[bin_count - 1].
inc_min = 1;
591 if (bins[bin_count - 1].min > qmin)
592 bins[bin_count - 1].
min = qmin;
596 for (i = 0; i < stats->
count; i++) {
601 for (j = 0; j < bin_count; j++) {
603 (!bins[j].inc_max &&
value < bins[j].max) || (
605 (
value < bins[j].max) ||
618 for (j = 0; j < bin_count; j++) {
620 (!bins[j].inc_min &&
value > bins[j].min) || (
622 (
value > bins[j].min) ||
635 for (i = 0; i < bin_count; i++) {
639 #if POSTGIS_DEBUG_LEVEL > 0
641 elapsed = ((double) (stop - start)) / CLOCKS_PER_SEC;
644 for (j = 0; j < bin_count; j++) {
645 RASTER_DEBUGF(5,
"(min, max, inc_min, inc_max, count, sum, percent) = (%f, %f, %d, %d, %d, %d, %f)",
646 bins[j].min, bins[j].max, bins[j].inc_min, bins[j].inc_max, bins[j].
count, sum, bins[j].percent);
651 *rtn_count = bin_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,...)
void rtdealloc(void *mem)