PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_band_set_pixel()

rt_errorstate rt_band_set_pixel ( rt_band  band,
int  x,
int  y,
double  val,
int *  converted 
)

Set single pixel's value.

Parameters
band: the band to set value to
x: pixel column (0-based)
y: pixel row (0-based)
val: the pixel value
converted: (optional) non-zero if value truncated/clamped/converted
Returns
ES_NONE on success, ES_ERROR on error
Parameters
band: the band to set value to
x: x ordinate (0-based)
y: y ordinate (0-based)
val: the pixel value
converted: (optional) non-zero if value truncated/clamped/converted
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 974 of file rt_band.c.

979  {
980  rt_pixtype pixtype = PT_END;
981  unsigned char* data = NULL;
982  uint32_t offset = 0;
983 
984  int32_t checkvalint = 0;
985  uint32_t checkvaluint = 0;
986  float checkvalfloat = 0;
987  double checkvaldouble = 0;
988 
989  assert(NULL != band);
990 
991  if (converted != NULL)
992  *converted = 0;
993 
994  if (band->offline) {
995  rterror("rt_band_set_pixel not implemented yet for OFFDB bands");
996  return ES_ERROR;
997  }
998 
999  pixtype = band->pixtype;
1000 
1001  if (
1002  x < 0 || x >= band->width ||
1003  y < 0 || y >= band->height
1004  ) {
1005  rterror("rt_band_set_pixel: Coordinates out of range");
1006  return ES_ERROR;
1007  }
1008 
1009  /* check that clamped value isn't clamped NODATA */
1010  if (band->hasnodata && pixtype != PT_64BF) {
1011  double newval;
1012  int corrected;
1013 
1014  rt_band_corrected_clamped_value(band, val, &newval, &corrected);
1015 
1016  if (corrected) {
1017 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1018  rtwarn("Value for pixel %d x %d has been corrected as clamped value becomes NODATA", x, y);
1019 #endif
1020  val = newval;
1021 
1022  if (converted != NULL)
1023  *converted = 1;
1024  }
1025  }
1026 
1028  offset = x + (y * band->width);
1029 
1030  switch (pixtype) {
1031  case PT_1BB: {
1032  data[offset] = rt_util_clamp_to_1BB(val);
1033  checkvalint = data[offset];
1034  break;
1035  }
1036  case PT_2BUI: {
1037  data[offset] = rt_util_clamp_to_2BUI(val);
1038  checkvalint = data[offset];
1039  break;
1040  }
1041  case PT_4BUI: {
1042  data[offset] = rt_util_clamp_to_4BUI(val);
1043  checkvalint = data[offset];
1044  break;
1045  }
1046  case PT_8BSI: {
1047  data[offset] = rt_util_clamp_to_8BSI(val);
1048  checkvalint = (int8_t) data[offset];
1049  break;
1050  }
1051  case PT_8BUI: {
1052  data[offset] = rt_util_clamp_to_8BUI(val);
1053  checkvalint = data[offset];
1054  break;
1055  }
1056  case PT_16BSI: {
1057  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
1058  ptr[offset] = rt_util_clamp_to_16BSI(val);
1059  checkvalint = (int16_t) ptr[offset];
1060  break;
1061  }
1062  case PT_16BUI: {
1063  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
1064  ptr[offset] = rt_util_clamp_to_16BUI(val);
1065  checkvalint = ptr[offset];
1066  break;
1067  }
1068  case PT_32BSI: {
1069  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
1070  ptr[offset] = rt_util_clamp_to_32BSI(val);
1071  checkvalint = (int32_t) ptr[offset];
1072  break;
1073  }
1074  case PT_32BUI: {
1075  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
1076  ptr[offset] = rt_util_clamp_to_32BUI(val);
1077  checkvaluint = ptr[offset];
1078  break;
1079  }
1080  case PT_32BF: {
1081  float *ptr = (float*) data; /* we assume correct alignment */
1082  ptr[offset] = rt_util_clamp_to_32F(val);
1083  checkvalfloat = ptr[offset];
1084  break;
1085  }
1086  case PT_64BF: {
1087  double *ptr = (double*) data; /* we assume correct alignment */
1088  ptr[offset] = val;
1089  checkvaldouble = ptr[offset];
1090  break;
1091  }
1092  default: {
1093  rterror("rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1094  return ES_ERROR;
1095  }
1096  }
1097 
1098  /* If the stored value is not NODATA, reset the isnodata flag */
1100  RASTER_DEBUG(3, "Band has a value that is not NODATA. Setting isnodata to FALSE");
1101  band->isnodata = FALSE;
1102  }
1103 
1104  /* Overflow checking */
1106  val,
1107  checkvalint, checkvaluint,
1108  checkvalfloat, checkvaldouble,
1109  pixtype
1110  ) && converted != NULL) {
1111  *converted = 1;
1112  }
1113 
1114  return ES_NONE;
1115 }
#define FALSE
Definition: dbfopen.c:168
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:49
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_util.c:34
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:69
rt_pixtype
Definition: librtcore.h:185
@ PT_32BUI
Definition: librtcore.h:194
@ PT_2BUI
Definition: librtcore.h:187
@ PT_32BSI
Definition: librtcore.h:193
@ PT_END
Definition: librtcore.h:197
@ PT_4BUI
Definition: librtcore.h:188
@ PT_32BF
Definition: librtcore.h:195
@ PT_1BB
Definition: librtcore.h:186
@ PT_16BUI
Definition: librtcore.h:192
@ PT_8BSI
Definition: librtcore.h:189
@ PT_16BSI
Definition: librtcore.h:191
@ PT_64BF
Definition: librtcore.h:196
@ PT_8BUI
Definition: librtcore.h:190
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
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:39
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:54
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:59
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:44
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:64
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:74
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:79
band
Definition: ovdump.py:57
data
Definition: ovdump.py:103
rt_errorstate rt_band_corrected_clamped_value(rt_band band, double val, double *newval, int *corrected)
Correct value when clamped value is equal to clamped NODATA value.
Definition: rt_band.c:1834
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:400
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_band.c:1798
unsigned int uint32_t
Definition: uthash.h:78

References ovdump::band, ovdump::data, ES_ERROR, ES_NONE, FALSE, 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_DEBUG, rt_band_clamped_value_is_nodata(), rt_band_corrected_clamped_value(), rt_band_get_data(), 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(), rterror(), rtwarn(), pixval::x, and pixval::y.

Referenced by fillRasterToPolygonize(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_setPixelValue(), RASTER_setPixelValuesArray(), RASTER_setPixelValuesGeomval(), rt_band_reclass(), rt_raster_gdal_rasterize(), rt_raster_iterator(), test_band_get_nearest_pixel(), test_band_get_pixel_line(), test_band_get_pixel_of_value(), 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_gdal_to_raster(), test_gdal_warp(), test_pixel_set_to_array(), test_raster_colormap(), 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(), test_raster_iterator(), test_raster_perimeter(), test_raster_pixel_as_polygon(), test_raster_surface(), test_raster_to_gdal(), and test_raster_within_distance().

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