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 1551 of file rt_band.c.
1556 {
1558 uint8_t*
data = NULL;
1559 uint32_t offset = 0;
1560
1561 assert(NULL != band);
1562 assert(NULL != value);
1563
1564
1565 if (nodata != NULL)
1566 *nodata = 0;
1567
1568 if (
1569 x < 0 || x >=
band->width ||
1570 y < 0 || y >=
band->height
1571 ) {
1572 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1574 }
1575
1576
1577 if (
band->isnodata) {
1578 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1580 if (nodata != NULL) *nodata = 1;
1582 }
1583
1585 if (data == NULL) {
1586 rterror(
"rt_band_get_pixel: Cannot get band data");
1588 }
1589
1590
1591 offset =
x + (
y *
band->width);
1592
1593 pixtype =
band->pixtype;
1594
1595 switch (pixtype) {
1597#ifdef OPTIMIZE_SPACE
1598 {
1599 int byteOffset = offset / 8;
1600 int bitOffset = offset % 8;
1602
1603
1604 *
value = getBits(data, val, 1, bitOffset);
1605 break;
1606 }
1607#endif
1609#ifdef OPTIMIZE_SPACE
1610 {
1611 int byteOffset = offset / 4;
1612 int bitOffset = offset % 4;
1614
1615
1616 *
value = getBits(data, val, 2, bitOffset);
1617 break;
1618 }
1619#endif
1621#ifdef OPTIMIZE_SPACE
1622 {
1623 int byteOffset = offset / 2;
1624 int bitOffset = offset % 2;
1626
1627
1628 *
value = getBits(data, val, 2, bitOffset);
1629 break;
1630 }
1631#endif
1633 int8_t val = (int8_t)data[offset];
1635 break;
1636 }
1638 uint8_t val =
data[offset];
1640 break;
1641 }
1643 int16_t *ptr = (int16_t*) data;
1644 *
value = ptr[offset];
1645 break;
1646 }
1648 uint16_t *ptr = (uint16_t*) data;
1649 *
value = ptr[offset];
1650 break;
1651 }
1653 int32_t *ptr = (int32_t*) data;
1654 *
value = ptr[offset];
1655 break;
1656 }
1658 uint32_t *ptr = (uint32_t *)data;
1659 *
value = ptr[offset];
1660 break;
1661 }
1663 uint16_t *ptr = (uint16_t *)data;
1665 break;
1666 }
1668 float *ptr = (float *)data;
1669 *
value = ptr[offset];
1670 break;
1671 }
1673 double *ptr = (double*) data;
1674 *
value = ptr[offset];
1675 break;
1676 }
1677 default: {
1678 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1680 }
1681 }
1682
1683
1684 if (
band->hasnodata && nodata != NULL) {
1686 *nodata = 1;
1687 }
1688
1690}
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
float rt_util_float16_to_float(uint16_t value)
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_16BF, 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(), rt_util_float16_to_float(), 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().