PostGIS  3.0.6dev-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 629 of file rt_util.c.

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

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().

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