PostGIS  2.4.9dev-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: (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 600 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().

600  {
601  rt_pixtype pixtype = PT_END;
602  int32_t checkvalint = 0;
603  uint32_t checkvaluint = 0;
604  float checkvalfloat = 0;
605  double checkvaldouble = 0;
606 
607  assert(NULL != band);
608 
609  if (converted != NULL)
610  *converted = 0;
611 
612  pixtype = band->pixtype;
613 
614  RASTER_DEBUGF(3, "rt_band_set_nodata: setting nodata value %g with band type %s", val, rt_pixtype_name(pixtype));
615 
616  /* return -1 on out of range */
617  switch (pixtype) {
618  case PT_1BB: {
619  band->nodataval = rt_util_clamp_to_1BB(val);
620  checkvalint = band->nodataval;
621  break;
622  }
623  case PT_2BUI: {
624  band->nodataval = rt_util_clamp_to_2BUI(val);
625  checkvalint = band->nodataval;
626  break;
627  }
628  case PT_4BUI: {
629  band->nodataval = rt_util_clamp_to_4BUI(val);
630  checkvalint = band->nodataval;
631  break;
632  }
633  case PT_8BSI: {
634  band->nodataval = rt_util_clamp_to_8BSI(val);
635  checkvalint = band->nodataval;
636  break;
637  }
638  case PT_8BUI: {
639  band->nodataval = rt_util_clamp_to_8BUI(val);
640  checkvalint = band->nodataval;
641  break;
642  }
643  case PT_16BSI: {
644  band->nodataval = rt_util_clamp_to_16BSI(val);
645  checkvalint = band->nodataval;
646  break;
647  }
648  case PT_16BUI: {
649  band->nodataval = rt_util_clamp_to_16BUI(val);
650  checkvalint = band->nodataval;
651  break;
652  }
653  case PT_32BSI: {
654  band->nodataval = rt_util_clamp_to_32BSI(val);
655  checkvalint = band->nodataval;
656  break;
657  }
658  case PT_32BUI: {
659  band->nodataval = rt_util_clamp_to_32BUI(val);
660  checkvaluint = band->nodataval;
661  break;
662  }
663  case PT_32BF: {
664  band->nodataval = rt_util_clamp_to_32F(val);
665  checkvalfloat = band->nodataval;
666  break;
667  }
668  case PT_64BF: {
669  band->nodataval = val;
670  checkvaldouble = band->nodataval;
671  break;
672  }
673  default: {
674  rterror("rt_band_set_nodata: Unknown pixeltype %d", pixtype);
675  band->hasnodata = 0;
676  return ES_ERROR;
677  }
678  }
679 
680  RASTER_DEBUGF(3, "rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
681  RASTER_DEBUGF(3, "rt_band_set_nodata: band->nodataval = %f", band->nodataval);
682  /* the nodata value was just set, so this band has NODATA */
683  band->hasnodata = 1;
684 
685  /* also set isnodata flag to false */
686  band->isnodata = 0;
687 
689  val,
690  checkvalint, checkvaluint,
691  checkvalfloat, checkvaldouble,
692  pixtype
693  ) && converted != NULL) {
694  *converted = 1;
695  }
696 
697  return ES_NONE;
698 }
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:2265
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:2272
#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:2270
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
int32_t hasnodata
Definition: librtcore.h:2269
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: