PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_band_get_pixel_line ( rt_band  band,
int  x,
int  y,
uint16_t  len,
void **  vals,
uint16_t *  nvals 
)

Get values of multiple pixels.

Unlike rt_band_get_pixel, values in vals are of the band's pixel type so cannot be assumed to be double. Function uses memcpy.

It is important to be careful when using this function as the number of values being fetched may exceed a pixel "row". Remember that the band values are stored in a stream (1-D array) regardless of what the raster's width and height might be. So, getting a number of values may cross multiple pixel "rows".

Parameters
band: the band to get pixel value from
x: pixel column (0-based)
y: pixel row (0-based)
len: the number of pixels to get
**vals: the pixel values
*nvals: the number of pixel values being returned
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 2465 of file rt_api.c.

References ovdump::data, ES_ERROR, ES_NONE, rt_band_t::height, rt_band_t::pixtype, RASTER_DEBUGF, rt_band_get_data(), rt_pixtype_size(), rtalloc(), rterror(), rtwarn(), and rt_band_t::width.

Referenced by RASTER_tile(), RASTER_union_transfn(), and test_band_get_pixel_line().

2470  {
2471  uint8_t *_vals = NULL;
2472  int pixsize = 0;
2473  uint8_t *data = NULL;
2474  uint32_t offset = 0;
2475  uint16_t _nvals = 0;
2476  int maxlen = 0;
2477  uint8_t *ptr = NULL;
2478 
2479  assert(NULL != band);
2480  assert(vals != NULL && nvals != NULL);
2481 
2482  /* initialize to no values */
2483  *nvals = 0;
2484 
2485  if (
2486  x < 0 || x >= band->width ||
2487  y < 0 || y >= band->height
2488  ) {
2489  rtwarn("Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
2490  return ES_ERROR;
2491  }
2492 
2493  if (len < 1)
2494  return ES_NONE;
2495 
2496  data = rt_band_get_data(band);
2497  if (data == NULL) {
2498  rterror("rt_band_get_pixel_line: Cannot get band data");
2499  return ES_ERROR;
2500  }
2501 
2502  /* +1 for the nodata value */
2503  offset = x + (y * band->width);
2504  RASTER_DEBUGF(4, "offset = %d", offset);
2505 
2506  pixsize = rt_pixtype_size(band->pixtype);
2507  RASTER_DEBUGF(4, "pixsize = %d", pixsize);
2508 
2509  /* cap _nvals so that it doesn't overflow */
2510  _nvals = len;
2511  maxlen = band->width * band->height;
2512 
2513  if (((int) (offset + _nvals)) > maxlen) {
2514  _nvals = maxlen - offset;
2515  rtwarn("Limiting returning number values to %d", _nvals);
2516  }
2517  RASTER_DEBUGF(4, "_nvals = %d", _nvals);
2518 
2519  ptr = data + (offset * pixsize);
2520 
2521  _vals = rtalloc(_nvals * pixsize);
2522  if (_vals == NULL) {
2523  rterror("rt_band_get_pixel_line: Could not allocate memory for pixel values");
2524  return ES_ERROR;
2525  }
2526 
2527  /* copy pixels */
2528  memcpy(_vals, ptr, _nvals * pixsize);
2529 
2530  *vals = _vals;
2531  *nvals = _nvals;
2532 
2533  return ES_NONE;
2534 }
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
rt_pixtype pixtype
Definition: rt_api.h:2239
uint16_t height
Definition: rt_api.h:2242
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_api.c:1097
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
uint16_t width
Definition: rt_api.h:2241
tuple x
Definition: pixval.py:53
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: