ccgl::data_raster::clsRasterData< T, MASK_T > Class Template Reference

Raster data (1D and 2D) I/O class Support I/O among ASCII file, TIFF, and MongoDB database. More...

#include <data_raster.hpp>

Public Member Functions

 clsRasterData (bool is_2d=false)
 Constructor an empty clsRasterData instance for 1D or 2D raster.
 
 clsRasterData (T *data, int cols, int rows, T nodata, double dx, double xll, double yll, const STRING_MAP &opts=STRING_MAP())
 Constructor 1D raster from necessary data.
 
 clsRasterData (T *data, int cols, int rows, T nodata, double dx, double xll, double yll, const string &srs)
 Constructor 1D raster from necessary data. More...
 
 clsRasterData (T **data2d, int cols, int rows, int nlayers, T nodata, double dx, double xll, double yll, const STRING_MAP &opts=STRING_MAP())
 Constructor 2D raster from necessary data.
 
 clsRasterData (T **data2d, int cols, int rows, int nlayers, T nodata, double dx, double xll, double yll, const string &srs)
 Constructor 2D raster from necessary data. More...
 
 clsRasterData (const string &filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Constructor of clsRasterData instance from TIFF, ASCII, or other GDAL supported format, which has one data layer, referred to as Raster1D. More...
 
 clsRasterData (vector< string > &filenames, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Constructor of clsRasterData instance from TIFF, ASCII, or other GDAL supported raster file, which may have one or more data layers, i.e., compatible with Raster1D and Rater2D. More...
 
 clsRasterData (clsRasterData< MASK_T > *mask, T *values, int len, const STRING_MAP &opts=STRING_MAP())
 Construct an clsRasterData instance by 1D array data and mask.
 
 clsRasterData (clsRasterData< MASK_T > *mask, T **values, int len, int lyrs, const STRING_MAP &opts=STRING_MAP())
 Construct an clsRasterData instance by 2D array data and mask.
 
 clsRasterData (MongoGridFs *gfs, const char *remote_filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Constructor based on mongoDB. More...
 
 clsRasterData (clsRasterData< T, MASK_T > *another)
 Copy constructor. More...
 
 ~clsRasterData ()
 Destructor.
 
bool ReadFromFile (const string &filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Read raster data from file, mask data is optional. More...
 
bool ReadFromFiles (vector< string > &filenames, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Read raster data from two or more files, mask data is optional. More...
 
bool ReadFromMongoDB (MongoGridFs *gfs, const string &filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Read raster data from MongoDB. More...
 
bool OutputToFile (const string &filename, bool out_origin=true)
 Write the whole raster to raster file, if 2D raster, output name will be corename_LyrNum. More...
 
bool OutputSubsetToFile (bool out_origin=false, bool out_combined=true, const string &outname=string(), const map< vint, vector< double > > &recls=map< vint, vector< double > >(), double default_value=NODATA_VALUE)
 Write one or more raster's subset to files, default name format: corename_SubID_LyrNum. More...
 
bool OutputAscFile (const string &filename)
 Write 1D or 2D raster data into ASC file(s)
 
bool OutputFileByGdal (const string &filename)
 Write 1D or 2D raster data into TIFF file by GDAL.
 
bool OutputToMongoDB (MongoGridFs *gfs, const string &filename=string(), const STRING_MAP &opts=STRING_MAP(), bool include_nodata=true, bool out_origin=true)
 Write the whole raster data to MongoDB, name format: corename__LyrNum. More...
 
bool OutputSubsetToMongoDB (MongoGridFs *gfs, const string &filename=string(), const STRING_MAP &opts=STRING_MAP(), bool include_nodata=true, bool out_origin=false, bool out_combined=true, const map< vint, vector< double > > &recls=map< vint, vector< double > >(), double default_value=NODATA_VALUE)
 Write one or more raster's subset to MongoDB,. More...
 
void SetHeader (const STRDBL_MAP &refers)
 
void SetCoreName (const string &name)
 Set new core file name.
 
void SetValue (int row, int col, T value, int lyr=1)
 Set value to the given position and layer.
 
bool SetCalcPositions ()
 Set the flag of calc_pos_ to true and recalculate positions and stored raster data if necessary.
 
bool SetPositions (int len, int **pdata)
 Set valid positions data, without mask raster layer.
 
bool SetPositions (int len, int *pdata)
 
bool SetUseMaskExt ()
 Set the flag of use_mask_ext_ to true and recalculate positions and stored raster data if necessary.
 
void SetDataType (RasterDataType const type)
 Set raster data type.
 
void SetDataType (const string &strtype)
 Set raster data type.
 
void SetOutDataType (RasterDataType type)
 Set output raster data type.
 
void SetOutDataType (const string &strtype)
 Set output raster data type.
 
void SetDefaultValue (const double defaultv)
 Set default value.
 
bool BuildSubSet (map< int, int > groups=map< int, int >())
 Build subsets by given groups (cell value->group ID) or by discrete values (default)
 
bool ReleaseSubset ()
 Release subsets.
 
bool RebuildSubSet (map< int, int > groups=map< int, int >())
 Re-build subsets by given groups (cell value->group ID) or by discrete values.
 
void CalculateStatistics ()
 Calculate basic statistics values in one time Mean, Max, Min, STD, Range, etc.
 
void UpdateStatistics ()
 Force to update basic statistics values Mean, Max, Min, STD, Range, etc.
 
void ReleaseStatsMap2D ()
 Release statistics map of 2D raster data.
 
double GetStatistics (string sindex, int lyr=1)
 Get basic statistics value Mean, Max, Min, STD, Range, etc. More...
 
void GetStatistics (string sindex, int *lyrnum, double **values)
 Get basic statistics values for 2D raster data. More...
 
double GetAverage (const int lyr=1)
 Get the average of raster data. More...
 
double GetMaximum (const int lyr=1)
 Get the maximum of raster data. More...
 
double GetMinimum (const int lyr=1)
 Get the minimum of raster data. More...
 
double GetStd (const int lyr=1)
 Get the stand derivation of raster data. More...
 
double GetRange (const int lyr=1)
 Get the range of raster data. More...
 
void GetAverage (int *lyrnum, double **values)
 Get the average of 2D raster data. More...
 
void GetMaximum (int *lyrnum, double **values)
 Get the maximum of 2D raster data. More...
 
void GetMinimum (int *lyrnum, double **values)
 Get the minimum of 2D raster data. More...
 
void GetStd (int *lyrnum, double **values)
 Get the standard derivation of 2D raster data. More...
 
void GetRange (int *lyrnum, double **values)
 Get the range of 2D raster data. More...
 
void GetValidNumber (int *lyrnum, double **values)
 Get the non-NoDATA number of 2D raster data. More...
 
int GetValidNumber (const int lyr=1)
 Get the non-NoDATA cells number of the given raster layer data. More...
 
int GetCellNumber () const
 
int GetDataLength () const
 Get the first dimension size. More...
 
int GetCols () const
 
int GetRows () const
 Get column number.
 
double GetCellWidth () const
 Get row number.
 
double GetXllCenter () const
 Get cell size. More...
 
double GetYllCenter () const
 Get Y coordinate of left lower center of raster data.
 
int GetLayers () const
 
RasterDataType GetDataType () const
 Get layer number.
 
RasterDataType GetOutDataType () const
 Get data type of source.
 
GetNoDataValue () const
 Get data type of output.
 
double GetDefaultValue () const
 Get NoDATA value.
 
int GetPosition (int row, int col)
 Get default value. More...
 
int GetPosition (float x, float y)
 Get position index in 1D raster data for given coordinate (x,y)
 
int GetPosition (double x, double y)
 Get position index in 1D raster data for given coordinate (x,y)
 
map< int, SubsetPositions * > & GetSubset ()
 Get subset.
 
bool GetRasterData (int *n_cells, T **data)
 Get raster data, include valid cell number and data. More...
 
bool Get2DRasterData (int *n_cells, int *n_lyrs, T ***data)
 Get 2D raster data, include valid cell number of each layer, layer number, and data. More...
 
const STRDBL_MAPGetRasterHeader () const
 Get raster header information.
 
const STRDBL_MAPGetStatistics () const
 Get raster statistics information.
 
const map< string, double * > & GetStatistics2D () const
 Get raster statistics information of 2D raster.
 
string GetFilePath () const
 Get full path name.
 
string GetCoreName () const
 Get core name.
 
void GetRasterPositionData (int *datalength, int ***positiondata)
 Get position index data and the data length. More...
 
void GetRasterPositionData (int *datalength, int **positiondata)
 
T * GetRasterDataPointer () const
 
int ** GetRasterPositionDataPointer () const
 Get pointer of raster 1D data.
 
int * GetRasterPositionIndexPointer () const
 Get pointer of position data.
 
T ** Get2DRasterDataPointer () const
 Get pointer of position data.
 
const char * GetSrs ()
 Get pointer of raster 2D data.
 
string GetSrsString ()
 Get the spatial reference (char*)
 
string GetOption (const char *key)
 Get the spatial reference (string)
 
const STRING_MAPGetOptions () const
 Get option by key, including the spatial reference by "SRS".
 
GetValueByIndex (int cell_index, int lyr=1)
 Get options. More...
 
void GetValueByIndex (int cell_index, T *&values)
 Get raster data at the valid cell index (both for 1D and 2D raster) More...
 
GetValue (int row, int col, int lyr=1)
 Get raster data via row and col The default lyr is 1, which means the 1D raster data, or the first layer of 2D data.
 
void GetValue (int row, int col, T *&values)
 Get raster data (both for 1D and 2D raster) at the (row, col) More...
 
bool IsNoData (const int row, const int col, const int lyr=1)
 Check if the raster data is NoData via row and col The default lyr is 1, which means the 1D raster data, or the first layer of 2D data.
 
bool Is2DRaster () const
 
bool PositionsCalculated () const
 Is 2D raster data?
 
bool PositionsAllocated () const
 Calculate positions or not.
 
bool MaskExtented () const
 position data is allocated or a pointer
 
bool StatisticsCalculated () const
 Use mask extent or not.
 
bool Initialized () const
 Basic statistics calculated?
 
bool ValidateRasterData ()
 Instance of clsRasterData initialized? More...
 
bool ValidateRowCol (const int row, const int col)
 Validate the input row and col.
 
bool ValidateLayer (const int lyr)
 Validate the input layer number.
 
bool ValidateIndex (const int idx)
 Validate the input index.
 
string GetFullFileName () const
 Get full filename.
 
clsRasterData< MASK_T > * GetMask () const
 Get mask data pointer.
 
void Copy (clsRasterData< T, MASK_T > *orgraster)
 Copy clsRasterData object.
 
void ReplaceNoData (T replacedv)
 Replace NoData value by the given value.
 
void Reclassify (map< int, T > reclass_map)
 classify raster
 
XY_COOR GetCoordinateByRowCol (int row, int col)
 Calculate XY coordinates by given row and col number. More...
 
ROW_COL GetPositionByCoordinate (double x, double y, STRDBL_MAP *header=nullptr)
 Calculate position by given coordinate. More...
 

Static Public Member Functions

static clsRasterData< T, MASK_T > * Init (const string &filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Validation check before the construction of clsRasterData, i.e., the raster file is existed and the data format supported. More...
 
static clsRasterData< T, MASK_T > * Init (vector< string > &filenames, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Validation check before the constructor of clsRasterData, i.e., the raster files are all existed and the data format supported. More...
 
static clsRasterData< T, MASK_T > * Init (MongoGridFs *gfs, const char *remote_filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
 Validation check before the constructor of clsRasterData.
 

Detailed Description

template<typename T, typename MASK_T = T>
class ccgl::data_raster::clsRasterData< T, MASK_T >

Raster data (1D and 2D) I/O class Support I/O among ASCII file, TIFF, and MongoDB database.

Constructor & Destructor Documentation

◆ clsRasterData() [1/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( T *  data,
int  cols,
int  rows,
nodata,
double  dx,
double  xll,
double  yll,
const string &  srs 
)

Constructor 1D raster from necessary data.

Deprecated:
The input parameter srs is highly recommended replaced by map<string, string>.

◆ clsRasterData() [2/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( T **  data2d,
int  cols,
int  rows,
int  nlayers,
nodata,
double  dx,
double  xll,
double  yll,
const string &  srs 
)

Constructor 2D raster from necessary data.

Deprecated:
The input parameter srs is highly recommended replaced by map<string, string>.

◆ clsRasterData() [3/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( const string &  filename,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)
explicit

Constructor of clsRasterData instance from TIFF, ASCII, or other GDAL supported format, which has one data layer, referred to as Raster1D.

Parameters
[in]filenameFull path of the raster file
[in]calc_posCalculate positions of valid cells excluding NODATA. The default is false.
[in]maskclsRasterData<MASK_T> Mask layer
[in]use_mask_extUse mask layer extent, even NoDATA exists.
[in]default_valueDefault value when mask data exceeds the raster extend.
[in]opts(Optional) Additional options of the raster data with the format of key-value

◆ clsRasterData() [4/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( vector< string > &  filenames,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)
explicit

Constructor of clsRasterData instance from TIFF, ASCII, or other GDAL supported raster file, which may have one or more data layers, i.e., compatible with Raster1D and Rater2D.

Parameters
[in]filenamesFull paths vector of the 2D raster data
[in]calc_posCalculate positions of valid cells excluding NODATA. The default is false.
[in]maskclsRasterData<MASK_T> Mask layer
[in]use_mask_extUse mask layer extent, even NoDATA exists.
[in]default_valueDefault value when mask data exceeds the raster extend.
[in]opts(Optional) Additional options of the raster data with the format of key-value

◆ clsRasterData() [5/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( MongoGridFs gfs,
const char *  remote_filename,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)

Constructor based on mongoDB.

See also
ReadFromMongoDB()
Parameters
[in]gfsmongoc_gridfs_t
[in]remote_filenamechar*
[in]calc_posCalculate positions of valid cells excluding NODATA. The default is false.
[in]maskclsRasterData<MASK_T> Mask layer
[in]use_mask_extUse mask layer extent, even NoDATA exists.
[in]default_valueDefault value when mask data exceeds the raster extend.
[in]optsOptional key-value stored in metadata

◆ clsRasterData() [6/6]

template<typename T , typename MASK_T >
ccgl::data_raster::clsRasterData< T, MASK_T >::clsRasterData ( clsRasterData< T, MASK_T > *  another)
explicit

Copy constructor.

// Method 1:
clsRasterData<T> newraster(baseraster);
// Method 2:
clsRasterData<T> newraster;
newraster.Copy(baseraster);
// Method 3:
clsRasterData<T>* newraster = new clsRasterData<T>(baseraster);
delete newraster;

Member Function Documentation

◆ Get2DRasterData()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::Get2DRasterData ( int *  n_cells,
int *  n_lyrs,
T ***  data 
)

Get 2D raster data, include valid cell number of each layer, layer number, and data.

Returns
true if the 2D raster has been initialized, otherwise return false and print error info.

◆ GetAverage() [1/2]

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetAverage ( const int  lyr = 1)
inline

Get the average of raster data.

Parameters
[in]lyroptional for 1D and the first layer of 2D raster data.

◆ GetAverage() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetAverage ( int *  lyrnum,
double **  values 
)
inline

Get the average of 2D raster data.

Parameters
[out]lyrnumint layer number
[out]valuesdouble* Statistics array

◆ GetCoordinateByRowCol()

template<typename T , typename MASK_T >
XY_COOR ccgl::data_raster::clsRasterData< T, MASK_T >::GetCoordinateByRowCol ( int  row,
int  col 
)

Calculate XY coordinates by given row and col number.

See also
GetPositionByCoordinate
Parameters
[in]rowRow number
[in]colCol number
Returns
pair<double x, double y>

◆ GetDataLength()

template<typename T , typename MASK_T = T>
int ccgl::data_raster::clsRasterData< T, MASK_T >::GetDataLength ( ) const
inline

Get the first dimension size.

Get the actual stored length of raster data

◆ GetMaximum() [1/2]

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetMaximum ( const int  lyr = 1)
inline

Get the maximum of raster data.

See also
GetAverage

◆ GetMaximum() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetMaximum ( int *  lyrnum,
double **  values 
)
inline

Get the maximum of 2D raster data.

See also
GetAverage

◆ GetMinimum() [1/2]

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetMinimum ( const int  lyr = 1)
inline

Get the minimum of raster data.

See also
GetAverage

◆ GetMinimum() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetMinimum ( int *  lyrnum,
double **  values 
)
inline

Get the minimum of 2D raster data.

See also
GetAverage

◆ GetPosition()

template<typename T , typename MASK_T >
int ccgl::data_raster::clsRasterData< T, MASK_T >::GetPosition ( int  row,
int  col 
)

Get default value.

Get position index in 1D raster data for specific row and column

Returns
-1 — the position is nodata -2 — the position is out of the extent, which indicates an error

◆ GetPositionByCoordinate()

template<typename T , typename MASK_T >
ROW_COL ccgl::data_raster::clsRasterData< T, MASK_T >::GetPositionByCoordinate ( double  x,
double  y,
STRDBL_MAP header = nullptr 
)

Calculate position by given coordinate.

See also
GetCoordinateByRowCol
Parameters
[in]xX coordinate
[in]yY coordinate
[in]headerOptional, header map of raster layer data, the default is m_header
Returns
pair<int row, int col>

◆ GetRange() [1/2]

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetRange ( const int  lyr = 1)
inline

Get the range of raster data.

See also
GetMaximum
GetMinimum

◆ GetRange() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetRange ( int *  lyrnum,
double **  values 
)
inline

Get the range of 2D raster data.

See also
GetAverage

◆ GetRasterData()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::GetRasterData ( int *  n_cells,
T **  data 
)

Get raster data, include valid cell number and data.

Returns
true if the raster data has been initialized, otherwise return false and print error info.

◆ GetRasterPositionData()

template<typename T , typename MASK_T >
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetRasterPositionData ( int *  datalength,
int ***  positiondata 
)

Get position index data and the data length.

Parameters
[out]datalengthData length
[out]positiondataThe pointer of 2D array (pointer)

◆ GetStatistics() [1/2]

template<typename T , typename MASK_T >
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetStatistics ( string  sindex,
int *  lyrnum,
double **  values 
)

Get basic statistics values for 2D raster data.

Mean, Max, Min, STD, Range, etc.

Parameters
[in]sindexstring case insensitive
[out]lyrnumint layer number
[out]valuesdouble* Statistics array or nullptr

◆ GetStatistics() [2/2]

template<typename T , typename MASK_T >
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetStatistics ( string  sindex,
int  lyr = 1 
)

Get basic statistics value Mean, Max, Min, STD, Range, etc.

Parameters
[in]sindexstring case insensitive
[in]lyroptional for 1D and the first layer of 2D raster data.
Returns
Statistics value or NoData

◆ GetStd() [1/2]

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetStd ( const int  lyr = 1)
inline

Get the stand derivation of raster data.

See also
GetAverage

◆ GetStd() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetStd ( int *  lyrnum,
double **  values 
)
inline

Get the standard derivation of 2D raster data.

See also
GetAverage

◆ GetValidNumber() [1/2]

template<typename T , typename MASK_T = T>
int ccgl::data_raster::clsRasterData< T, MASK_T >::GetValidNumber ( const int  lyr = 1)
inline

Get the non-NoDATA cells number of the given raster layer data.

See also
GetCellNumber
GetDataLength

◆ GetValidNumber() [2/2]

template<typename T , typename MASK_T = T>
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetValidNumber ( int *  lyrnum,
double **  values 
)
inline

Get the non-NoDATA number of 2D raster data.

See also
GetAverage

◆ GetValue()

template<typename T , typename MASK_T >
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetValue ( int  row,
int  col,
T *&  values 
)

Get raster data (both for 1D and 2D raster) at the (row, col)

Parameters
[in]rowRow index
[in]colCol index
[out]valuesA float array with the length of n_lyrs_

◆ GetValueByIndex() [1/2]

template<typename T , typename MASK_T >
T ccgl::data_raster::clsRasterData< T, MASK_T >::GetValueByIndex ( int  cell_index,
int  lyr = 1 
)

Get options.

Get raster data at the valid cell index The default lyr is 1, which means the 1D raster data, or the first layer of 2D data.

◆ GetValueByIndex() [2/2]

template<typename T , typename MASK_T >
void ccgl::data_raster::clsRasterData< T, MASK_T >::GetValueByIndex ( int  cell_index,
T *&  values 
)

Get raster data at the valid cell index (both for 1D and 2D raster)

Parameters
[in]cell_indexCell's index in the first dimension
[out]valuesA float array with length as n_lyrs_ which should be release in the invoke code

◆ GetXllCenter()

template<typename T , typename MASK_T = T>
double ccgl::data_raster::clsRasterData< T, MASK_T >::GetXllCenter ( ) const
inline

Get cell size.

Get X coordinate of left lower center of raster data

◆ Init() [1/2]

template<typename T , typename MASK_T >
clsRasterData< T, MASK_T > * ccgl::data_raster::clsRasterData< T, MASK_T >::Init ( const string &  filename,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)
static

Validation check before the construction of clsRasterData, i.e., the raster file is existed and the data format supported.

This is the recommended way to construct an instance of clsRasterData.

clsRasterData<T> *rs = clsRasterData<T>::Init(filename)
if (nullptr == rs) {
throw exception("clsRasterData initialization failed!");
// or other error handling code.
}
static clsRasterData< T, MASK_T > * Init(const string &filename, bool calc_pos=false, clsRasterData< MASK_T > *mask=nullptr, bool use_mask_ext=true, double default_value=NODATA_VALUE, const STRING_MAP &opts=STRING_MAP())
Validation check before the construction of clsRasterData, i.e., the raster file is existed and the d...
Definition: data_raster.hpp:2150

◆ Init() [2/2]

template<typename T , typename MASK_T >
clsRasterData< T, MASK_T > * ccgl::data_raster::clsRasterData< T, MASK_T >::Init ( vector< string > &  filenames,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)
static

Validation check before the constructor of clsRasterData, i.e., the raster files are all existed and the data format supported.

This is the recommended way to construct an instance of clsRasterData, compatible with Raster1D and Rater2D.

vector<string> filenames = {"layer1.tif", "layer2.tif", "layer3.tif"};
clsRasterData<T> *rs = clsRasterData<T>::Init(filenames)
if (nullptr == rs) {
throw exception("clsRasterData initialization failed!");
// or other error handling code.
}

◆ OutputSubsetToFile()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::OutputSubsetToFile ( bool  out_origin = false,
bool  out_combined = true,
const string &  outname = string(),
const map< vint, vector< double > > &  recls = map<vint, vector<double> >(),
double  default_value = NODATA_VALUE 
)

Write one or more raster's subset to files, default name format: corename_SubID_LyrNum.

Parameters
out_origin(Optional) Output original raster data or data_ assigned for subset
out_combined(Optional) Output combined data of subset
outname(Optional) Output filename, if not specified, use origin directory and default name
recls(Optional) Reclassification map, no need to SetData before output subset
default_value(Optional) Default value for missed type of reclassification map

◆ OutputSubsetToMongoDB()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::OutputSubsetToMongoDB ( MongoGridFs gfs,
const string &  filename = string(),
const STRING_MAP opts = STRING_MAP(),
bool  include_nodata = true,
bool  out_origin = false,
bool  out_combined = true,
const map< vint, vector< double > > &  recls = map<vint, vector<double> >(),
double  default_value = NODATA_VALUE 
)

Write one or more raster's subset to MongoDB,.

   File name format in GridFS: corename_SubID_LyrNum, if SubID < 0, use 'n' as the prefix.
   e.g., corename_n1_1, corename_2_1, corename_3_1
Parameters
gfsmongoc_gridfs_t
filename(Optional) Core file name
opts(Optional) Key-value map for additional user-specific metadata
include_nodata(Optional) Include nodata or not
out_origin(Optional) Output original raster data or data_ assigned for subset
out_combined(Optional) Output combined data of subset
recls(Optional) Reclassification map, no need to SetData before output subset
default_value(Optional) Default value for missed type of reclassification map

◆ OutputToFile()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::OutputToFile ( const string &  filename,
bool  out_origin = true 
)

Write the whole raster to raster file, if 2D raster, output name will be corename_LyrNum.

Parameters
filenamefilename with prefix, e.g. ".asc" and ".tif"
out_origin(Optional) Write combination of original data or subset's data

◆ OutputToMongoDB()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::OutputToMongoDB ( MongoGridFs gfs,
const string &  filename = string(),
const STRING_MAP opts = STRING_MAP(),
bool  include_nodata = true,
bool  out_origin = true 
)

Write the whole raster data to MongoDB, name format: corename__LyrNum.

Parameters
gfsmongoc_gridfs_t
filename(Optional) File name, default is the core file name of input
opts(Optional) Key-value map for user-specific metadata
include_nodata(Optional) Include nodata or not
out_origin(Optional) Output original raster data or subset's data

◆ ReadFromFile()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::ReadFromFile ( const string &  filename,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)

Read raster data from file, mask data is optional.

Parameters
[in]filenamestring
[in]calc_posCalculate positions of valid cells excluding NODATA. The default is false.
[in]maskclsRasterData<MASK_T>
[in]use_mask_extUse mask layer extent, even NoDATA exists.
[in]default_valueDefault value when mask data exceeds the raster extend.
[in]optsOptional key-value stored in metadata

◆ ReadFromFiles()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::ReadFromFiles ( vector< string > &  filenames,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)

Read raster data from two or more files, mask data is optional.

See also
ReadFromFile

◆ ReadFromMongoDB()

template<typename T , typename MASK_T >
bool ccgl::data_raster::clsRasterData< T, MASK_T >::ReadFromMongoDB ( MongoGridFs gfs,
const string &  filename,
bool  calc_pos = false,
clsRasterData< MASK_T > *  mask = nullptr,
bool  use_mask_ext = true,
double  default_value = NODATA_VALUE,
const STRING_MAP opts = STRING_MAP() 
)

Read raster data from MongoDB.

Parameters
[in]gfsmongoc_gridfs_t
[in]filenamechar*, raster file name
[in]calc_posCalculate positions of valid cells excluding NODATA. The default is false.
[in]maskclsRasterData<MASK_T>
[in]use_mask_extUse mask layer extent, even NoDATA exists.
[in]default_valueDefault value when mask data exceeds the raster extend.
[in]optsOptional key-value stored in metadata, used to filter GridFs file

◆ ValidateRasterData()

template<typename T , typename MASK_T = T>
bool ccgl::data_raster::clsRasterData< T, MASK_T >::ValidateRasterData ( )
inline

Instance of clsRasterData initialized?

Validate the available of raster data, both 1D and 2D data


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