PostGIS  2.5.1dev-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 627 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().

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