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 1221 of file rt_band.c.
1226 {
1228 uint8_t*
data = NULL;
1229 uint32_t offset = 0;
1230
1231 assert(NULL != band);
1232 assert(NULL != value);
1233
1234
1235 if (nodata != NULL)
1236 *nodata = 0;
1237
1238 if (
1239 x < 0 || x >=
band->width ||
1240 y < 0 || y >=
band->height
1241 ) {
1242 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1244 }
1245
1246
1247 if (
band->isnodata) {
1248 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1250 if (nodata != NULL) *nodata = 1;
1252 }
1253
1255 if (data == NULL) {
1256 rterror(
"rt_band_get_pixel: Cannot get band data");
1258 }
1259
1260
1261 offset =
x + (
y *
band->width);
1262
1263 pixtype =
band->pixtype;
1264
1265 switch (pixtype) {
1267#ifdef OPTIMIZE_SPACE
1268 {
1269 int byteOffset = offset / 8;
1270 int bitOffset = offset % 8;
1272
1273
1274 *
value = getBits(data, val, 1, bitOffset);
1275 break;
1276 }
1277#endif
1279#ifdef OPTIMIZE_SPACE
1280 {
1281 int byteOffset = offset / 4;
1282 int bitOffset = offset % 4;
1284
1285
1286 *
value = getBits(data, val, 2, bitOffset);
1287 break;
1288 }
1289#endif
1291#ifdef OPTIMIZE_SPACE
1292 {
1293 int byteOffset = offset / 2;
1294 int bitOffset = offset % 2;
1296
1297
1298 *
value = getBits(data, val, 2, bitOffset);
1299 break;
1300 }
1301#endif
1303 int8_t val = (int8_t)data[offset];
1305 break;
1306 }
1308 uint8_t val =
data[offset];
1310 break;
1311 }
1313 int16_t *ptr = (int16_t*) data;
1314 *
value = ptr[offset];
1315 break;
1316 }
1318 uint16_t *ptr = (uint16_t*) data;
1319 *
value = ptr[offset];
1320 break;
1321 }
1323 int32_t *ptr = (int32_t*) data;
1324 *
value = ptr[offset];
1325 break;
1326 }
1328 uint32_t *ptr = (uint32_t*) data;
1329 *
value = ptr[offset];
1330 break;
1331 }
1333 float *ptr = (float*) data;
1334 *
value = ptr[offset];
1335 break;
1336 }
1338 double *ptr = (double*) data;
1339 *
value = ptr[offset];
1340 break;
1341 }
1342 default: {
1343 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1345 }
1346 }
1347
1348
1349 if (
band->hasnodata && nodata != NULL) {
1351 *nodata = 1;
1352 }
1353
1355}
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
void rtwarn(const char *fmt,...)
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
References ES_ERROR, ES_NONE, 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(), and rtwarn().
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().