PostGIS  2.1.10dev-r@@SVN_REVISION@@
int rt_util_dbl_trunc_warning ( double  initialvalue,
int32_t  checkvalint,
uint32_t  checkvaluint,
float  checkvalfloat,
double  checkvaldouble,
rt_pixtype  pixtype 
)

Definition at line 934 of file rt_api.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, result, rt_pixtype_name(), and rtwarn().

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

939  {
940  int result = 0;
941 
942  switch (pixtype) {
943  case PT_1BB:
944  case PT_2BUI:
945  case PT_4BUI:
946  case PT_8BSI:
947  case PT_8BUI:
948  case PT_16BSI:
949  case PT_16BUI:
950  case PT_32BSI: {
951  if (fabs(checkvalint - initialvalue) >= 1) {
952 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
953  rtwarn("Value set for %s band got clamped from %f to %d",
954  rt_pixtype_name(pixtype),
955  initialvalue, checkvalint
956  );
957 #endif
958  result = 1;
959  }
960  else if (FLT_NEQ(checkvalint, initialvalue)) {
961 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
962  rtwarn("Value set for %s band got truncated from %f to %d",
963  rt_pixtype_name(pixtype),
964  initialvalue, checkvalint
965  );
966 #endif
967  result = 1;
968  }
969  break;
970  }
971  case PT_32BUI: {
972  if (fabs(checkvaluint - initialvalue) >= 1) {
973 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
974  rtwarn("Value set for %s band got clamped from %f to %u",
975  rt_pixtype_name(pixtype),
976  initialvalue, checkvaluint
977  );
978 #endif
979  result = 1;
980  }
981  else if (FLT_NEQ(checkvaluint, initialvalue)) {
982 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
983  rtwarn("Value set for %s band got truncated from %f to %u",
984  rt_pixtype_name(pixtype),
985  initialvalue, checkvaluint
986  );
987 #endif
988  result = 1;
989  }
990  break;
991  }
992  case PT_32BF: {
993  /*
994  For float, because the initial value is a double,
995  there is very often a difference between the desired value and the obtained one
996  */
997  if (FLT_NEQ(checkvalfloat, initialvalue)) {
998 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
999  rtwarn("Value set for %s band got converted from %f to %f",
1000  rt_pixtype_name(pixtype),
1001  initialvalue, checkvalfloat
1002  );
1003 #endif
1004  result = 1;
1005  }
1006  break;
1007  }
1008  case PT_64BF: {
1009  if (FLT_NEQ(checkvaldouble, initialvalue)) {
1010 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1011  rtwarn("Value set for %s band got converted from %f to %f",
1012  rt_pixtype_name(pixtype),
1013  initialvalue, checkvaldouble
1014  );
1015 #endif
1016  result = 1;
1017  }
1018  break;
1019  }
1020  case PT_END:
1021  break;
1022  }
1023 
1024  return result;
1025 }
#define FLT_NEQ(x, y)
Definition: rt_api.h:2158
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_api.c:1168
Definition: rt_api.h:184
Definition: rt_api.h:173
char ** result
Definition: liblwgeom.h:218
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920

Here is the call graph for this function:

Here is the caller graph for this function: