data_raster.hpp File Reference

Define Raster class to handle raster data Part of the Common Cross-platform Geographic Library (CCGL) More...

#include <string>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <typeinfo>
#include <cassert>
#include <omp.h>
#include "gdal.h"
#include "gdal_priv.h"
#include "cpl_string.h"
#include "ogr_spatialref.h"
#include "basic.h"
#include "utils_filesystem.h"
#include "utils_string.h"
#include "utils_array.h"
#include "utils_math.h"
#include "db_mongoc.h"

Go to the source code of this file.

Classes

class  ccgl::data_raster::SubsetPositions
 Subset positions of raster data. More...
 
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. More...
 

Namespaces

namespace  ccgl
 Common Cross-platform Geographic Library (CCGL)
 
namespace  ccgl::data_raster
 Raster class to handle various raster data.
 

Macros

#define CONST_CHARS   static const char*
 const string
 
#define IntRaster   clsRasterData<int>
 
#define FltRaster   clsRasterData<float>
 
#define DblRaster   clsRasterData<double>
 
#define IntIntRaster   clsRasterData<int, int>
 
#define FltIntRaster   clsRasterData<float, int>
 
#define DblIntRaster   clsRasterData<double, int>
 

Typedefs

typedef std::pair< int, int > ccgl::data_raster::ROW_COL
 GeoTIFF extension.
 
typedef std::pair< double, double > ccgl::data_raster::XY_COOR
 Row and Col pair.
 

Enumerations

enum  ccgl::data_raster::RasterDataType {
  ccgl::data_raster::RDT_Unknown , ccgl::data_raster::RDT_UInt8 , ccgl::data_raster::RDT_Int8 , ccgl::data_raster::RDT_UInt16 ,
  ccgl::data_raster::RDT_Int16 , ccgl::data_raster::RDT_UInt32 , ccgl::data_raster::RDT_Int32 , ccgl::data_raster::RDT_UInt64 ,
  ccgl::data_raster::RDT_Int64 , ccgl::data_raster::RDT_Float , ccgl::data_raster::RDT_Double
}
 Coordinate pair. More...
 

Functions

string ccgl::data_raster::RasterDataTypeToString (int type)
 Common functions independent to clsRasterData. More...
 
RasterDataType ccgl::data_raster::StringToRasterDataType (const string &stype)
 Convert string to RasterDataType.
 
RasterDataType ccgl::data_raster::TypeToRasterDataType (const std::type_info &t)
 Convert C++ data type to RasterDataType.
 
double ccgl::data_raster::DefaultNoDataByType (RasterDataType type)
 Default NoData value by data type.
 
GDALDataType ccgl::data_raster::CvtToGDALDataType (const RasterDataType type)
 
STRDBL_MAP ccgl::data_raster::InitialHeader ()
 Initialize header information in double.
 
void ccgl::data_raster::CopyHeader (const STRDBL_MAP &refers, STRDBL_MAP &dst)
 Copy header information from one to another. More...
 
template<typename T >
void ccgl::data_raster::UpdateHeader (STRDBL_MAP &header, const string &key, T val)
 Update value in header information.
 
STRING_MAP ccgl::data_raster::InitialStrHeader ()
 Initialize header information in string.
 
void ccgl::data_raster::UpdateStrHeader (STRING_MAP &strheader, const string &key, const string &val)
 Update header information in string.
 
RasterDataType ccgl::data_raster::RasterDataTypeInOptionals (const STRING_MAP &opts)
 Get output raster data type from optional inputs.
 
void ccgl::data_raster::InitialStatsMap (STRDBL_MAP &stats, map< string, double * > &stats2d)
 Initialize statistics values for 1D and 2D raster data.
 
template<typename T >
bool ccgl::data_raster::ReadAscFile (const string &filename, STRDBL_MAP &header, T *&values)
 Read raster data from ASC file, the simply usage. More...
 
bool ccgl::data_raster::WriteAscHeaders (const string &filename, const STRDBL_MAP &header)
 Write raster header information into a ASC file. More...
 
template<typename T >
bool ccgl::data_raster::WriteSingleAsc (const string &filename, const STRDBL_MAP &header, T *values)
 Write raster data as a single ASC file. More...
 
template<typename T >
bool ccgl::data_raster::ReadRasterFileByGdal (const string &filename, STRDBL_MAP &header, T *&values, RasterDataType &in_type, string &srs)
 Read single raster file by GDAL. More...
 
template<typename T >
bool ccgl::data_raster::WriteSingleGeotiff (const string &filename, const STRDBL_MAP &header, const STRING_MAP &opts, T *values)
 Write single geotiff file If the file exists, delete it first. More...
 
template<typename T >
bool ccgl::data_raster::WriteRasterToFile (const string &filename, const STRDBL_MAP &header, const STRING_MAP &opts, T *values)
 Write single raster file, if the file exists, delete it first. More...
 
template<typename T >
bool ccgl::data_raster::ReadGridFsFile (MongoGridFs *gfs, const string &filename, T *&data, STRDBL_MAP &header, STRING_MAP &header_str, const STRING_MAP &opts)
 Read GridFs file from MongoDB. More...
 
template<typename T >
bool ccgl::data_raster::WriteStreamDataAsGridfs (MongoGridFs *gfs, const string &filename, STRDBL_MAP &header, T *values, const int datalength, const STRING_MAP &opts=STRING_MAP())
 Write array data (both valid and full-sized raster data) as GridFS file. More...
 

Variables

CONST_CHARS ccgl::data_raster::HEADER_RS_NODATA = "NODATA_VALUE"
 
CONST_CHARS ccgl::data_raster::HEADER_RS_XLL = "XLLCENTER"
 NoData value.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_YLL = "YLLCENTER"
 X coordinate value of left low center.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_XLLCOR = "XLLCORNER"
 Y coordinate value of left low center.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_YLLCOR = "YLLCORNER"
 X coordinate value of left low center.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_NROWS = "NROWS"
 Y coordinate value of left low center.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_NCOLS = "NCOLS"
 Rows number.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_CELLSIZE = "CELLSIZE"
 Column number.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_LAYERS = "LAYERS"
 Cell size (length)
 
CONST_CHARS ccgl::data_raster::HEADER_RS_CELLSNUM = "CELLSNUM"
 Layers number.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_SRS = "SRS"
 Number of the first layer's valid cells.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_PARAM_ABSTRACTION_TYPE = "PARAM_ABSTRACTION_TYPE"
 SRS.
 
CONST_CHARS ccgl::data_raster::HEADER_RS_DATATYPE = "DATATYPE"
 spatial parameter type, physical or conceptual
 
CONST_CHARS ccgl::data_raster::HEADER_RSOUT_DATATYPE = "DATATYPE_OUT"
 Data type of original raster.
 
CONST_CHARS ccgl::data_raster::HEADER_INC_NODATA = "INCLUDE_NODATA"
 Desired output data type of raster.
 
CONST_CHARS ccgl::data_raster::HEADER_MASK_NAME = "MASK_NAME"
 Include nodata ("TRUE") or not ("FALSE"), for DB only.
 
CONST_CHARS ccgl::data_raster::STATS_RS_VALIDNUM = "VALID_CELLNUMBER"
 Mask layer's name if only store valid values.
 
CONST_CHARS ccgl::data_raster::STATS_RS_MEAN = "MEAN"
 Valid cell number.
 
CONST_CHARS ccgl::data_raster::STATS_RS_MIN = "MIN"
 Mean value.
 
CONST_CHARS ccgl::data_raster::STATS_RS_MAX = "MAX"
 Minimum value.
 
CONST_CHARS ccgl::data_raster::STATS_RS_STD = "STD"
 Maximum value.
 
CONST_CHARS ccgl::data_raster::STATS_RS_RANGE = "RANGE"
 Standard derivation value.
 
CONST_CHARS ccgl::data_raster::ASCIIExtension = "asc"
 Range value.
 
CONST_CHARS ccgl::data_raster::GTiffExtension = "tif"
 ASCII extension.
 

Detailed Description

Define Raster class to handle raster data Part of the Common Cross-platform Geographic Library (CCGL)

  • 1. Using GDAL and MongoDB (currently, up to mongo-c-driver 1.16.2 was tested)
  • 2. Array1D and Array2D raster data are supported
  • 3. C++11 supported
  • 4. Unit Tests based Google Test.
Remarks
  • 1. Dec. 2016 lj Separated from SEIMS to a common library for widely use.
  • 2. Mar. 2017 lj VLD check, bug fixed, function enhanced.
  • 3. Apr. 2017 lj Avoid try...catch block
  • 4. May. 2017 lj Use MongoDB wrapper
  • 5. Nov. 2017 lj Code review based on C++11 and use a single header file.
  • 6. Dec. 2017 lj Add Unittest based on Google Test.
  • 7. Mar. 2018 lj Make part of CCGL, and make GDAL optional. Follows Google C++ Code Style.
  • 8. Jun. 2018 lj Use emplace and emplace_back rather than insert and push_back whenever possible.
  • 9. Nov. 2018 lj Add specific field-value as options of raster data, including SRS. -10. Jul. 2021 lj No need to use pointer-to-pointer as arguments in GetValue and GetValueByIndex. -11. Apr. 2022 lj Comprehensive functional testing, bug fixing, and robustness improving. Add subset feature to support data decomposition and combination. -12. Jul. 2023 lj Add valid position index (1D array, pos_idx_) and will remove pos_data_ in next version. -13. Aug. 2023 lj Add GDAL data types added from versions 3.5 and 3.7
Author
Liangjun Zhu, zlj(at)lreis.ac.cn
Version
2.8