PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_band_get_pixel_line()

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 1137 of file rt_band.c.

1142  {
1143  uint8_t *_vals = NULL;
1144  int pixsize = 0;
1145  uint8_t *data = NULL;
1146  uint32_t offset = 0;
1147  uint16_t _nvals = 0;
1148  int maxlen = 0;
1149  uint8_t *ptr = NULL;
1150 
1151  assert(NULL != band);
1152  assert(vals != NULL && nvals != NULL);
1153 
1154  /* initialize to no values */
1155  *nvals = 0;
1156 
1157  if (
1158  x < 0 || x >= band->width ||
1159  y < 0 || y >= band->height
1160  ) {
1161  rtwarn("Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
1162  return ES_ERROR;
1163  }
1164 
1165  if (len < 1)
1166  return ES_NONE;
1167 
1169  if (data == NULL) {
1170  rterror("rt_band_get_pixel_line: Cannot get band data");
1171  return ES_ERROR;
1172  }
1173 
1174  /* +1 for the nodata value */
1175  offset = x + (y * band->width);
1176  RASTER_DEBUGF(4, "offset = %d", offset);
1177 
1178  pixsize = rt_pixtype_size(band->pixtype);
1179  RASTER_DEBUGF(4, "pixsize = %d", pixsize);
1180 
1181  /* cap _nvals so that it doesn't overflow */
1182  _nvals = len;
1183  maxlen = band->width * band->height;
1184 
1185  if (((int) (offset + _nvals)) > maxlen) {
1186  _nvals = maxlen - offset;
1187  rtwarn("Limiting returning number values to %d", _nvals);
1188  }
1189  RASTER_DEBUGF(4, "_nvals = %d", _nvals);
1190 
1191  ptr = data + (offset * pixsize);
1192 
1193  _vals = rtalloc(_nvals * pixsize);
1194  if (_vals == NULL) {
1195  rterror("rt_band_get_pixel_line: Could not allocate memory for pixel values");
1196  return ES_ERROR;
1197  }
1198 
1199  /* copy pixels */
1200  memcpy(_vals, ptr, _nvals * pixsize);
1201 
1202  *vals = _vals;
1203  *nvals = _nvals;
1204 
1205  return ES_NONE;
1206 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
band
Definition: ovdump.py:57
data
Definition: ovdump.py:103
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:400
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79

References ovdump::band, ovdump::data, ES_ERROR, ES_NONE, RASTER_DEBUGF, rt_band_get_data(), rt_pixtype_size(), rtalloc(), rterror(), rtwarn(), pixval::x, and pixval::y.

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

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