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 1527 of file rt_band.c.
1532 {
1534 uint8_t*
data = NULL;
1535 uint32_t offset = 0;
1536
1537 assert(NULL != band);
1538 assert(NULL != value);
1539
1540
1541 if (nodata != NULL)
1542 *nodata = 0;
1543
1544 if (
1545 x < 0 || x >=
band->width ||
1546 y < 0 || y >=
band->height
1547 ) {
1548 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1550 }
1551
1552
1553 if (
band->isnodata) {
1554 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1556 if (nodata != NULL) *nodata = 1;
1558 }
1559
1561 if (data == NULL) {
1562 rterror(
"rt_band_get_pixel: Cannot get band data");
1564 }
1565
1566
1567 offset =
x + (
y *
band->width);
1568
1569 pixtype =
band->pixtype;
1570
1571 switch (pixtype) {
1573#ifdef OPTIMIZE_SPACE
1574 {
1575 int byteOffset = offset / 8;
1576 int bitOffset = offset % 8;
1578
1579
1580 *
value = getBits(data, val, 1, bitOffset);
1581 break;
1582 }
1583#endif
1585#ifdef OPTIMIZE_SPACE
1586 {
1587 int byteOffset = offset / 4;
1588 int bitOffset = offset % 4;
1590
1591
1592 *
value = getBits(data, val, 2, bitOffset);
1593 break;
1594 }
1595#endif
1597#ifdef OPTIMIZE_SPACE
1598 {
1599 int byteOffset = offset / 2;
1600 int bitOffset = offset % 2;
1602
1603
1604 *
value = getBits(data, val, 2, bitOffset);
1605 break;
1606 }
1607#endif
1609 int8_t val = (int8_t)data[offset];
1611 break;
1612 }
1614 uint8_t val =
data[offset];
1616 break;
1617 }
1619 int16_t *ptr = (int16_t*) data;
1620 *
value = ptr[offset];
1621 break;
1622 }
1624 uint16_t *ptr = (uint16_t*) data;
1625 *
value = ptr[offset];
1626 break;
1627 }
1629 int32_t *ptr = (int32_t*) data;
1630 *
value = ptr[offset];
1631 break;
1632 }
1634 uint32_t *ptr = (uint32_t*) data;
1635 *
value = ptr[offset];
1636 break;
1637 }
1639 float *ptr = (float*) data;
1640 *
value = ptr[offset];
1641 break;
1642 }
1644 double *ptr = (double*) data;
1645 *
value = ptr[offset];
1646 break;
1647 }
1648 default: {
1649 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1651 }
1652 }
1653
1654
1655 if (
band->hasnodata && nodata != NULL) {
1657 *nodata = 1;
1658 }
1659
1661}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
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_clip(), RASTER_dumpValues(), RASTER_getPixelCentroids(), 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_bilinear(), rt_band_get_pixel_of_value(), rt_band_get_pixel_resample(), rt_band_get_quantiles_stream(), rt_band_get_summary_stats(), rt_band_get_value_count(), rt_band_reclass(), rt_band_reclass_exact(), 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().