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 1534 of file rt_mapalgebra.c.
1537 {
1541 int i = 0;
1542 int j = 0;
1543 int k = 0;
1544
1545 assert(colormap != NULL);
1546
1547
1549 return NULL;
1550
1551
1552 if (colormap->
nentry < 1) {
1553 rterror(
"rt_raster_colormap: colormap must have at least one entry");
1554 return NULL;
1555 }
1556
1557
1559 rterror(
"rt_raster_colormap: raster has no band at index %d", nband);
1560 return NULL;
1561 }
1562
1564 if (band == NULL) {
1565 rterror(
"rt_raster_colormap: Could not get band at index %d", nband);
1566 return NULL;
1567 }
1568
1569
1571 if (arg == NULL) {
1572 rterror(
"rt_raster_colormap: Could not initialize internal variables");
1573 return NULL;
1574 }
1575
1576
1580 }
1581
1582
1583 if (colormap->
ncolor < 1) {
1584 rterror(
"rt_raster_colormap: At least one color must be provided");
1586 return NULL;
1587 }
1588 else if (colormap->
ncolor > 4) {
1589 rtinfo(
"More than four colors indicated. Using only the first four colors");
1591 }
1592
1593
1596 if (arg->
pos == NULL) {
1597 rterror(
"rt_raster_colormap: Could not allocate memory for valid entries");
1599 return NULL;
1600 }
1601 for (i = 0, j = 0; i < colormap->
nentry; i++) {
1602
1604
1607 else
1608 rtwarn(
"More than one colormap entry found for NODATA value. Only using first NOTDATA entry");
1609
1610 continue;
1611 }
1612
1615 }
1616
1617
1618 if (colormap->
method == CM_INTERPOLATE && arg->
npos < 2) {
1619 rtwarn(
"Method INTERPOLATE requires at least two non-NODATA colormap entries. Using NEAREST instead");
1620 colormap->
method = CM_NEAREST;
1621 }
1622
1623
1625 rtinfo(
"Band at index %d has no NODATA value. Ignoring NODATA entry", nband);
1627 }
1628
1629
1631
1632
1633 if (colormap->
method == CM_INTERPOLATE)
1635
1636 else if (colormap->
method == CM_EXACT)
1638
1639
1643 if (arg->
expr == NULL) {
1644 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expressions");
1646 return NULL;
1647 }
1650
1651 for (i = 0; i < arg->
nexpr; i++) {
1653 if (arg->
expr[i] == NULL) {
1654 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expression");
1656 return NULL;
1657 }
1658 }
1659
1660
1661
1662 for (i = 0; i < colormap->
ncolor; i++) {
1663 k = 0;
1664
1665
1673
1676
1681
1682 RASTER_DEBUGF(4,
"NODATA expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1683 k,
1690 );
1691 RASTER_DEBUGF(4,
"NODATA expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1692 k,
1699 );
1700
1701 k++;
1702 }
1703
1704
1705 for (j = 0; j < arg->
npos; j++) {
1706 if (colormap->
method == CM_INTERPOLATE) {
1707 if (j == arg->
npos - 1)
1708 continue;
1709
1713
1717
1720
1723
1726 }
1727 else if (colormap->
method == CM_NEAREST) {
1728
1729
1730 if (j != arg->
npos - 1) {
1734 }
1735
1736 else {
1740 }
1741
1742
1743 if (j > 0) {
1747 }
1748
1749 else {
1753 }
1754
1758
1762 }
1763 else if (colormap->
method == CM_EXACT) {
1767
1771
1775
1779 }
1780
1781 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1782 k,
1789 );
1790
1791 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1792 k,
1799 );
1800
1801 k++;
1802 }
1803
1804
1805 if (colormap->
method == CM_EXACT) {
1809
1813
1817
1821
1822 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1823 k,
1830 );
1831
1832 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1833 k,
1840 );
1841
1842 k++;
1843 }
1844
1845
1847 if (arg->
band == NULL) {
1848 rterror(
"rt_raster_colormap: Could not reclassify band");
1850 return NULL;
1851 }
1852
1853
1855 rterror(
"rt_raster_colormap: Could not add reclassified band to output raster");
1857 return NULL;
1858 }
1859 }
1860
1864
1865 return rtnraster;
1866}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
void void rtinfo(const char *fmt,...) __attribute__((format(printf
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
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.
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::@13 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().