PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ rt_util_dbl_trunc_warning()

int rt_util_dbl_trunc_warning ( double  initialvalue,
int32_t  checkvalint,
uint32_t  checkvaluint,
float  checkvalfloat,
double  checkvaldouble,
rt_pixtype  pixtype 
)

Definition at line 625 of file rt_util.c.

References FLT_NEQ, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, rt_pixtype_name(), and rtwarn().

Referenced by rt_band_reclass(), rt_band_set_nodata(), rt_band_set_pixel(), and rt_raster_generate_new_band().

630  {
631  int result = 0;
632 
633  switch (pixtype) {
634  case PT_1BB:
635  case PT_2BUI:
636  case PT_4BUI:
637  case PT_8BSI:
638  case PT_8BUI:
639  case PT_16BSI:
640  case PT_16BUI:
641  case PT_32BSI: {
642  if (fabs(checkvalint - initialvalue) >= 1) {
643 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
644  rtwarn("Value set for %s band got clamped from %f to %d",
645  rt_pixtype_name(pixtype),
646  initialvalue, checkvalint
647  );
648 #endif
649  result = 1;
650  }
651  else if (FLT_NEQ(checkvalint, initialvalue)) {
652 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
653  rtwarn("Value set for %s band got truncated from %f to %d",
654  rt_pixtype_name(pixtype),
655  initialvalue, checkvalint
656  );
657 #endif
658  result = 1;
659  }
660  break;
661  }
662  case PT_32BUI: {
663  if (fabs(checkvaluint - initialvalue) >= 1) {
664 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
665  rtwarn("Value set for %s band got clamped from %f to %u",
666  rt_pixtype_name(pixtype),
667  initialvalue, checkvaluint
668  );
669 #endif
670  result = 1;
671  }
672  else if (FLT_NEQ(checkvaluint, initialvalue)) {
673 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
674  rtwarn("Value set for %s band got truncated from %f to %u",
675  rt_pixtype_name(pixtype),
676  initialvalue, checkvaluint
677  );
678 #endif
679  result = 1;
680  }
681  break;
682  }
683  case PT_32BF: {
684  /*
685  For float, because the initial value is a double,
686  there is very often a difference between the desired value and the obtained one
687  */
688  if (FLT_NEQ(checkvalfloat, initialvalue)) {
689 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
690  rtwarn("Value set for %s band got converted from %f to %f",
691  rt_pixtype_name(pixtype),
692  initialvalue, checkvalfloat
693  );
694 #endif
695  result = 1;
696  }
697  break;
698  }
699  case PT_64BF: {
700  if (FLT_NEQ(checkvaldouble, initialvalue)) {
701 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
702  rtwarn("Value set for %s band got converted from %f to %f",
703  rt_pixtype_name(pixtype),
704  initialvalue, checkvaldouble
705  );
706 #endif
707  result = 1;
708  }
709  break;
710  }
711  case PT_END:
712  break;
713  }
714 
715  return result;
716 }
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
#define FLT_NEQ(x, y)
Definition: librtcore.h:2213
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
Here is the call graph for this function:
Here is the caller graph for this function: