PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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/converted
Returns
ES_NONE or ES_ERROR

Definition at line 892 of file rt_band.c.

892 {
893 rt_pixtype pixtype = PT_END;
894 int32_t checkvalint = 0;
895 uint32_t checkvaluint = 0;
896 float checkvalfloat = 0;
897 double checkvaldouble = 0;
898
899 assert(NULL != band);
900
901 if (converted != NULL)
902 *converted = 0;
903
904 pixtype = band->pixtype;
905
906 RASTER_DEBUGF(3, "rt_band_set_nodata: setting nodata value %g with band type %s", val, rt_pixtype_name(pixtype));
907
908 /* return -1 on out of range */
909 switch (pixtype) {
910 case PT_1BB: {
911 band->nodataval = rt_util_clamp_to_1BB(val);
912 checkvalint = band->nodataval;
913 break;
914 }
915 case PT_2BUI: {
916 band->nodataval = rt_util_clamp_to_2BUI(val);
917 checkvalint = band->nodataval;
918 break;
919 }
920 case PT_4BUI: {
921 band->nodataval = rt_util_clamp_to_4BUI(val);
922 checkvalint = band->nodataval;
923 break;
924 }
925 case PT_8BSI: {
926 band->nodataval = rt_util_clamp_to_8BSI(val);
927 checkvalint = band->nodataval;
928 break;
929 }
930 case PT_8BUI: {
931 band->nodataval = rt_util_clamp_to_8BUI(val);
932 checkvalint = band->nodataval;
933 break;
934 }
935 case PT_16BSI: {
936 band->nodataval = rt_util_clamp_to_16BSI(val);
937 checkvalint = band->nodataval;
938 break;
939 }
940 case PT_16BUI: {
941 band->nodataval = rt_util_clamp_to_16BUI(val);
942 checkvalint = band->nodataval;
943 break;
944 }
945 case PT_32BSI: {
946 band->nodataval = rt_util_clamp_to_32BSI(val);
947 checkvalint = band->nodataval;
948 break;
949 }
950 case PT_32BUI: {
951 band->nodataval = rt_util_clamp_to_32BUI(val);
952 checkvaluint = band->nodataval;
953 break;
954 }
955 case PT_16BF: {
956 float half = rt_util_clamp_to_16F(val);
957 /* Persist the exact half-float encoding so nodata comparisons stay bitwise-stable. */
959 checkvalfloat = (float)band->nodataval;
960 break;
961 }
962 case PT_32BF: {
963 band->nodataval = rt_util_clamp_to_32F(val);
964 checkvalfloat = band->nodataval;
965 break;
966 }
967 case PT_64BF: {
968 band->nodataval = val;
969 checkvaldouble = band->nodataval;
970 break;
971 }
972 default: {
973 rterror("rt_band_set_nodata: Unknown pixeltype %d", pixtype);
974 band->hasnodata = 0;
975 return ES_ERROR;
976 }
977 }
978
979 RASTER_DEBUGF(3, "rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
980 RASTER_DEBUGF(3, "rt_band_set_nodata: band->nodataval = %f", band->nodataval);
981 /* the nodata value was just set, so this band has NODATA */
982 band->hasnodata = 1;
983
984 /* also set isnodata flag to false */
985 band->isnodata = 0;
986
988 val,
989 checkvalint, checkvaluint,
990 checkvalfloat, checkvaldouble,
991 pixtype
992 ) && converted != NULL) {
993 *converted = 1;
994 }
995
996 return ES_NONE;
997}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:308
int8_t rt_util_clamp_to_8BSI(double value)
Definition rt_util.c:51
uint8_t rt_util_clamp_to_1BB(double value)
Definition rt_util.c:36
float rt_util_clamp_to_16F(double value)
Definition rt_util.c:88
int32_t rt_util_clamp_to_32BSI(double value)
Definition rt_util.c:71
uint16_t rt_util_float_to_float16(float value)
Definition rt_util.c:101
float rt_util_float16_to_float(uint16_t value)
Definition rt_util.c:134
rt_pixtype
Definition librtcore.h:188
@ PT_32BUI
Definition librtcore.h:197
@ PT_16BF
Definition librtcore.h:198
@ PT_2BUI
Definition librtcore.h:190
@ PT_32BSI
Definition librtcore.h:196
@ PT_END
Definition librtcore.h:201
@ PT_4BUI
Definition librtcore.h:191
@ PT_32BF
Definition librtcore.h:199
@ PT_1BB
Definition librtcore.h:189
@ PT_16BUI
Definition librtcore.h:195
@ PT_8BSI
Definition librtcore.h:192
@ PT_16BSI
Definition librtcore.h:194
@ PT_64BF
Definition librtcore.h:200
@ PT_8BUI
Definition librtcore.h:193
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:778
uint8_t rt_util_clamp_to_2BUI(double value)
Definition rt_util.c:41
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition rt_pixel.c:114
uint8_t rt_util_clamp_to_8BUI(double value)
Definition rt_util.c:56
@ ES_NONE
Definition librtcore.h:182
@ ES_ERROR
Definition librtcore.h:183
int16_t rt_util_clamp_to_16BSI(double value)
Definition rt_util.c:61
uint8_t rt_util_clamp_to_4BUI(double value)
Definition rt_util.c:46
uint16_t rt_util_clamp_to_16BUI(double value)
Definition rt_util.c:66
uint32_t rt_util_clamp_to_32BUI(double value)
Definition rt_util.c:76
float rt_util_clamp_to_32F(double value)
Definition rt_util.c:81

References ES_ERROR, ES_NONE, PT_16BF, 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_16F(), 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(), rt_util_float16_to_float(), rt_util_float_to_float16(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: