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 1520 of file rt_mapalgebra.c.
References _rti_colormap_arg_destroy(), _rti_colormap_arg_init(), _rti_iterator_arg_t::arg, _rti_iterator_arg_t::band, _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().
1531 assert(colormap != NULL);
1538 if (colormap->
nentry < 1) {
1539 rterror(
"rt_raster_colormap: colormap must have at least one entry");
1545 rterror(
"rt_raster_colormap: raster has no band at index %d",
nband);
1551 rterror(
"rt_raster_colormap: Could not get band at index %d",
nband);
1558 rterror(
"rt_raster_colormap: Could not initialize internal variables");
1569 if (colormap->
ncolor < 1) {
1570 rterror(
"rt_raster_colormap: At least one color must be provided");
1574 else if (colormap->
ncolor > 4) {
1575 rtinfo(
"More than four colors indicated. Using only the first four colors");
1582 if (arg->
pos == NULL) {
1583 rterror(
"rt_raster_colormap: Could not allocate memory for valid entries");
1587 for (i = 0, j = 0; i < colormap->
nentry; i++) {
1594 rtwarn(
"More than one colormap entry found for NODATA value. Only using first NOTDATA entry");
1604 if (colormap->
method == CM_INTERPOLATE && arg->
npos < 2) {
1605 rtwarn(
"Method INTERPOLATE requires at least two non-NODATA colormap entries. Using NEAREST instead");
1606 colormap->
method = CM_NEAREST;
1611 rtinfo(
"Band at index %d has no NODATA value. Ignoring NODATA entry",
nband);
1619 if (colormap->
method == CM_INTERPOLATE)
1622 else if (colormap->
method == CM_EXACT)
1629 if (arg->
expr == NULL) {
1630 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expressions");
1637 for (i = 0; i < arg->
nexpr; i++) {
1639 if (arg->
expr[i] == NULL) {
1640 rterror(
"rt_raster_colormap: Could not allocate memory for reclass expression");
1648 for (i = 0; i < colormap->
ncolor; i++) {
1668 RASTER_DEBUGF(4,
"NODATA expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1677 RASTER_DEBUGF(4,
"NODATA expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1691 for (j = 0; j < arg->
npos; j++) {
1692 if (colormap->
method == CM_INTERPOLATE) {
1693 if (j == arg->
npos - 1)
1713 else if (colormap->
method == CM_NEAREST) {
1716 if (j != arg->
npos - 1) {
1749 else if (colormap->
method == CM_EXACT) {
1767 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1777 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1791 if (colormap->
method == CM_EXACT) {
1808 RASTER_DEBUGF(4,
"expr[%d]->src (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1818 RASTER_DEBUGF(4,
"expr[%d]->dst (min, max, in, ix, en, ex) = (%f, %f, %d, %d, %d, %d)",
1833 if (arg->
band == NULL) {
1834 rterror(
"rt_raster_colormap: Could not reclassify band");
1841 rterror(
"rt_raster_colormap: Could not add reclassified band to output raster");
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.
int rt_raster_get_num_bands(rt_raster raster)
static _rti_colormap_arg _rti_colormap_arg_init(rt_raster raster)
struct rt_reclassexpr_t::rt_reclassrange dst
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
static void _rti_colormap_arg_destroy(_rti_colormap_arg arg)
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
struct rt_reclassexpr_t::rt_reclassrange src
void rtwarn(const char *fmt,...)
enum rt_colormap_t::@7 method
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
void rtinfo(const char *fmt,...)
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.
#define RASTER_DEBUGF(level, msg,...)
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
rt_colormap_entry nodataentry