Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified band of the input raster.
- Parameters
-
| raster | input raster |
| nband | 0-based index of the band to process with colormap |
| colormap | rt_colormap object of colormap to apply to band |
- Returns
- new raster or NULL on error
Definition at line 1523 of file rt_mapalgebra.c.
1526 {
1530 int i = 0;
1531 int j = 0;
1532 int k = 0;
1533
1534 assert(colormap != NULL);
1535
1536
1538 return NULL;
1539
1540
1541 if (colormap->
nentry < 1) {
1542 rterror(
"rt_raster_colormap: colormap must have at least one entry");
1543 return NULL;
1544 }
1545
1546
1548 rterror(
"rt_raster_colormap: raster has no band at index %d", nband);
1549 return NULL;
1550 }
1551
1553 if (band == NULL) {
1554 rterror(
"rt_raster_colormap: Could not get band at index %d", nband);
1555 return NULL;
1556 }
1557
1558
1560 if (arg == NULL) {
1561 rterror(
"rt_raster_colormap: Could not initialize internal variables");
1562 return NULL;
1563 }
1564
1565
1569 }
1570
1571
1572 if (colormap->
ncolor < 1) {
1573 rterror(
"rt_raster_colormap: At least one color must be provided");
1575 return NULL;
1576 }
1577 else if (colormap->
ncolor > 4) {
1578 rtinfo(
"More than four colors indicated. Using only the first four colors");
1580 }
1581
1582
1585 if (arg->
pos == NULL) {
1586 rterror(
"rt_raster_colormap: Could not allocate memory for valid entries");
1588 return NULL;
1589 }
1590 for (i = 0, j = 0; i < colormap->
nentry; i++) {
1591
1593
1596 else
1597 rtwarn(
"More than one colormap entry found for NODATA value. Only using first NOTDATA entry");
1598
1599 continue;
1600 }
1601
1604 }
1605
1606
1607 if (colormap->
method == CM_INTERPOLATE && arg->
npos < 2) {
1608 rtwarn(
"Method INTERPOLATE requires at least two non-NODATA colormap entries. Using NEAREST instead");
1609 colormap->
method = CM_NEAREST;
1610 }
1611
1612
1614 rtinfo(
"Band at index %d has no NODATA value. Ignoring NODATA entry", nband);
1616 }
1617
1618
1620
1621
1622 if (colormap->
method == CM_INTERPOLATE)
1624
1625 else if (colormap->
method == CM_EXACT)
1627
1628
1632 if (arg->
expr == NULL) {
1633 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expressions");
1635 return NULL;
1636 }
1639
1640 for (i = 0; i < arg->
nexpr; i++) {
1642 if (arg->
expr[i] == NULL) {
1643 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expression");
1645 return NULL;
1646 }
1647 }
1648
1649
1650
1651 for (i = 0; i < colormap->
ncolor; i++) {
1652 k = 0;
1653
1654
1662
1665
1670
1671 RASTER_DEBUGF(4,
"NODATA expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1672 k,
1679 );
1680 RASTER_DEBUGF(4,
"NODATA expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1681 k,
1688 );
1689
1690 k++;
1691 }
1692
1693
1694 for (j = 0; j < arg->
npos; j++) {
1695 if (colormap->
method == CM_INTERPOLATE) {
1696 if (j == arg->
npos - 1)
1697 continue;
1698
1702
1706
1709
1712
1715 }
1716 else if (colormap->
method == CM_NEAREST) {
1717
1718
1719 if (j != arg->
npos - 1) {
1723 }
1724
1725 else {
1729 }
1730
1731
1732 if (j > 0) {
1736 }
1737
1738 else {
1742 }
1743
1747
1751 }
1752 else if (colormap->
method == CM_EXACT) {
1756
1760
1764
1768 }
1769
1770 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1771 k,
1778 );
1779
1780 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1781 k,
1788 );
1789
1790 k++;
1791 }
1792
1793
1794 if (colormap->
method == CM_EXACT) {
1798
1802
1806
1810
1811 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1812 k,
1819 );
1820
1821 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1822 k,
1829 );
1830
1831 k++;
1832 }
1833
1834
1836 if (arg->
band == NULL) {
1837 rterror(
"rt_raster_colormap: Could not reclassify band");
1839 return NULL;
1840 }
1841
1842
1844 rterror(
"rt_raster_colormap: Could not add reclassified band to output raster");
1846 return NULL;
1847 }
1848 }
1849
1853
1854 return rtnraster;
1855}
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
void rtinfo(const char *fmt,...)
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
void rtwarn(const char *fmt,...)
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, rt_reclassexpr *exprset, int exprcount)
Returns new band with values reclassified.
static void _rti_colormap_arg_destroy(_rti_colormap_arg arg)
static _rti_colormap_arg _rti_colormap_arg_init(rt_raster raster)
rt_colormap_entry nodataentry
enum rt_colormap_t::@9 method
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst
References _rti_colormap_arg_destroy(), _rti_colormap_arg_init(), _rti_colormap_arg_t::band, rt_colormap_entry_t::color, rt_reclassexpr_t::dst, rt_colormap_t::entry, rt_reclassexpr_t::rt_reclassrange::exc_max, rt_reclassexpr_t::rt_reclassrange::exc_min, _rti_colormap_arg_t::expr, _rti_colormap_arg_t::hasnodata, rt_reclassexpr_t::rt_reclassrange::inc_max, rt_reclassexpr_t::rt_reclassrange::inc_min, rt_colormap_entry_t::isnodata, rt_reclassexpr_t::rt_reclassrange::max, rt_colormap_t::method, rt_reclassexpr_t::rt_reclassrange::min, rt_colormap_t::ncolor, rt_colormap_t::nentry, _rti_colormap_arg_t::nexpr, _rti_colormap_arg_t::nodataentry, _rti_colormap_arg_t::nodataval, _rti_colormap_arg_t::npos, _rti_colormap_arg_t::pos, PT_8BUI, _rti_colormap_arg_t::raster, RASTER_DEBUGF, rt_band_get_hasnodata_flag(), rt_band_get_nodata(), rt_band_reclass(), rt_raster_add_band(), rt_raster_get_band(), rt_raster_get_num_bands(), rt_raster_has_band(), rt_raster_is_empty(), rtalloc(), rterror(), rtinfo(), rtwarn(), rt_reclassexpr_t::src, and rt_colormap_entry_t::value.
Referenced by RASTER_colorMap(), and test_raster_colormap().