PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_band_get_pixel ( rt_band  band,
int  x,
int  y,
double *  value,
int *  nodata 
)

Get pixel value.

If band's isnodata flag is TRUE, value returned will be the band's NODATA value

Parameters
band: the band to set nodata value to
x: x ordinate (0-based)
y: x ordinate (0-based)
*value: pixel value
*nodata: 0 if pixel is not NODATA
Returns
0 on success, -1 on error (value out of valid range).

Definition at line 2549 of file rt_api.c.

References ovdump::data, ES_ERROR, ES_NONE, rt_band_t::hasnodata, rt_band_t::height, 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_DEBUG, rt_band_clamped_value_is_nodata(), rt_band_get_data(), rterror(), rtwarn(), and rt_band_t::width.

Referenced by _rti_raster_get_band_perimeter(), RASTER_dumpValues(), RASTER_getPixelPolygons(), RASTER_getPixelValue(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_nearestValue(), RASTER_neighborhood(), RASTER_setPixelValuesArray(), RASTER_setPixelValuesGeomval(), rt_band_check_is_nodata(), rt_band_get_nearest_pixel(), rt_band_get_pixel_of_value(), rt_band_get_quantiles_stream(), rt_band_get_summary_stats(), rt_band_get_value_count(), rt_band_reclass(), rt_band_set_pixel_line(), rt_raster_gdal_rasterize(), rt_raster_intersects(), rt_raster_intersects_algorithm(), rt_raster_iterator(), rt_raster_to_gdal_mem(), 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_gdal_to_raster(), test_gdal_warp(), test_raster_colormap(), and test_raster_wkb().

2554  {
2555  rt_pixtype pixtype = PT_END;
2556  uint8_t* data = NULL;
2557  uint32_t offset = 0;
2558 
2559  assert(NULL != band);
2560  assert(NULL != value);
2561 
2562  /* set nodata to 0 */
2563  if (nodata != NULL)
2564  *nodata = 0;
2565 
2566  if (
2567  x < 0 || x >= band->width ||
2568  y < 0 || y >= band->height
2569  ) {
2570  rtwarn("Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
2571  return ES_ERROR;
2572  }
2573 
2574  /* band is NODATA */
2575  if (band->isnodata) {
2576  RASTER_DEBUG(3, "Band's isnodata flag is TRUE. Returning NODATA value");
2577  *value = band->nodataval;
2578  if (nodata != NULL) *nodata = 1;
2579  return ES_NONE;
2580  }
2581 
2582  data = rt_band_get_data(band);
2583  if (data == NULL) {
2584  rterror("rt_band_get_pixel: Cannot get band data");
2585  return ES_ERROR;
2586  }
2587 
2588  /* +1 for the nodata value */
2589  offset = x + (y * band->width);
2590 
2591  pixtype = band->pixtype;
2592 
2593  switch (pixtype) {
2594  case PT_1BB:
2595 #ifdef OPTIMIZE_SPACE
2596  {
2597  int byteOffset = offset / 8;
2598  int bitOffset = offset % 8;
2599  data += byteOffset;
2600 
2601  /* Bit to set is bitOffset into data */
2602  *value = getBits(data, val, 1, bitOffset);
2603  break;
2604  }
2605 #endif
2606  case PT_2BUI:
2607 #ifdef OPTIMIZE_SPACE
2608  {
2609  int byteOffset = offset / 4;
2610  int bitOffset = offset % 4;
2611  data += byteOffset;
2612 
2613  /* Bits to set start at bitOffset into data */
2614  *value = getBits(data, val, 2, bitOffset);
2615  break;
2616  }
2617 #endif
2618  case PT_4BUI:
2619 #ifdef OPTIMIZE_SPACE
2620  {
2621  int byteOffset = offset / 2;
2622  int bitOffset = offset % 2;
2623  data += byteOffset;
2624 
2625  /* Bits to set start at bitOffset into data */
2626  *value = getBits(data, val, 2, bitOffset);
2627  break;
2628  }
2629 #endif
2630  case PT_8BSI: {
2631  int8_t val = data[offset];
2632  *value = val;
2633  break;
2634  }
2635  case PT_8BUI: {
2636  uint8_t val = data[offset];
2637  *value = val;
2638  break;
2639  }
2640  case PT_16BSI: {
2641  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
2642  *value = ptr[offset];
2643  break;
2644  }
2645  case PT_16BUI: {
2646  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
2647  *value = ptr[offset];
2648  break;
2649  }
2650  case PT_32BSI: {
2651  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
2652  *value = ptr[offset];
2653  break;
2654  }
2655  case PT_32BUI: {
2656  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
2657  *value = ptr[offset];
2658  break;
2659  }
2660  case PT_32BF: {
2661  float *ptr = (float*) data; /* we assume correct alignment */
2662  *value = ptr[offset];
2663  break;
2664  }
2665  case PT_64BF: {
2666  double *ptr = (double*) data; /* we assume correct alignment */
2667  *value = ptr[offset];
2668  break;
2669  }
2670  default: {
2671  rterror("rt_band_get_pixel: Unknown pixeltype %d", pixtype);
2672  return ES_ERROR;
2673  }
2674  }
2675 
2676  /* set NODATA flag */
2677  if (band->hasnodata && nodata != NULL) {
2679  *nodata = 1;
2680  }
2681 
2682  return ES_NONE;
2683 }
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
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
Definition: rt_api.h:184
uint16_t height
Definition: rt_api.h:2242
Definition: rt_api.h:173
#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
double nodataval
Definition: rt_api.h:2246
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 isnodata
Definition: rt_api.h:2244
int32_t hasnodata
Definition: rt_api.h:2243
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: