PostGIS  2.5.0dev-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: 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 926 of file rt_band.c.

References ovdump::data, ES_ERROR, ES_NONE, FALSE, rt_band_t::hasnodata, rt_band_t::height, rt_band_t::isnodata, rt_band_t::offline, 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_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(), and rt_band_t::width.

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().

931  {
932  rt_pixtype pixtype = PT_END;
933  unsigned char* data = NULL;
934  uint32_t offset = 0;
935 
936  int32_t checkvalint = 0;
937  uint32_t checkvaluint = 0;
938  float checkvalfloat = 0;
939  double checkvaldouble = 0;
940 
941  assert(NULL != band);
942 
943  if (converted != NULL)
944  *converted = 0;
945 
946  if (band->offline) {
947  rterror("rt_band_set_pixel not implemented yet for OFFDB bands");
948  return ES_ERROR;
949  }
950 
951  pixtype = band->pixtype;
952 
953  if (
954  x < 0 || x >= band->width ||
955  y < 0 || y >= band->height
956  ) {
957  rterror("rt_band_set_pixel: Coordinates out of range");
958  return ES_ERROR;
959  }
960 
961  /* check that clamped value isn't clamped NODATA */
962  if (band->hasnodata && pixtype != PT_64BF) {
963  double newval;
964  int corrected;
965 
966  rt_band_corrected_clamped_value(band, val, &newval, &corrected);
967 
968  if (corrected) {
969 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
970  rtwarn("Value for pixel %d x %d has been corrected as clamped value becomes NODATA", x, y);
971 #endif
972  val = newval;
973 
974  if (converted != NULL)
975  *converted = 1;
976  }
977  }
978 
979  data = rt_band_get_data(band);
980  offset = x + (y * band->width);
981 
982  switch (pixtype) {
983  case PT_1BB: {
984  data[offset] = rt_util_clamp_to_1BB(val);
985  checkvalint = data[offset];
986  break;
987  }
988  case PT_2BUI: {
989  data[offset] = rt_util_clamp_to_2BUI(val);
990  checkvalint = data[offset];
991  break;
992  }
993  case PT_4BUI: {
994  data[offset] = rt_util_clamp_to_4BUI(val);
995  checkvalint = data[offset];
996  break;
997  }
998  case PT_8BSI: {
999  data[offset] = rt_util_clamp_to_8BSI(val);
1000  checkvalint = (int8_t) data[offset];
1001  break;
1002  }
1003  case PT_8BUI: {
1004  data[offset] = rt_util_clamp_to_8BUI(val);
1005  checkvalint = data[offset];
1006  break;
1007  }
1008  case PT_16BSI: {
1009  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
1010  ptr[offset] = rt_util_clamp_to_16BSI(val);
1011  checkvalint = (int16_t) ptr[offset];
1012  break;
1013  }
1014  case PT_16BUI: {
1015  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
1016  ptr[offset] = rt_util_clamp_to_16BUI(val);
1017  checkvalint = ptr[offset];
1018  break;
1019  }
1020  case PT_32BSI: {
1021  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
1022  ptr[offset] = rt_util_clamp_to_32BSI(val);
1023  checkvalint = (int32_t) ptr[offset];
1024  break;
1025  }
1026  case PT_32BUI: {
1027  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
1028  ptr[offset] = rt_util_clamp_to_32BUI(val);
1029  checkvaluint = ptr[offset];
1030  break;
1031  }
1032  case PT_32BF: {
1033  float *ptr = (float*) data; /* we assume correct alignment */
1034  ptr[offset] = rt_util_clamp_to_32F(val);
1035  checkvalfloat = ptr[offset];
1036  break;
1037  }
1038  case PT_64BF: {
1039  double *ptr = (double*) data; /* we assume correct alignment */
1040  ptr[offset] = val;
1041  checkvaldouble = ptr[offset];
1042  break;
1043  }
1044  default: {
1045  rterror("rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1046  return ES_ERROR;
1047  }
1048  }
1049 
1050  /* If the stored value is not NODATA, reset the isnodata flag */
1051  if (!rt_band_clamped_value_is_nodata(band, val)) {
1052  RASTER_DEBUG(3, "Band has a value that is not NODATA. Setting isnodata to FALSE");
1053  band->isnodata = FALSE;
1054  }
1055 
1056  /* Overflow checking */
1058  val,
1059  checkvalint, checkvaluint,
1060  checkvalfloat, checkvaldouble,
1061  pixtype
1062  ) && converted != NULL) {
1063  *converted = 1;
1064  }
1065 
1066  return ES_NONE;
1067 }
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
data
Definition: ovdump.py:103
uint16_t height
Definition: librtcore.h:2297
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
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
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
uint16_t width
Definition: librtcore.h:2296
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
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band&#39;s clamped NODATA value.
Definition: rt_band.c:1750
int32_t offline
Definition: librtcore.h:2295
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:1786
int32_t isnodata
Definition: librtcore.h:2299
#define FALSE
Definition: dbfopen.c:168
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
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
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:396
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: