PostGIS  2.5.0beta2dev-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 733 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().

733  {
734  rt_pixtype pixtype = PT_END;
735  int32_t checkvalint = 0;
736  uint32_t checkvaluint = 0;
737  float checkvalfloat = 0;
738  double checkvaldouble = 0;
739 
740  assert(NULL != band);
741 
742  if (converted != NULL)
743  *converted = 0;
744 
745  pixtype = band->pixtype;
746 
747  RASTER_DEBUGF(3, "rt_band_set_nodata: setting nodata value %g with band type %s", val, rt_pixtype_name(pixtype));
748 
749  /* return -1 on out of range */
750  switch (pixtype) {
751  case PT_1BB: {
752  band->nodataval = rt_util_clamp_to_1BB(val);
753  checkvalint = band->nodataval;
754  break;
755  }
756  case PT_2BUI: {
757  band->nodataval = rt_util_clamp_to_2BUI(val);
758  checkvalint = band->nodataval;
759  break;
760  }
761  case PT_4BUI: {
762  band->nodataval = rt_util_clamp_to_4BUI(val);
763  checkvalint = band->nodataval;
764  break;
765  }
766  case PT_8BSI: {
767  band->nodataval = rt_util_clamp_to_8BSI(val);
768  checkvalint = band->nodataval;
769  break;
770  }
771  case PT_8BUI: {
772  band->nodataval = rt_util_clamp_to_8BUI(val);
773  checkvalint = band->nodataval;
774  break;
775  }
776  case PT_16BSI: {
777  band->nodataval = rt_util_clamp_to_16BSI(val);
778  checkvalint = band->nodataval;
779  break;
780  }
781  case PT_16BUI: {
782  band->nodataval = rt_util_clamp_to_16BUI(val);
783  checkvalint = band->nodataval;
784  break;
785  }
786  case PT_32BSI: {
787  band->nodataval = rt_util_clamp_to_32BSI(val);
788  checkvalint = band->nodataval;
789  break;
790  }
791  case PT_32BUI: {
792  band->nodataval = rt_util_clamp_to_32BUI(val);
793  checkvaluint = band->nodataval;
794  break;
795  }
796  case PT_32BF: {
797  band->nodataval = rt_util_clamp_to_32F(val);
798  checkvalfloat = band->nodataval;
799  break;
800  }
801  case PT_64BF: {
802  band->nodataval = val;
803  checkvaldouble = band->nodataval;
804  break;
805  }
806  default: {
807  rterror("rt_band_set_nodata: Unknown pixeltype %d", pixtype);
808  band->hasnodata = 0;
809  return ES_ERROR;
810  }
811  }
812 
813  RASTER_DEBUGF(3, "rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
814  RASTER_DEBUGF(3, "rt_band_set_nodata: band->nodataval = %f", band->nodataval);
815  /* the nodata value was just set, so this band has NODATA */
816  band->hasnodata = 1;
817 
818  /* also set isnodata flag to false */
819  band->isnodata = 0;
820 
822  val,
823  checkvalint, checkvaluint,
824  checkvalfloat, checkvaldouble,
825  pixtype
826  ) && converted != NULL) {
827  *converted = 1;
828  }
829 
830  return ES_NONE;
831 }
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:2314
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:627
double nodataval
Definition: librtcore.h:2321
#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:2319
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
int32_t hasnodata
Definition: librtcore.h:2318
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: