PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ rt_band_get_pixel()

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 get pixel value from
x: pixel column (0-based)
y: pixel row (0-based)
*value: pixel value
*nodata: 0 if pixel is not NODATA
Returns
ES_NONE on success, ES_ERROR on error

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 1173 of file rt_band.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_pixel_set_to_array(), test_raster_colormap(), and test_raster_wkb().

1178  {
1179  rt_pixtype pixtype = PT_END;
1180  uint8_t* data = NULL;
1181  uint32_t offset = 0;
1182 
1183  assert(NULL != band);
1184  assert(NULL != value);
1185 
1186  /* set nodata to 0 */
1187  if (nodata != NULL)
1188  *nodata = 0;
1189 
1190  if (
1191  x < 0 || x >= band->width ||
1192  y < 0 || y >= band->height
1193  ) {
1194  rtwarn("Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1195  return ES_ERROR;
1196  }
1197 
1198  /* band is NODATA */
1199  if (band->isnodata) {
1200  RASTER_DEBUG(3, "Band's isnodata flag is TRUE. Returning NODATA value");
1201  *value = band->nodataval;
1202  if (nodata != NULL) *nodata = 1;
1203  return ES_NONE;
1204  }
1205 
1206  data = rt_band_get_data(band);
1207  if (data == NULL) {
1208  rterror("rt_band_get_pixel: Cannot get band data");
1209  return ES_ERROR;
1210  }
1211 
1212  /* +1 for the nodata value */
1213  offset = x + (y * band->width);
1214 
1215  pixtype = band->pixtype;
1216 
1217  switch (pixtype) {
1218  case PT_1BB:
1219 #ifdef OPTIMIZE_SPACE
1220  {
1221  int byteOffset = offset / 8;
1222  int bitOffset = offset % 8;
1223  data += byteOffset;
1224 
1225  /* Bit to set is bitOffset into data */
1226  *value = getBits(data, val, 1, bitOffset);
1227  break;
1228  }
1229 #endif
1230  case PT_2BUI:
1231 #ifdef OPTIMIZE_SPACE
1232  {
1233  int byteOffset = offset / 4;
1234  int bitOffset = offset % 4;
1235  data += byteOffset;
1236 
1237  /* Bits to set start at bitOffset into data */
1238  *value = getBits(data, val, 2, bitOffset);
1239  break;
1240  }
1241 #endif
1242  case PT_4BUI:
1243 #ifdef OPTIMIZE_SPACE
1244  {
1245  int byteOffset = offset / 2;
1246  int bitOffset = offset % 2;
1247  data += byteOffset;
1248 
1249  /* Bits to set start at bitOffset into data */
1250  *value = getBits(data, val, 2, bitOffset);
1251  break;
1252  }
1253 #endif
1254  case PT_8BSI: {
1255  int8_t val = data[offset];
1256  *value = val;
1257  break;
1258  }
1259  case PT_8BUI: {
1260  uint8_t val = data[offset];
1261  *value = val;
1262  break;
1263  }
1264  case PT_16BSI: {
1265  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
1266  *value = ptr[offset];
1267  break;
1268  }
1269  case PT_16BUI: {
1270  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
1271  *value = ptr[offset];
1272  break;
1273  }
1274  case PT_32BSI: {
1275  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
1276  *value = ptr[offset];
1277  break;
1278  }
1279  case PT_32BUI: {
1280  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
1281  *value = ptr[offset];
1282  break;
1283  }
1284  case PT_32BF: {
1285  float *ptr = (float*) data; /* we assume correct alignment */
1286  *value = ptr[offset];
1287  break;
1288  }
1289  case PT_64BF: {
1290  double *ptr = (double*) data; /* we assume correct alignment */
1291  *value = ptr[offset];
1292  break;
1293  }
1294  default: {
1295  rterror("rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1296  return ES_ERROR;
1297  }
1298  }
1299 
1300  /* set NODATA flag */
1301  if (band->hasnodata && nodata != NULL) {
1303  *nodata = 1;
1304  }
1305 
1306  return ES_NONE;
1307 }
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
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
double nodataval
Definition: librtcore.h:2301
uint16_t width
Definition: librtcore.h:2296
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 isnodata
Definition: librtcore.h:2299
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
int32_t hasnodata
Definition: librtcore.h:2298
int value
Definition: genraster.py:61
unsigned char uint8_t
Definition: uthash.h:79
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:396
Here is the call graph for this function:
Here is the caller graph for this function: