PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 2302 of file rt_api.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_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().

2307  {
2308  rt_pixtype pixtype = PT_END;
2309  unsigned char* data = NULL;
2310  uint32_t offset = 0;
2311 
2312  int32_t checkvalint = 0;
2313  uint32_t checkvaluint = 0;
2314  float checkvalfloat = 0;
2315  double checkvaldouble = 0;
2316 
2317  assert(NULL != band);
2318 
2319  if (converted != NULL)
2320  *converted = 0;
2321 
2322  if (band->offline) {
2323  rterror("rt_band_set_pixel not implemented yet for OFFDB bands");
2324  return ES_ERROR;
2325  }
2326 
2327  pixtype = band->pixtype;
2328 
2329  if (
2330  x < 0 || x >= band->width ||
2331  y < 0 || y >= band->height
2332  ) {
2333  rterror("rt_band_set_pixel: Coordinates out of range");
2334  return ES_ERROR;
2335  }
2336 
2337  /* check that clamped value isn't clamped NODATA */
2338  if (band->hasnodata && pixtype != PT_64BF) {
2339  double newval;
2340  int corrected;
2341 
2342  rt_band_corrected_clamped_value(band, val, &newval, &corrected);
2343 
2344  if (corrected) {
2345 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
2346  rtwarn("Value for pixel %d x %d has been corrected as clamped value becomes NODATA", x, y);
2347 #endif
2348  val = newval;
2349 
2350  if (converted != NULL)
2351  *converted = 1;
2352  }
2353  }
2354 
2355  data = rt_band_get_data(band);
2356  offset = x + (y * band->width);
2357 
2358  switch (pixtype) {
2359  case PT_1BB: {
2360  data[offset] = rt_util_clamp_to_1BB(val);
2361  checkvalint = data[offset];
2362  break;
2363  }
2364  case PT_2BUI: {
2365  data[offset] = rt_util_clamp_to_2BUI(val);
2366  checkvalint = data[offset];
2367  break;
2368  }
2369  case PT_4BUI: {
2370  data[offset] = rt_util_clamp_to_4BUI(val);
2371  checkvalint = data[offset];
2372  break;
2373  }
2374  case PT_8BSI: {
2375  data[offset] = rt_util_clamp_to_8BSI(val);
2376  checkvalint = (int8_t) data[offset];
2377  break;
2378  }
2379  case PT_8BUI: {
2380  data[offset] = rt_util_clamp_to_8BUI(val);
2381  checkvalint = data[offset];
2382  break;
2383  }
2384  case PT_16BSI: {
2385  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
2386  ptr[offset] = rt_util_clamp_to_16BSI(val);
2387  checkvalint = (int16_t) ptr[offset];
2388  break;
2389  }
2390  case PT_16BUI: {
2391  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
2392  ptr[offset] = rt_util_clamp_to_16BUI(val);
2393  checkvalint = ptr[offset];
2394  break;
2395  }
2396  case PT_32BSI: {
2397  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
2398  ptr[offset] = rt_util_clamp_to_32BSI(val);
2399  checkvalint = (int32_t) ptr[offset];
2400  break;
2401  }
2402  case PT_32BUI: {
2403  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
2404  ptr[offset] = rt_util_clamp_to_32BUI(val);
2405  checkvaluint = ptr[offset];
2406  break;
2407  }
2408  case PT_32BF: {
2409  float *ptr = (float*) data; /* we assume correct alignment */
2410  ptr[offset] = rt_util_clamp_to_32F(val);
2411  checkvalfloat = ptr[offset];
2412  break;
2413  }
2414  case PT_64BF: {
2415  double *ptr = (double*) data; /* we assume correct alignment */
2416  ptr[offset] = val;
2417  checkvaldouble = ptr[offset];
2418  break;
2419  }
2420  default: {
2421  rterror("rt_band_set_pixel: Unknown pixeltype %d", pixtype);
2422  return ES_ERROR;
2423  }
2424  }
2425 
2426  /* If the stored value is not NODATA, reset the isnodata flag */
2427  if (!rt_band_clamped_value_is_nodata(band, val)) {
2428  RASTER_DEBUG(3, "Band has a value that is not NODATA. Setting isnodata to FALSE");
2429  band->isnodata = FALSE;
2430  }
2431 
2432  /* Overflow checking */
2434  val,
2435  checkvalint, checkvaluint,
2436  checkvalfloat, checkvaldouble,
2437  pixtype
2438  ) && converted != NULL) {
2439  *converted = 1;
2440  }
2441 
2442  return ES_NONE;
2443 }
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_api.c:109
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_api.c:99
tuple data
Definition: ovdump.py:103
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_api.c:1710
float rt_util_clamp_to_32F(double value)
Definition: rt_api.c:134
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_api.c:124
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_api.c:3126
rt_pixtype pixtype
Definition: rt_api.h:2239
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_api.c:89
Definition: rt_api.h:184
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_api.c:3162
uint16_t height
Definition: rt_api.h:2242
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
Definition: rt_api.c:934
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_api.c:94
Definition: rt_api.h:173
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_api.c:119
#define RASTER_DEBUG(level, msg)
Definition: rt_api.h:281
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920
rt_pixtype
Definition: rt_api.h:172
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_api.c:129
uint16_t width
Definition: rt_api.h:2241
tuple x
Definition: pixval.py:53
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int32_t offline
Definition: rt_api.h:2240
int32_t isnodata
Definition: rt_api.h:2244
#define FALSE
Definition: dbfopen.c:169
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_api.c:104
int32_t hasnodata
Definition: rt_api.h:2243
tuple y
Definition: pixval.py:54
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_api.c:114

Here is the call graph for this function:

Here is the caller graph for this function: