GDAL
gdal::Reclassifier Class Reference

Class to manage reclassification of pixel values. More...

#include <vrtreclassifier.h>

Classes

struct  Interval
 Internal struct to hold an interval of values to be reclassified. More...

Public Member Functions

CPLErr Init (const char *pszText, std::optional< double > noDataValue, GDALDataType eBufType)
 Initialize a Reclassifier from text.
void AddMapping (const Interval &interval, std::optional< double > dfDstVal)
 Set a mapping between an interval and (optionally) a destination value.
double Reclassify (double srcVal, bool &bFoundInterval) const
 Reclassify a value.
void SetDefaultPassThrough (bool value)
 If true, values not matched by any interval will be returned unmodified.
void SetDefaultValue (double value)
 Sets a default value for any value not matched by any interval.
void SetNaNValue (double value)
 Sets a value for an input NaN value.
CPLErr Finalize ()
 Prepare reclassifier for use.

Static Public Attributes

static constexpr char MAPPING_INTERVAL_SEP_CHAR = ';'
 Character separating elements in a list of mapping.
static constexpr char MAPPING_FROMTO_SEP_CHAR = '='
 Character separating source interval from target value.

Detailed Description

Class to manage reclassification of pixel values.

Member Function Documentation

◆ AddMapping()

void gdal::Reclassifier::AddMapping ( const Interval & interval,
std::optional< double > dfDstVal )

Set a mapping between an interval and (optionally) a destination value.

If no destination value is provided, values matching the interval will be passed through unmodified. It will not be verified that these values fit within the destination data type.

◆ Finalize()

CPLErr gdal::Reclassifier::Finalize ( )

Prepare reclassifier for use.

No more mappings may be added.

◆ Init()

CPLErr gdal::Reclassifier::Init ( const char * pszText,
std::optional< double > noDataValue,
GDALDataType eBufType )

Initialize a Reclassifier from text.

The text consists of a series of SOURCE=DEST mappings, separated by a semicolon.

Each SOURCE element much be one of:

  • a constant value
  • a range of values, such as (3, 4] or [7, inf]
  • the value NO_DATA, for which the provided NoData value will be substituted
  • the value DEFAULT, to define a DEST for any value that does not match another SOURCE mapping

Each DEST element must be one of:

  • a constant value
  • the value NO_DATA, for which the provided NoData value will be substituted

An error will be returned if:

  • NO_DATA is used by a NoData value is not defined.
  • a DEST value does not fit into the destination data type
Parameters
pszTexttext to parse
noDataValueNoData value
eBufTypeDestination data type
Returns
CE_None if no errors occurred, CE_Failure otherwise

◆ Reclassify()

double gdal::Reclassifier::Reclassify ( double srcVal,
bool & bFoundInterval ) const

Reclassify a value.

Parameters
srcValthe value to reclassify
bFoundIntervalset to True if the value could be reclassified
Returns
the reclassified value

◆ SetDefaultPassThrough()

void gdal::Reclassifier::SetDefaultPassThrough ( bool value)
inline

If true, values not matched by any interval will be returned unmodified.

It will not be verified that these values fit within the destination data type.


The documentation for this class was generated from the following files: