PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ rt_band_set_nodata()

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: if non-zero, value was truncated/clamped/coverted
Returns
ES_NONE or ES_ERROR

Definition at line 685 of file rt_band.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().

685  {
686  rt_pixtype pixtype = PT_END;
687  int32_t checkvalint = 0;
688  uint32_t checkvaluint = 0;
689  float checkvalfloat = 0;
690  double checkvaldouble = 0;
691 
692  assert(NULL != band);
693 
694  if (converted != NULL)
695  *converted = 0;
696 
697  pixtype = band->pixtype;
698 
699  RASTER_DEBUGF(3, "rt_band_set_nodata: setting nodata value %g with band type %s", val, rt_pixtype_name(pixtype));
700 
701  /* return -1 on out of range */
702  switch (pixtype) {
703  case PT_1BB: {
704  band->nodataval = rt_util_clamp_to_1BB(val);
705  checkvalint = band->nodataval;
706  break;
707  }
708  case PT_2BUI: {
709  band->nodataval = rt_util_clamp_to_2BUI(val);
710  checkvalint = band->nodataval;
711  break;
712  }
713  case PT_4BUI: {
714  band->nodataval = rt_util_clamp_to_4BUI(val);
715  checkvalint = band->nodataval;
716  break;
717  }
718  case PT_8BSI: {
719  band->nodataval = rt_util_clamp_to_8BSI(val);
720  checkvalint = band->nodataval;
721  break;
722  }
723  case PT_8BUI: {
724  band->nodataval = rt_util_clamp_to_8BUI(val);
725  checkvalint = band->nodataval;
726  break;
727  }
728  case PT_16BSI: {
729  band->nodataval = rt_util_clamp_to_16BSI(val);
730  checkvalint = band->nodataval;
731  break;
732  }
733  case PT_16BUI: {
734  band->nodataval = rt_util_clamp_to_16BUI(val);
735  checkvalint = band->nodataval;
736  break;
737  }
738  case PT_32BSI: {
739  band->nodataval = rt_util_clamp_to_32BSI(val);
740  checkvalint = band->nodataval;
741  break;
742  }
743  case PT_32BUI: {
744  band->nodataval = rt_util_clamp_to_32BUI(val);
745  checkvaluint = band->nodataval;
746  break;
747  }
748  case PT_32BF: {
749  band->nodataval = rt_util_clamp_to_32F(val);
750  checkvalfloat = band->nodataval;
751  break;
752  }
753  case PT_64BF: {
754  band->nodataval = val;
755  checkvaldouble = band->nodataval;
756  break;
757  }
758  default: {
759  rterror("rt_band_set_nodata: Unknown pixeltype %d", pixtype);
760  band->hasnodata = 0;
761  return ES_ERROR;
762  }
763  }
764 
765  RASTER_DEBUGF(3, "rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
766  RASTER_DEBUGF(3, "rt_band_set_nodata: band->nodataval = %f", band->nodataval);
767  /* the nodata value was just set, so this band has NODATA */
768  band->hasnodata = 1;
769 
770  /* also set isnodata flag to false */
771  band->isnodata = 0;
772 
774  val,
775  checkvalint, checkvaluint,
776  checkvalfloat, checkvaldouble,
777  pixtype
778  ) && converted != NULL) {
779  *converted = 1;
780  }
781 
782  return ES_NONE;
783 }
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:69
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:74
rt_pixtype pixtype
Definition: librtcore.h:2294
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
rt_pixtype
Definition: librtcore.h:185
unsigned int uint32_t
Definition: uthash.h:78
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:64
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:49
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
Definition: rt_util.c:625
double nodataval
Definition: librtcore.h:2301
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:44
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:54
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_util.c:34
int32_t isnodata
Definition: librtcore.h:2299
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
int32_t hasnodata
Definition: librtcore.h:2298
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:39
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:79
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:59
Here is the call graph for this function:
Here is the caller graph for this function: