PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_band_set_nodata ( rt_band  band,
double  val,
int *  converted 
)

Set nodata value.

Parameters
band: the band to set nodata value to
val: the nodata value
converted: (optional) if non-zero, value was truncated/clamped/converted
Returns
ES_NONE or ES_ERROR
Parameters
band: the band to set nodata value to
val: the nodata value
converted: if non-zero, value was truncated/clamped/coverted
Returns
ES_NONE or ES_ERROR

Definition at line 2061 of file rt_api.c.

References ES_ERROR, ES_NONE, rt_band_t::hasnodata, rt_band_t::isnodata, rt_band_t::nodataval, rt_band_t::pixtype, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, RASTER_DEBUGF, rt_pixtype_name(), rt_util_clamp_to_16BSI(), rt_util_clamp_to_16BUI(), rt_util_clamp_to_1BB(), rt_util_clamp_to_2BUI(), rt_util_clamp_to_32BSI(), rt_util_clamp_to_32BUI(), rt_util_clamp_to_32F(), rt_util_clamp_to_4BUI(), rt_util_clamp_to_8BSI(), rt_util_clamp_to_8BUI(), rt_util_dbl_trunc_warning(), and rterror().

Referenced by RASTER_setBandNoDataValue(), rt_band_new_inline(), rt_band_new_offline(), test_band_metadata(), test_band_pixtype_16BSI(), test_band_pixtype_16BUI(), test_band_pixtype_1BB(), test_band_pixtype_2BUI(), test_band_pixtype_32BF(), test_band_pixtype_32BSI(), test_band_pixtype_32BUI(), test_band_pixtype_4BUI(), test_band_pixtype_64BF(), test_band_pixtype_8BSI(), test_band_pixtype_8BUI(), test_band_reclass(), test_band_stats(), test_band_value_count(), test_raster_colormap(), test_raster_from_band(), test_raster_fully_within_distance(), test_raster_geos_contains(), test_raster_geos_contains_properly(), test_raster_geos_covered_by(), test_raster_geos_covers(), test_raster_geos_overlaps(), test_raster_geos_touches(), test_raster_intersects(), and test_raster_within_distance().

2061  {
2062  rt_pixtype pixtype = PT_END;
2063  int32_t checkvalint = 0;
2064  uint32_t checkvaluint = 0;
2065  float checkvalfloat = 0;
2066  double checkvaldouble = 0;
2067 
2068  assert(NULL != band);
2069 
2070  if (converted != NULL)
2071  *converted = 0;
2072 
2073  pixtype = band->pixtype;
2074 
2075  RASTER_DEBUGF(3, "rt_band_set_nodata: setting nodata value %g with band type %s", val, rt_pixtype_name(pixtype));
2076 
2077  /* return -1 on out of range */
2078  switch (pixtype) {
2079  case PT_1BB: {
2080  band->nodataval = rt_util_clamp_to_1BB(val);
2081  checkvalint = band->nodataval;
2082  break;
2083  }
2084  case PT_2BUI: {
2085  band->nodataval = rt_util_clamp_to_2BUI(val);
2086  checkvalint = band->nodataval;
2087  break;
2088  }
2089  case PT_4BUI: {
2090  band->nodataval = rt_util_clamp_to_4BUI(val);
2091  checkvalint = band->nodataval;
2092  break;
2093  }
2094  case PT_8BSI: {
2095  band->nodataval = rt_util_clamp_to_8BSI(val);
2096  checkvalint = band->nodataval;
2097  break;
2098  }
2099  case PT_8BUI: {
2100  band->nodataval = rt_util_clamp_to_8BUI(val);
2101  checkvalint = band->nodataval;
2102  break;
2103  }
2104  case PT_16BSI: {
2105  band->nodataval = rt_util_clamp_to_16BSI(val);
2106  checkvalint = band->nodataval;
2107  break;
2108  }
2109  case PT_16BUI: {
2110  band->nodataval = rt_util_clamp_to_16BUI(val);
2111  checkvalint = band->nodataval;
2112  break;
2113  }
2114  case PT_32BSI: {
2115  band->nodataval = rt_util_clamp_to_32BSI(val);
2116  checkvalint = band->nodataval;
2117  break;
2118  }
2119  case PT_32BUI: {
2120  band->nodataval = rt_util_clamp_to_32BUI(val);
2121  checkvaluint = band->nodataval;
2122  break;
2123  }
2124  case PT_32BF: {
2125  band->nodataval = rt_util_clamp_to_32F(val);
2126  checkvalfloat = band->nodataval;
2127  break;
2128  }
2129  case PT_64BF: {
2130  band->nodataval = val;
2131  checkvaldouble = band->nodataval;
2132  break;
2133  }
2134  default: {
2135  rterror("rt_band_set_nodata: Unknown pixeltype %d", pixtype);
2136  band->hasnodata = 0;
2137  return ES_ERROR;
2138  }
2139  }
2140 
2141  RASTER_DEBUGF(3, "rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
2142  RASTER_DEBUGF(3, "rt_band_set_nodata: band->nodataval = %f", band->nodataval);
2143  /* the nodata value was just set, so this band has NODATA */
2144  band->hasnodata = 1;
2145 
2146  /* also set isnodata flag to false */
2147  band->isnodata = 0;
2148 
2150  val,
2151  checkvalint, checkvaluint,
2152  checkvalfloat, checkvaldouble,
2153  pixtype
2154  ) && converted != NULL) {
2155  *converted = 1;
2156  }
2157 
2158  return ES_NONE;
2159 }
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_api.c:109
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_api.c:99
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_api.c:1168
float rt_util_clamp_to_32F(double value)
Definition: rt_api.c:134
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_api.c:124
rt_pixtype pixtype
Definition: rt_api.h:2239
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_api.c:89
Definition: rt_api.h:184
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
Definition: rt_api.c:934
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_api.c:94
Definition: rt_api.h:173
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_api.c:119
rt_pixtype
Definition: rt_api.h:172
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_api.c:129
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
double nodataval
Definition: rt_api.h:2246
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int32_t isnodata
Definition: rt_api.h:2244
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_api.c:104
int32_t hasnodata
Definition: rt_api.h:2243
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_api.c:114

Here is the call graph for this function:

Here is the caller graph for this function: