From cddc87b85d7873fd4b2604311dd9d0a1ebda595f Mon Sep 17 00:00:00 2001 From: Liang-Jun Zhu Date: Sat, 15 Jul 2023 11:13:02 +0800 Subject: [PATCH] Squashed 'seims/src/ccgl/' changes from 7441ea46..c3cb5566 c3cb5566 Update download link of GDAL libarary on Windows 5772bc58 (performance improved)Add valid position index (1D array, pos_idx_) and will remove pos_data_ in next version. 809ed126 Merge branch 'dev' abf08c78 feat: sync SEIMS to CCGL, and add `opts` to filter metadata of files in mongodb ce81cfe2 Merge branch 'dev' 9cbf53c1 disable jekyll git-subtree-dir: seims/src/ccgl git-subtree-split: c3cb5566bcafec3efb41b579d6df50e881a109ee --- .../cmake_builds_with-gdal-mongodb.yml | 1 - .github/workflows/download_gdal.ps1 | 4 +- src/data_raster.cpp | 13 +- src/data_raster.hpp | 213 ++++++++++++++---- src/db_mongoc.cpp | 17 +- src/db_mongoc.h | 2 +- src/utils_array.h | 18 +- src/utils_time.cpp | 37 +++ src/utils_time.h | 8 +- test/raster/test_raster1d_mask_exceed.cpp | 38 +++- test/raster/test_raster1d_mask_within.cpp | 48 +++- test/raster/test_raster1d_nomask.cpp | 9 + test/raster/test_raster1d_split_merge.cpp | 1 + test/raster/test_raster2d_mask.cpp | 8 + test/raster/test_raster2d_nomask.cpp | 9 + test/raster/test_raster2d_split_merge.cpp | 1 + test/raster/test_raster_constructor.cpp | 1 + 17 files changed, 351 insertions(+), 77 deletions(-) diff --git a/.github/workflows/cmake_builds_with-gdal-mongodb.yml b/.github/workflows/cmake_builds_with-gdal-mongodb.yml index 27e8bcaafc..ded480ff34 100644 --- a/.github/workflows/cmake_builds_with-gdal-mongodb.yml +++ b/.github/workflows/cmake_builds_with-gdal-mongodb.yml @@ -93,7 +93,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} commit_message: ${{ github.event.head_commit.message }} - disable_nojekyll: true publish_branch: gh-pages force_orphan: true publish_dir: html diff --git a/.github/workflows/download_gdal.ps1 b/.github/workflows/download_gdal.ps1 index 7029c2d6dd..d92015b1f1 100644 --- a/.github/workflows/download_gdal.ps1 +++ b/.github/workflows/download_gdal.ps1 @@ -1,8 +1,8 @@ param ($gdalPath = "$env:SystemDrive\gdal", $VSversion = "1928", $GDALversion = "3.5.3", $MAPSversion = "8.0.0") $GDALversion=$GDALversion -replace '\.','-' $MAPSversion=$MAPSversion -replace '\.','-' -$urllib = "https://build2.gisinternals.com/sdk/downloads/release-$VSversion-x64-gdal-$GDALversion-mapserver-$MAPSversion-libs.zip" -$urlbin = "https://build2.gisinternals.com/sdk/downloads/release-$VSversion-x64-gdal-$GDALversion-mapserver-$MAPSversion.zip" +$urllib = "https://download.gisinternals.com/sdk/downloads/release-$VSversion-x64-gdal-$GDALversion-mapserver-$MAPSversion-libs.zip" +$urlbin = "https://download.gisinternals.com/sdk/downloads/release-$VSversion-x64-gdal-$GDALversion-mapserver-$MAPSversion.zip" $zipLibFile = "$gdalPath\gdallib.zip" $zipBinFile = "$gdalPath\gdal.zip" diff --git a/src/data_raster.cpp b/src/data_raster.cpp index 6833d29ef6..7842cea170 100644 --- a/src/data_raster.cpp +++ b/src/data_raster.cpp @@ -198,6 +198,7 @@ bool SubsetPositions::Initialization() { g_ecol = -1; alloc_ = false; local_pos_ = nullptr; + local_posidx_ = nullptr; global_ = nullptr; data_ = nullptr; data2d_ = nullptr; @@ -229,6 +230,7 @@ SubsetPositions::SubsetPositions(SubsetPositions*& src, const bool deep_copy) { alloc_ = true; Initialize1DArray(n_cells, global_, src->global_); Initialize2DArray(n_cells, 2, local_pos_, src->local_pos_); + Initialize1DArray(n_cells, local_posidx_, src->local_posidx_); if (nullptr != src->data_) { Initialize1DArray(n_cells, data_, src->data_); } @@ -240,6 +242,7 @@ SubsetPositions::SubsetPositions(SubsetPositions*& src, const bool deep_copy) { alloc_ = false; global_ = src->global_; local_pos_ = src->local_pos_; + local_posidx_ = src->local_posidx_; if (nullptr != src->data_) { data_ = src->data_; } if (nullptr != src->data2d_) { data2d_ = src->data2d_; } } @@ -250,6 +253,10 @@ SubsetPositions::~SubsetPositions() { if (alloc_) { Release2DArray(local_pos_); } else { local_pos_ = nullptr; } } + if (nullptr != local_posidx_) { + if (alloc_) { Release1DArray(local_posidx_); } + else { local_posidx_ = nullptr; } + } if (nullptr != global_) { if (alloc_) { Release1DArray(global_); } else { global_ = nullptr; } @@ -282,7 +289,8 @@ bool SubsetPositions::ReadFromMongoDB(MongoGridFs* gfs, const string& fname, con Initialize1DArray(n_cells, data_, NODATA_VALUE); } for (int i = 0; i < n_cells; i++) { - data_[i] = dbdata[local_pos_[i][0] * ncols + local_pos_[i][1]]; + //data_[i] = dbdata[local_pos_[i][0] * ncols + local_pos_[i][1]]; + data_[i] = dbdata[local_posidx_[i]]; } } else { @@ -292,7 +300,8 @@ bool SubsetPositions::ReadFromMongoDB(MongoGridFs* gfs, const string& fname, con for (int i = 0; i < n_cells; i++) { for (int j = 0; j < n_lyrs; j++) { if (nfull == db_ncells) { // consider data from MongoDB is fullsize data - data2d_[i][j] = dbdata[(local_pos_[i][0] * ncols + local_pos_[i][1]) * n_lyrs + j]; + //data2d_[i][j] = dbdata[(local_pos_[i][0] * ncols + local_pos_[i][1]) * n_lyrs + j]; + data2d_[i][j] = dbdata[local_posidx_[i] * n_lyrs + j]; } else { data2d_[i][j] = dbdata[i * n_lyrs + j]; } } diff --git a/src/data_raster.hpp b/src/data_raster.hpp index 979889b9c6..8ab6d3313d 100644 --- a/src/data_raster.hpp +++ b/src/data_raster.hpp @@ -22,9 +22,10 @@ * -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. * * \author Liangjun Zhu, zlj(at)lreis.ac.cn - * \version 2.6 + * \version 2.7 */ #ifndef CCGL_DATA_RASTER_H #define CCGL_DATA_RASTER_H @@ -96,6 +97,7 @@ CONST_CHARS HEADER_RS_CELLSIZE = "CELLSIZE"; /// Cell size (length) CONST_CHARS HEADER_RS_LAYERS = "LAYERS"; /// Layers number CONST_CHARS HEADER_RS_CELLSNUM = "CELLSNUM"; /// Number of the first layer's valid cells CONST_CHARS HEADER_RS_SRS = "SRS"; /// SRS +CONST_CHARS HEADER_RS_PARAM_ABSTRACTION_TYPE = "PARAM_ABSTRACTION_TYPE"; /// spatial parameter type, physical or conceptual CONST_CHARS HEADER_RS_DATATYPE = "DATATYPE"; /// Data type of original raster CONST_CHARS HEADER_RSOUT_DATATYPE = "DATATYPE_OUT"; /// Desired output data type of raster CONST_CHARS HEADER_INC_NODATA = "INCLUDE_NODATA"; /// Include nodata ("TRUE") or not ("FALSE"), for DB only @@ -780,7 +782,7 @@ bool ReadGridFsFile(MongoGridFs* gfs, const string& filename, // Get stream data and metadata by file name vint length; char* buf = nullptr; - if (!gfs->GetStreamData(filename, buf, length, nullptr, opts) || + if (!gfs->GetStreamData(filename, buf, length, nullptr, &opts) || nullptr == buf) { return false; } @@ -1037,7 +1039,8 @@ class SubsetPositions: NotCopyable { T* tmpdata = nullptr; Initialize1DArray(fullsize, tmpdata, nodata); for (int vi = 0; vi < n_cells; vi++) { - int j = local_pos_[vi][0] * ncols + local_pos_[vi][1]; + //int j = local_pos_[vi][0] * ncols + local_pos_[vi][1]; + int j = local_posidx_[vi]; if (n_lyrs > 1 && nullptr != data2d_) { tmpdata[j] = static_cast(data2d_[vi][ilyr]); } @@ -1058,6 +1061,7 @@ class SubsetPositions: NotCopyable { int g_ecol; ///< end col in global data bool alloc_; ///< local_pos_ and global_ are allocated? int** local_pos_; ///< local position data + int* local_posidx_; ///< local position index int* global_; ///< global position index double* data_; ///< valid data array double** data2d_; ///< valid 2d data array @@ -1363,6 +1367,7 @@ class clsRasterData { * \brief Set valid positions data, without mask raster layer */ bool SetPositions(int len, int** pdata); + bool SetPositions(int len, int* pdata); /*! * \brief Set the flag of use_mask_ext_ to true and @@ -1598,8 +1603,11 @@ class clsRasterData { */ void GetRasterPositionData(int* datalength, int*** positiondata); + void GetRasterPositionData(int* datalength, int** positiondata); + T* GetRasterDataPointer() const { return raster_; } /// Get pointer of raster 1D data int** GetRasterPositionDataPointer() const { return pos_data_; } /// Get pointer of position data + int* GetRasterPositionIndexPointer() const { return pos_idx_; } /// Get pointer of position data T** Get2DRasterDataPointer() const { return raster_2d_; } /// Get pointer of raster 2D data const char* GetSrs(); /// Get the spatial reference (char*) string GetSrsString(); /// Get the spatial reference (string) @@ -1857,8 +1865,10 @@ class clsRasterData { T* raster_; //! 2D raster data, data access format: raster_2d_[cellIndex][layer], layer starts from 1 T** raster_2d_; - //! cell index (row, col) in raster_data_ or the first layer of raster_2d_ (2D array) + //! valid cells' position (row, col) in raster_data_ or the first layer of raster_2d_ (2D array) int** pos_data_; + //! valid cells' index (row * cols + col) in raster_data_ or the first layer of raster_2d_ + int* pos_idx_; //! Key-value options in string format, including spatial reference STRING_MAP options_; //! Header information, using double in case of truncation of coordinate value @@ -1922,6 +1932,7 @@ void clsRasterData::InitializeRasterClass(bool is_2d /* = false */) { default_value_ = NODATA_VALUE; raster_ = nullptr; pos_data_ = nullptr; + pos_idx_ = nullptr; mask_ = nullptr; subset_ = map(); n_lyrs_ = -1; @@ -2101,6 +2112,7 @@ clsRasterData::clsRasterData(clsRasterData* mask, T* const va use_mask_ext_ = true; n_lyrs_ = 1; mask->GetRasterPositionData(&n_cells_, &pos_data_); + mask->GetRasterPositionData(&n_cells_, &pos_idx_); if (n_cells_ != len) { StatusMessage("Input data length MUST EQUALS TO valid cell's number of mask!"); initialized_ = false; @@ -2122,6 +2134,7 @@ clsRasterData::clsRasterData(clsRasterData* mask, T** const v use_mask_ext_ = true; n_lyrs_ = lyrs; mask->GetRasterPositionData(&n_cells_, &pos_data_); + mask->GetRasterPositionData(&n_cells_, &pos_idx_); if (n_cells_ != len) { StatusMessage("Input data length MUST EQUALS TO valid cell's number of mask!"); initialized_ = false; @@ -2209,6 +2222,7 @@ clsRasterData::~clsRasterData() { if (!core_name_.empty()) { StatusMessage(("Release raster: " + core_name_).c_str()); } if (nullptr != raster_) { Release1DArray(raster_); } if (nullptr != pos_data_ && store_pos_) { Release2DArray(pos_data_); } + if (nullptr != pos_idx_ && store_pos_) { Release1DArray(pos_idx_); } if (nullptr != raster_2d_ && is_2draster) { Release2DArray(raster_2d_); } if (is_2draster && stats_calculated_) { ReleaseStatsMap2D(); } ReleaseSubset(); @@ -2217,10 +2231,12 @@ clsRasterData::~clsRasterData() { template bool clsRasterData::BuildSubSet(map groups /* = map() */) { if (!ValidateRasterData()) { return false; } - if (nullptr == pos_data_) { + if (nullptr == pos_data_ || nullptr == pos_idx_) { if (!SetCalcPositions()) { return false; } } if (!subset_.empty()) { return true; } + + int global_ncols = GetCols(); map > global_idx; for (int vi = 0; vi < n_cells_; vi++) { T curv = GetValueByIndex(vi); // compatible with 2D Raster @@ -2229,8 +2245,10 @@ bool clsRasterData::BuildSubSet(map groups /* = map specified group ID } - int currow = pos_data_[vi][0]; - int curcol = pos_data_[vi][1]; + //int currow = pos_data_[vi][0]; + //int curcol = pos_data_[vi][1]; + int currow = pos_idx_[vi] / global_ncols; + int curcol = pos_idx_[vi] % global_ncols; if (subset_.find(groupv) == subset_.end()) { #ifdef HAS_VARIADIC_TEMPLATES subset_.emplace(groupv, new SubsetPositions(currow, currow, curcol, curcol)); @@ -2261,9 +2279,18 @@ bool clsRasterData::BuildSubSet(map groups /* = mapsecond->n_cells, 2, it->second->local_pos_, -1); + Initialize1DArray(it->second->n_cells, it->second->local_posidx_, -1); + + int nrows = it->second->g_erow - it->second->g_srow + 1; + int local_ncols = it->second->g_ecol - it->second->g_scol + 1; for (int gidx = 0; gidx < it->second->n_cells; gidx++) { - it->second->local_pos_[gidx][0] = pos_data_[it->second->global_[gidx]][0] - it->second->g_srow; - it->second->local_pos_[gidx][1] = pos_data_[it->second->global_[gidx]][1] - it->second->g_scol; + //it->second->local_pos_[gidx][0] = pos_data_[it->second->global_[gidx]][0] - it->second->g_srow; + //it->second->local_pos_[gidx][1] = pos_data_[it->second->global_[gidx]][1] - it->second->g_scol; + int local_row = pos_idx_[it->second->global_[gidx]] / global_ncols - it->second->g_srow; + int local_col = pos_idx_[it->second->global_[gidx]] % global_ncols - it->second->g_scol; + it->second->local_pos_[gidx][0] = local_row; + it->second->local_pos_[gidx][1] = local_col; + it->second->local_posidx_[gidx] = local_row * local_ncols + local_col; } it->second->alloc_ = true; } @@ -2410,12 +2437,28 @@ int clsRasterData::GetPosition(const int row, const int col) { if (!ValidateRasterData() || !ValidateRowCol(row, col)) { return -2; // means error occurred! } - if (!calc_pos_ || nullptr == pos_data_) { - return GetCols() * row + col; - } - for (int i = 0; i < n_cells_; i++) { - if (row == pos_data_[i][0] && col == pos_data_[i][1]) { - return i; + int pos_idx = GetCols() * row + col; + if (!calc_pos_ || nullptr == pos_data_ || nullptr == pos_idx_) { + return pos_idx; + } +// previous low-efficiency code +// for (int i = 0; i < n_cells_; i++) { +// if (row == pos_data_[i][0] && col == pos_data_[i][1]) { +// return i; +// } +// } + // Use binary search method, refers to https://leetcode.cn/problems/binary-search + //int search(vector& nums, int target) { + int left = 0; + int right = n_cells_ - 1; // assumes pos_idx belongs to pos_idx_[left, right] + while (left <= right) { // when left==right,[left, right] still works,so use <= + int middle = left + ((right - left) / 2); // equals to (left + right)/2 + if (pos_idx_[middle] > pos_idx) { + right = middle - 1; // pos_idx belongs to [left, middle - 1] + } else if (pos_idx_[middle] < pos_idx) { + left = middle + 1; // pos_idx belongs to [middle + 1, right] + } else { // pos_idx_[middle] == pos_idx + return middle; } } return -1; // means the location of the raster data or mask data is NODATA @@ -2436,8 +2479,10 @@ int clsRasterData::GetPosition(const double x, const double y) { int n_rows = GetRows(); int n_cols = GetCols(); - if (FloatEqual(xll_center, CVT_DBL(NODATA_VALUE)) || FloatEqual(yll_center, CVT_DBL(NODATA_VALUE)) || - FloatEqual(dx, CVT_DBL(NODATA_VALUE)) || n_rows < 0 || n_cols < 0) { + if (FloatEqual(xll_center, CVT_DBL(NODATA_VALUE)) + || FloatEqual(yll_center, CVT_DBL(NODATA_VALUE)) + || FloatEqual(dx, CVT_DBL(NODATA_VALUE)) + || n_rows < 0 || n_cols < 0) { StatusMessage("No available header information!"); return -2; } @@ -2504,6 +2549,24 @@ void clsRasterData::GetRasterPositionData(int* datalength, int*** pos } } +template +void clsRasterData::GetRasterPositionData(int* datalength, int** positiondata) { + if (nullptr != pos_idx_) { + *datalength = n_cells_; + *positiondata = pos_idx_; + } else { + // reCalculate position data + if (!ValidateRasterData()) { + *datalength = -1; + *positiondata = nullptr; + return; + } + CalculateValidPositionsFromGridData(); + *datalength = n_cells_; + *positiondata = pos_idx_; + } +} + template const char* clsRasterData::GetSrs() { return GetSrsString().c_str(); @@ -2559,7 +2622,7 @@ T clsRasterData::GetValue(const int row, const int col, const int lyr return no_data_value_; } // get index according to position data if possible - if (calc_pos_ && nullptr != pos_data_) { + if (calc_pos_ && (nullptr != pos_data_ || nullptr != pos_idx_)) { int valid_cell_index = GetPosition(row, col); if (valid_cell_index < 0) { return no_data_value_; }// error or NODATA return GetValueByIndex(valid_cell_index, lyr); @@ -2579,7 +2642,7 @@ void clsRasterData::GetValue(const int row, const int col, T*& values if (nullptr == values) { Initialize1DArray(n_lyrs_, values, no_data_value_); } - if (calc_pos_ && nullptr != pos_data_) { + if (calc_pos_ && (nullptr != pos_data_ || nullptr != pos_idx_)) { int valid_cell_index = GetPosition(row, col); if (valid_cell_index == -1) { for (int i = 0; i < n_lyrs_; i++) { @@ -2635,7 +2698,7 @@ void clsRasterData::SetValue(const int row, const int col, T value, c template bool clsRasterData::SetCalcPositions() { if (!ValidateRasterData()) { return false; } - if (calc_pos_ && nullptr != pos_data_) { + if (calc_pos_ && (nullptr != pos_data_ || nullptr != pos_idx_)) { // already set as True, no need to recalculate. return false; } @@ -2655,6 +2718,17 @@ bool clsRasterData::SetPositions(int len, int** pdata) { return true; } +template +bool clsRasterData::SetPositions(int len, int* pdata) { + if (nullptr != pos_idx_) { + if (len != n_cells_) { return false; } // cannot change origin n_cells_ + Release1DArray(pos_idx_); + } + pos_idx_ = pdata; + calc_pos_ = true; + store_pos_ = false; + return true; +} template bool clsRasterData::SetUseMaskExt() { @@ -2806,9 +2880,10 @@ bool clsRasterData::PrepareCombSubsetData(T** values, int* datalen, i for (int vi = 0; vi < it->second->n_cells; vi++) { for (int ilyr = 0; ilyr < lyrs; ilyr++) { int gidx = it->second->global_[vi]; - int tmpr = pos_data_[gidx][0]; - int tmpc = pos_data_[gidx][1]; - int tmprc = tmpr * gncols + tmpc; + //int tmpr = pos_data_[gidx][0]; + //int tmpc = pos_data_[gidx][1]; + //int tmprc = tmpr * gncols + tmpc; + int tmprc = pos_idx_[gidx]; if (!include_nodata) { tmprc = gidx; } if (!recls.empty()) { // first priority double uniqe_value = default_value; @@ -2886,7 +2961,8 @@ bool clsRasterData::PrepareSubsetData(const int sub_id, SubsetPositio Initialize1DArray(data_length, data1d, no_data_value_); for (int vi = 0; vi < sub->n_cells; vi++) { for (int ilyr = 0; ilyr < lyrs; ilyr++) { - int j = sub->local_pos_[vi][0] * ncols + sub->local_pos_[vi][1]; + //int j = sub->local_pos_[vi][0] * ncols + sub->local_pos_[vi][1]; + int j = sub->local_posidx_[vi]; int gidx = sub->global_[vi]; if (!include_nodata) { j = vi; } if (!recls.empty()) { // first priority @@ -2957,11 +3033,14 @@ bool clsRasterData::OutputAscFile(const string& filename) { // Is there need to calculate valid position index? int count; int** position = nullptr; + int* position_idx = nullptr; bool outputdirectly = true; - if (nullptr != pos_data_) { + if ((nullptr != pos_data_ || nullptr != pos_idx_)) { GetRasterPositionData(&count, &position); + GetRasterPositionData(&count, &position_idx); outputdirectly = false; assert(nullptr != position); + assert(nullptr != position_idx); } // Begin to write raster data int rows = CVT_INT(headers_.at(HEADER_RS_NROWS)); @@ -3028,7 +3107,7 @@ bool clsRasterData::OutputAscFile(const string& filename) { template bool clsRasterData::OutputFileByGdal(const string& filename) { string abs_filename = GetAbsolutePath(filename); - bool outputdirectly = nullptr == pos_data_; + bool outputdirectly = (nullptr == pos_data_ || nullptr == pos_idx_); int n_rows = CVT_INT(headers_.at(HEADER_RS_NROWS)); int n_cols = CVT_INT(headers_.at(HEADER_RS_NCOLS)); bool outflag = false; @@ -3050,7 +3129,8 @@ bool clsRasterData::OutputFileByGdal(const string& filename) { Initialize1DArray(n_rows * n_cols, data_1d, no_data_value_); } for (int vi = 0; vi < n_cells_; vi++) { - data_1d[pos_data_[vi][0] * n_cols + pos_data_[vi][1]] = raster_2d_[vi][lyr]; + //data_1d[pos_data_[vi][0] * n_cols + pos_data_[vi][1]] = raster_2d_[vi][lyr]; + data_1d[pos_idx_[vi]] = raster_2d_[vi][lyr]; } } outflag = WriteSingleGeotiff(tmpfilename, headers_, options_, data_1d); @@ -3066,7 +3146,8 @@ bool clsRasterData::OutputFileByGdal(const string& filename) { } else { Initialize1DArray(n_rows * n_cols, data_1d, no_data_value_); for (int vi = 0; vi < n_cells_; vi++) { - data_1d[pos_data_[vi][0] * n_cols + pos_data_[vi][1]] = raster_[vi]; + //data_1d[pos_data_[vi][0] * n_cols + pos_data_[vi][1]] = raster_[vi]; + data_1d[pos_idx_[vi]] = raster_[vi]; } outflag = WriteSingleGeotiff(abs_filename, headers_, options_, data_1d); Release1DArray(data_1d); @@ -3098,11 +3179,11 @@ bool clsRasterData::OutputToMongoDB(MongoGridFs* gfs, const string& f bool outputdirectly = true; // output directly or create new full size array int cnt; int** pos = nullptr; - if (nullptr != pos_data_ && include_nodata) { + if ((nullptr != pos_data_ || nullptr != pos_idx_) && include_nodata) { outputdirectly = false; GetRasterPositionData(&cnt, &pos); } - if (nullptr == pos_data_ && !include_nodata) { + if ((nullptr == pos_data_ || nullptr == pos_idx_) && !include_nodata) { SetCalcPositions(); GetRasterPositionData(&cnt, &pos); } @@ -3182,6 +3263,8 @@ bool clsRasterData::OutputSubsetToMongoDB(MongoGridFs* gfs, UpdateStrHeader(options_, HEADER_RSOUT_DATATYPE, RasterDataTypeToString(TypeToRasterDataType(typeid(T)))); } + + int grows = GetRows(); string outnameact = filename.empty() ? core_name_ : filename; bool out_comb = out_combined; @@ -3289,11 +3372,13 @@ bool clsRasterData::ReadFromFiles(vector& filenames, const bo return false; #endif } - if (nullptr != pos_data_) { + if (nullptr != pos_data_ || nullptr != pos_idx_) { #pragma omp parallel for for (int i = 0; i < n_cells_; ++i) { - int tmp_row = pos_data_[i][0]; - int tmp_col = pos_data_[i][1]; + //int tmp_row = pos_data_[i][0]; // row * ncols + col, + //int tmp_col = pos_data_[i][1]; + int tmp_row = pos_idx_[i] / cols; + int tmp_col = pos_idx_[i] % cols; AddOtherLayerRasterData(tmp_row, tmp_col, i, fileidx, tmpheader, tmplyrdata); } } @@ -3366,11 +3451,12 @@ bool clsRasterData::ReadFromMongoDB(MongoGridFs* gfs, if (include_nodata && n_cells_ != fullsize) { return false; } if (n_cells_ != fullsize) { calc_pos_ = true; } - // check the valid values count and determine whether can read directly. + // check the valid values count and determine whether we can read directly. bool mask_pos_subset = true; if (nullptr != mask_ && calc_pos_ && use_mask_ext_ && n_cells_ == mask_->GetValidNumber()) { store_pos_ = false; mask_->GetRasterPositionData(&n_cells_, &pos_data_); + mask_->GetRasterPositionData(&n_cells_, &pos_idx_); if (!mask->GetSubset().empty()) { map& mask_subset = mask_->GetSubset(); for (auto it = mask_subset.begin(); it != mask_subset.end(); ++it) { @@ -3386,7 +3472,7 @@ bool clsRasterData::ReadFromMongoDB(MongoGridFs* gfs, mask_pos_subset = false; } - if (!include_nodata && nullptr == pos_data_) { return false; } + if (!include_nodata && (nullptr == pos_data_ || nullptr == pos_idx_)) { return false; } if (n_lyrs_ == 1) { is_2draster = false; @@ -3394,7 +3480,8 @@ bool clsRasterData::ReadFromMongoDB(MongoGridFs* gfs, Initialize1DArray(n_cells_, raster_, no_data_value_); #pragma omp parallel for for (int i = 0; i < n_cells_; i++) { - int tmpidx = pos_data_[i][0] * n_cols + pos_data_[i][1]; + //int tmpidx = pos_data_[i][0] * n_cols + pos_data_[i][1]; + int tmpidx = pos_idx_[i]; raster_[i] = static_cast(dbdata[tmpidx]); } Release1DArray(dbdata); @@ -3407,7 +3494,8 @@ bool clsRasterData::ReadFromMongoDB(MongoGridFs* gfs, for (int i = 0; i < n_cells_; i++) { int tmpidx = i; if (include_nodata && !mask_pos_subset) { - tmpidx = pos_data_[i][0] * n_cols + pos_data_[i][1]; + //tmpidx = pos_data_[i][0] * n_cols + pos_data_[i][1]; + tmpidx = pos_idx_[i]; } for (int j = 0; j < n_lyrs_; j++) { int idx = tmpidx * n_lyrs_ + j; @@ -3461,6 +3549,9 @@ void clsRasterData::Copy(clsRasterData* orgraster) { if (nullptr != pos_data_) { Release2DArray(pos_data_); } + if (nullptr != pos_idx_) { + Release1DArray(pos_idx_); + } if (stats_calculated_) { ReleaseStatsMap2D(); stats_calculated_ = false; @@ -3486,8 +3577,8 @@ void clsRasterData::Copy(clsRasterData* orgraster) { } if (calc_pos_) { store_pos_ = true; - Initialize2DArray(n_cells_, 2, pos_data_, - orgraster->GetRasterPositionDataPointer()); + Initialize2DArray(n_cells_, 2, pos_data_, orgraster->GetRasterPositionDataPointer()); + Initialize1DArray(n_cells_, pos_idx_, orgraster->GetRasterPositionIndexPointer()); } stats_calculated_ = orgraster->StatisticsCalculated(); if (stats_calculated_) { @@ -3650,6 +3741,7 @@ void clsRasterData::CalculateValidPositionsFromGridData() { } // pos_data_ is nullptr till now. Initialize2DArray(n_cells_, 2, pos_data_, 0); + Initialize1DArray(n_cells_, pos_idx_, 0); store_pos_ = true; #pragma omp parallel for for (int i = 0; i < n_cells_; ++i) { @@ -3665,6 +3757,7 @@ void clsRasterData::CalculateValidPositionsFromGridData() { } pos_data_[i][0] = pos_rows.at(i); pos_data_[i][1] = pos_cols.at(i); + pos_idx_[i] = pos_rows.at(i) * ncols + pos_cols.at(i); } calc_pos_ = true; } @@ -3674,7 +3767,7 @@ int clsRasterData::MaskAndCalculateValidPosition() { int old_fullsize = GetRows() * GetCols(); if (nullptr == mask_) { if (calc_pos_) { - if (nullptr == pos_data_) { + if (nullptr == pos_data_ || nullptr == pos_idx_) { CalculateValidPositionsFromGridData(); return 1; } @@ -3780,7 +3873,7 @@ int clsRasterData::MaskAndCalculateValidPosition() { } } - // Set several flags + // Set several flags // Flag 1: If masked cells' count equals valid positions' count of the mask layer bool match_exactly = matched_count == mask_ncells; // Flag2 : Is the valid grid extent same as the mask data, which means the mask @@ -3907,15 +4000,26 @@ int clsRasterData::MaskAndCalculateValidPosition() { store_pos_ = true; n_cells_ = CVT_INT(values.size()); - if (nullptr != pos_data_) { Release1DArray(pos_data_); } + if (nullptr != pos_data_) { Release2DArray(pos_data_); } + if (nullptr != pos_idx_) { Release1DArray(pos_idx_); } Initialize2DArray(n_cells_, 2, pos_data_, 0); + Initialize1DArray(n_cells_, pos_idx_, 0); for (size_t k = 0; k < pos_rows.size(); ++k) { pos_data_[k][0] = pos_rows.at(k); pos_data_[k][1] = pos_cols.at(k); + if (upd_header_rowcol) { + pos_idx_[k] = pos_rows.at(k) * new_cols + pos_cols.at(k); + } else { + pos_idx_[k] = pos_rows.at(k) * mask_cols + pos_cols.at(k); + } } } else { - if (nullptr != pos_data_) { Release1DArray(pos_data_); } - if (calc_pos_) mask_->GetRasterPositionData(&n_cells_, &pos_data_); + if (nullptr != pos_data_) { Release2DArray(pos_data_); } + if (nullptr != pos_idx_) { Release1DArray(pos_idx_); } + if (calc_pos_) { + mask_->GetRasterPositionData(&n_cells_, &pos_data_); + mask_->GetRasterPositionData(&n_cells_, &pos_idx_); + } store_pos_ = false; } @@ -4006,24 +4110,35 @@ int clsRasterData::MaskAndCalculateValidPosition() { it->second->g_ecol = ecol; it->second->n_cells = count; it->second->n_lyrs = n_lyrs_; + int local_ncols = ecol - scol + 1; if (it->second->alloc_) { Release1DArray(it->second->global_); Release2DArray(it->second->local_pos_); + Release1DArray(it->second->local_posidx_); } it->second->global_ = nullptr; // not affect mask's subset it->second->local_pos_ = nullptr; + it->second->local_posidx_ = nullptr; it->second->alloc_ = true; Initialize1DArray(count, it->second->global_, -1); Initialize2DArray(count, 2, it->second->local_pos_, -1); + Initialize1DArray(count, it->second->local_posidx_, -1); for (int ii = 0; ii < count; ii++) { it->second->global_[ii] = globalpos[ii]; - if (nullptr == pos_data_) { - it->second->local_pos_[ii][0] = globalpos[ii] / ncols - it->second->g_srow; - it->second->local_pos_[ii][1] = globalpos[ii] % ncols - it->second->g_scol; + int local_row = -1; + int local_col = -1; + if (nullptr == pos_data_ || nullptr == pos_idx_) { + local_row = globalpos[ii] / ncols - it->second->g_srow; + local_col = globalpos[ii] % ncols - it->second->g_scol; } else { - it->second->local_pos_[ii][0] = pos_data_[globalpos[ii]][0] - it->second->g_srow; - it->second->local_pos_[ii][1] = pos_data_[globalpos[ii]][1] - it->second->g_scol; + //local_row = pos_data_[globalpos[ii]][0] - it->second->g_srow; + //local_col = pos_data_[globalpos[ii]][1] - it->second->g_scol; + local_row = pos_idx_[globalpos[ii]] / ncols - it->second->g_srow; + local_col = pos_idx_[globalpos[ii]] % ncols - it->second->g_scol; } + it->second->local_pos_[ii][0] = local_row; + it->second->local_pos_[ii][1] = local_col; + it->second->local_posidx_[ii] = local_row * local_ncols + local_col; } it->second->data_ = nullptr; it->second->data2d_ = nullptr; diff --git a/src/db_mongoc.cpp b/src/db_mongoc.cpp index fd30dd18bc..282def2efb 100644 --- a/src/db_mongoc.cpp +++ b/src/db_mongoc.cpp @@ -239,7 +239,7 @@ void MongoDatabase::GetCollectionNames(vector& collnames) { // Refers to https://stackoverflow.com/a/18703743/4837280 std::for_each(splitstrs.begin(), splitstrs.end() - 1, [&](const std::string &piece){ realname += piece; }); - string another_coll = splitstrs.back() == "files" ? + string another_coll = splitstrs.back() == "files" ? realname + ".chunks" : realname + ".files"; if (find(collnames.begin(), collnames.end(), another_coll) == collnames.end()) { @@ -278,7 +278,7 @@ mongoc_cursor_t* MongoCollection::ExecuteQuery(const bson_t* b) { // Upd 12/13/2017 The new method also failed in our linux cluster (redhat 6.2 and Intel C++ 12.1). // Upd 12/29/2021 I decide to use new method from a quite later version such as v1.8.0. // Maybe a precise version can be determined after a thorough test. - // Upd 06/24/2022 The new API still not working in Windows. + // Upd 06/24/2022 The new API still not working in Windows. mongoc_cursor_t* cursor = nullptr; // #if MONGOC_CHECK_VERSION(1, 8, 0) // cursor = mongoc_collection_find_with_opts(collection_, b, NULL, NULL); @@ -420,13 +420,17 @@ bson_t* MongoGridFs::GetFileMetadata(string const& gfilename, bool MongoGridFs::GetStreamData(string const& gfilename, char*& databuf, vint& datalength, mongoc_gridfs_t* gfs /* = NULL */, - STRING_MAP opts /* = STRING_MAP() */) { + const STRING_MAP* opts /* = nullptr */) { if (gfs_ != NULL) { gfs = gfs_; } if (NULL == gfs) { StatusMessage("mongoc_gridfs_t must be provided for MongoGridFs!"); return false; } - mongoc_gridfs_file_t* gfile = GetFile(gfilename, gfs, opts); + STRING_MAP opts_temp; + if (nullptr == opts) { + opts = &opts_temp; + } + mongoc_gridfs_file_t* gfile = GetFile(gfilename, gfs, *opts); if (NULL == gfile) { databuf = NULL; StatusMessage(("MongoGridFs::GetStreamData(" + gfilename + ") failed!").c_str()); @@ -564,7 +568,10 @@ bool GetBoolFromBson(bson_t* bmeta, const char* key) { time_t GetDatetimeFromBsonIterator(bson_iter_t* iter) { const bson_value_t* vv = bson_iter_value(iter); if (vv->value_type == BSON_TYPE_DATE_TIME) { - return CVT_TIMET(vv->value.v_datetime); + string str_milisec = std::to_string(vv->value.v_datetime); + string str_second = str_milisec.substr(0, str_milisec.length() - 3); + int intStr = atoi(str_second.c_str()); + return CVT_TIMET(intStr); } if (vv->value_type == BSON_TYPE_UTF8) { string tmp_time_str = vv->value.v_utf8.str; diff --git a/src/db_mongoc.h b/src/db_mongoc.h index 4ef4cfc625..bb5974eb35 100644 --- a/src/db_mongoc.h +++ b/src/db_mongoc.h @@ -167,7 +167,7 @@ class MongoGridFs { /*! Get stream data of a given GridFS file name */ bool GetStreamData(string const& gfilename, char*& databuf, vint& datalength, mongoc_gridfs_t* gfs = NULL, - STRING_MAP opts = STRING_MAP()); + const STRING_MAP* opts = nullptr); /*! Write stream data to a GridFS file */ bool WriteStreamData(const string& gfilename, char*& buf, vint length, diff --git a/src/utils_array.h b/src/utils_array.h index cfeda7c7bd..4b93b830be 100644 --- a/src/utils_array.h +++ b/src/utils_array.h @@ -50,6 +50,8 @@ bool Initialize1DArray(int row, T*& data, INI_T init_value); template bool Initialize1DArray(int row, T*& data, INI_T* init_data); +template +bool Initialize1DArray4ItpWeight(int row, T*& data, INI_T* init_data, int itp_weight_data_length); /*! * \brief Initialize DT_Array2D data * @@ -329,11 +331,12 @@ class Array2D { template bool Initialize1DArray(const int row, T*& data, const INI_T init_value) { if (nullptr != data) { - cout << "The input 1D array pointer is not nullptr, without initialized!" << endl; + //Should allow an array to re-enter this function then just return? --wyj + //cout << "The input 1D array pointer is not nullptr. No initialization performed!" << endl; return false; } if (row <= 0) { - cout << "The data length MUST greater than 0!" << endl; + cout << "The data length MUST be greater than 0!" << endl; data = nullptr; return false; } @@ -355,7 +358,7 @@ bool Initialize1DArray(const int row, T*& data, const INI_T init_value) { template bool Initialize1DArray(const int row, T*& data, INI_T* const init_data) { if (nullptr != data) { - cout << "The input 1D array pointer is not nullptr, without initialized!" << endl; + cout << "The input 1D array pointer is not nullptr. No initialization performed!" << endl; return false; } data = new(nothrow) T[row]; @@ -376,13 +379,10 @@ bool Initialize1DArray(const int row, T*& data, INI_T* const init_data) { } template -bool Initialize2DArray(const int row, const int col, T**& data, const INI_T init_value) { - if (row <= 0 || col <= 0) { - cout << "The row and col should not be less or equal to ZERO!" << endl; - return false; - } +bool Initialize2DArray(const int row, const int col, T**& data, + const INI_T init_value) { if (nullptr != data) { - cout << "The input 2D array pointer is not nullptr, without initialized!" << endl; + cout << "The input 2D array pointer is not nullptr. No initialization performed!" << endl; return false; } data = new(nothrow) T*[row]; diff --git a/src/utils_time.cpp b/src/utils_time.cpp index 43a5c23718..f56efcafce 100644 --- a/src/utils_time.cpp +++ b/src/utils_time.cpp @@ -72,6 +72,43 @@ string ConvertToString2(const time_t date, const bool utc_time /* = true */) { delete date_info; return s; } +/// format: 2022_11_17_092000 +string ConvertToString3(const time_t date, const bool utc_time /* = true */) { + static int month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + struct tm* date_info = new tm(); + GetDateTime(date, date_info, utc_time); + if (date_info->tm_isdst > 0) { + if (date_info->tm_hour != 0) { + date_info->tm_hour -= 1; + } + else { + date_info->tm_hour = 23; + date_info->tm_mday -= 1; + if (date_info->tm_mday == 0) { + date_info->tm_mon -= 1; + + if (date_info->tm_mon == 0) { + date_info->tm_year -= 1; + date_info->tm_mon = 12; + date_info->tm_mday = 31; + } + else { + if (IsLeapYear(date_info->tm_year)) { + date_info->tm_mday = month_days[date_info->tm_mon] + 1; + } + else { + date_info->tm_mday = month_days[date_info->tm_mon]; + } + } + } + } + } + char date_string[30]; + strftime(date_string, 30, "%Y_%m_%d_%H%M%S", date_info); + string s(date_string); + delete date_info; + return s; +} time_t ConvertToTime(const string& str_date, string const& format, const bool include_hour, const bool utc_time /* = true */) { diff --git a/src/utils_time.h b/src/utils_time.h index cb9de9ca65..835a5478e3 100644 --- a/src/utils_time.h +++ b/src/utils_time.h @@ -45,7 +45,13 @@ string ConvertToString(const time_t date, bool utc_time = true); * \return Date time \a string */ string ConvertToString2(const time_t date, bool utc_time = true); - +/*! + * \brief Convert date time to string as the format of "YYYY_MM_DD_HHMMSS" + * \param[in] date \a time_t data type + * \param[in] utc_time By default, the input date is under UTC+00:00 timezone. + * \return Date time \a string + */ +string ConvertToString3(const time_t date, bool utc_time = true); /*! * \brief Convert string to date time, string format could be %4d%2d%2d or %d-%d-%d * diff --git a/test/raster/test_raster1d_mask_exceed.cpp b/test/raster/test_raster1d_mask_exceed.cpp index 96bf1c43fb..e559b13d94 100644 --- a/test/raster/test_raster1d_mask_exceed.cpp +++ b/test/raster/test_raster1d_mask_exceed.cpp @@ -86,14 +86,16 @@ class clsRasterDataTestMaskExceed : public TestWithParam { void SetUp() OVERRIDE { // Read mask data without calculate valid positions - // Mask data that do not matched exactly + // Mask data that do not match exactly maskrs_ = IntRaster::Init(GetParam()->mask_name, false); ASSERT_NE(nullptr, maskrs_); EXPECT_FALSE(maskrs_->PositionsCalculated()); EXPECT_EQ(maskrs_->GetRasterPositionDataPointer(), nullptr); + EXPECT_EQ(maskrs_->GetRasterPositionIndexPointer(), nullptr); maskrs_->SetCalcPositions(); EXPECT_TRUE(maskrs_->PositionsCalculated()); EXPECT_NE(maskrs_->GetRasterPositionDataPointer(), nullptr); + EXPECT_NE(maskrs_->GetRasterPositionIndexPointer(), nullptr); EXPECT_TRUE(maskrs_->PositionsCalculated()); EXPECT_EQ(3, maskrs_->GetValidNumber()); @@ -111,9 +113,11 @@ class clsRasterDataTestMaskExceed : public TestWithParam { ASSERT_NE(nullptr, maskrs2_); EXPECT_FALSE(maskrs2_->PositionsCalculated()); EXPECT_EQ(maskrs2_->GetRasterPositionDataPointer(), nullptr); + EXPECT_EQ(maskrs2_->GetRasterPositionIndexPointer(), nullptr); maskrs2_->SetCalcPositions(); EXPECT_TRUE(maskrs2_->PositionsCalculated()); EXPECT_NE(maskrs2_->GetRasterPositionDataPointer(), nullptr); + EXPECT_NE(maskrs2_->GetRasterPositionIndexPointer(), nullptr); EXPECT_TRUE(maskrs2_->PositionsCalculated()); EXPECT_EQ(5, maskrs2_->GetValidNumber()); @@ -176,6 +180,7 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactNoPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_EQ(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_EQ(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -304,9 +309,12 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactNoPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posidx); mongors_valid->SetPositions(poslen, posdata); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -360,6 +368,7 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactNoPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -487,9 +496,12 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactNoPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -543,6 +555,7 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactCalPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -668,9 +681,12 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactCalPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -724,6 +740,7 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactCalPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -851,9 +868,12 @@ TEST_P(clsRasterDataTestMaskExceed, MatchExactCalPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -908,6 +928,7 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactNoPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_EQ(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_EQ(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1033,9 +1054,12 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactNoPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -1090,6 +1114,7 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactNoPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1224,9 +1249,12 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactNoPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -1281,6 +1309,7 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactCalPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1406,9 +1435,12 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactCalPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -1463,6 +1495,7 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactCalPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1588,9 +1621,12 @@ TEST_P(clsRasterDataTestMaskExceed, NotMatchExactCalPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, diff --git a/test/raster/test_raster1d_mask_within.cpp b/test/raster/test_raster1d_mask_within.cpp index 10da28146b..115cd11173 100644 --- a/test/raster/test_raster1d_mask_within.cpp +++ b/test/raster/test_raster1d_mask_within.cpp @@ -91,17 +91,21 @@ class clsRasterDataTestMaskWithin: public TestWithParam { ASSERT_NE(nullptr, maskrs_); EXPECT_FALSE(maskrs_->PositionsCalculated()); EXPECT_EQ(maskrs_->GetRasterPositionDataPointer(), nullptr); + EXPECT_EQ(maskrs_->GetRasterPositionIndexPointer(), nullptr); maskrs_->SetCalcPositions(); EXPECT_TRUE(maskrs_->PositionsCalculated()); EXPECT_NE(maskrs_->GetRasterPositionDataPointer(), nullptr); + EXPECT_NE(maskrs_->GetRasterPositionIndexPointer(), nullptr); // Mask data that do not matched exactly maskrs2_ = IntRaster::Init(GetParam()->mask2_name, false); ASSERT_NE(nullptr, maskrs2_); EXPECT_FALSE(maskrs2_->PositionsCalculated()); EXPECT_EQ(maskrs2_->GetRasterPositionDataPointer(), nullptr); + EXPECT_EQ(maskrs2_->GetRasterPositionIndexPointer(), nullptr); maskrs2_->SetCalcPositions(); EXPECT_TRUE(maskrs2_->PositionsCalculated()); EXPECT_NE(maskrs2_->GetRasterPositionDataPointer(), nullptr); + EXPECT_NE(maskrs2_->GetRasterPositionIndexPointer(), nullptr); #ifdef USE_MONGODB client_ = GlobalEnv->client_; gfs_ = GlobalEnv->gfs_; @@ -163,6 +167,7 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactNoPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -317,9 +322,12 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactNoPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -387,6 +395,7 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactNoPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -542,9 +551,12 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactNoPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -594,6 +606,7 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactCalPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /// Test members after constructing. EXPECT_EQ(2, rs_->GetDataLength()); // m_nCells, which will be nRows * nCols @@ -741,9 +754,12 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactCalPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -791,6 +807,7 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactCalPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /// Set to use the extent of mask data rs_->SetUseMaskExt(); @@ -940,9 +957,12 @@ TEST_P(clsRasterDataTestMaskWithin, MatchExactCalPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -995,6 +1015,7 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactNoPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1137,9 +1158,12 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactNoPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, true, @@ -1196,6 +1220,7 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactNoPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1338,9 +1363,12 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactNoPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, @@ -1397,6 +1425,7 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactCalcPosNoMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1536,9 +1565,12 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactCalcPosNoMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -1594,6 +1626,7 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactCalcPosUseMaskExt) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -1733,9 +1766,12 @@ TEST_P(clsRasterDataTestMaskWithin, NotMatchExactCalcPosUseMaskExt) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(copyrs->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; - copyrs->GetRasterPositionData(&poslen, &posdata); + rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); diff --git a/test/raster/test_raster1d_nomask.cpp b/test/raster/test_raster1d_nomask.cpp index 57872388ae..d834ffb172 100644 --- a/test/raster/test_raster1d_nomask.cpp +++ b/test/raster/test_raster1d_nomask.cpp @@ -93,6 +93,7 @@ TEST_P(clsRasterDataTestNoMask, RasterIO) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_EQ(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_EQ(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -271,9 +272,12 @@ TEST_P(clsRasterDataTestNoMask, RasterIO) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -307,6 +311,7 @@ TEST_P(clsRasterDataTestNoMask, RasterIOWithCalcPos) { EXPECT_TRUE(rs_->PositionsCalculated()); EXPECT_TRUE(rs_->PositionsAllocated()); EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); EXPECT_EQ(6, ncells); EXPECT_NE(nullptr, positions); @@ -345,6 +350,7 @@ TEST_P(clsRasterDataTestNoMask, RasterIOWithCalcPos) { EXPECT_NE(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -512,9 +518,12 @@ TEST_P(clsRasterDataTestNoMask, RasterIOWithCalcPos) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); diff --git a/test/raster/test_raster1d_split_merge.cpp b/test/raster/test_raster1d_split_merge.cpp index d324a74953..e35fd7ed7a 100644 --- a/test/raster/test_raster1d_split_merge.cpp +++ b/test/raster/test_raster1d_split_merge.cpp @@ -338,6 +338,7 @@ TEST_P(clsRasterDataSplitMerge, MaskLyrIO) { for (int i = 0; i < full->n_cells; i++) { EXPECT_EQ(full->local_pos_[i][0], valid->local_pos_[i][0]); EXPECT_EQ(full->local_pos_[i][1], valid->local_pos_[i][1]); + EXPECT_EQ(full->local_posidx_[i], valid->local_posidx_[i]); EXPECT_DOUBLE_EQ(full->data_[i], valid->data_[i]); } } diff --git a/test/raster/test_raster2d_mask.cpp b/test/raster/test_raster2d_mask.cpp index af6a02761d..42e30efb38 100644 --- a/test/raster/test_raster2d_mask.cpp +++ b/test/raster/test_raster2d_mask.cpp @@ -148,6 +148,7 @@ TEST_P(clsRasterDataTestMask2D, NoPos) { EXPECT_EQ(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_NE(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -347,9 +348,12 @@ TEST_P(clsRasterDataTestMask2D, NoPos) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; maskrs_->GetRasterPositionData(&poslen, &posdata); + maskrs_->GetRasterPositionData(&poslen, &posidx); mongors_valid->SetPositions(poslen, posdata); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, @@ -397,6 +401,7 @@ TEST_P(clsRasterDataTestMask2D, CalcPos) { EXPECT_EQ(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_NE(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /// Test members after constructing. EXPECT_EQ(6, rs_->GetDataLength()); // m_nCells * n_lyrs_ @@ -603,9 +608,12 @@ TEST_P(clsRasterDataTestMask2D, CalcPos) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; maskrs_->GetRasterPositionData(&poslen, &posdata); + maskrs_->GetRasterPositionData(&poslen, &posidx); mongors_valid->SetPositions(poslen, posdata); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); diff --git a/test/raster/test_raster2d_nomask.cpp b/test/raster/test_raster2d_nomask.cpp index b2f9796baf..52d7c09594 100644 --- a/test/raster/test_raster2d_nomask.cpp +++ b/test/raster/test_raster2d_nomask.cpp @@ -112,6 +112,7 @@ TEST_P(clsRasterDataTest2DNoMask, RasterIO) { EXPECT_EQ(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_NE(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_EQ(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_EQ(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -415,9 +416,12 @@ TEST_P(clsRasterDataTest2DNoMask, RasterIO) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); @@ -454,6 +458,7 @@ TEST_P(clsRasterDataTest2DNoMask, RasterIOWithCalcPos) { EXPECT_TRUE(rs_->PositionsCalculated()); EXPECT_TRUE(rs_->PositionsAllocated()); EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); EXPECT_EQ(6, ncells); EXPECT_NE(nullptr, positions); @@ -490,6 +495,7 @@ TEST_P(clsRasterDataTest2DNoMask, RasterIOWithCalcPos) { EXPECT_EQ(nullptr, rs_->GetRasterDataPointer()); // m_rasterData EXPECT_NE(nullptr, rs_->Get2DRasterDataPointer()); // m_raster2DData EXPECT_NE(nullptr, rs_->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_NE(nullptr, rs_->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ STRDBL_MAP header_info = rs_->GetRasterHeader(); @@ -747,9 +753,12 @@ TEST_P(clsRasterDataTest2DNoMask, RasterIOWithCalcPos) { FltRaster* mongors_valid = new FltRaster(); // create empty raster, set and read data mongors_valid->SetHeader(rs_->GetRasterHeader()); // set header int** posdata; + int* posidx; int poslen; rs_->GetRasterPositionData(&poslen, &posdata); mongors_valid->SetPositions(poslen, posdata); + rs_->GetRasterPositionData(&poslen, &posidx); + mongors_valid->SetPositions(poslen, posidx); STRING_MAP opts; UpdateStringMap(opts, HEADER_INC_NODATA, "FALSE"); mongors_valid->ReadFromMongoDB(gfs_, gfsfilename_valid, false, nullptr, true, NODATA_VALUE, opts); diff --git a/test/raster/test_raster2d_split_merge.cpp b/test/raster/test_raster2d_split_merge.cpp index f34c545bb8..3ea203940f 100644 --- a/test/raster/test_raster2d_split_merge.cpp +++ b/test/raster/test_raster2d_split_merge.cpp @@ -393,6 +393,7 @@ TEST_P(clsRasterData2DSplitMerge, MaskLyrIO) { for (int i = 0; i < full->n_cells; i++) { EXPECT_EQ(full->local_pos_[i][0], valid->local_pos_[i][0]); EXPECT_EQ(full->local_pos_[i][1], valid->local_pos_[i][1]); + EXPECT_EQ(full->local_posidx_[i], valid->local_posidx_[i]); for (int l = 0; l < newlyrs; l++) { EXPECT_DOUBLE_EQ(full->data2d_[i][l], valid->data2d_[i][l]); } diff --git a/test/raster/test_raster_constructor.cpp b/test/raster/test_raster_constructor.cpp index 0da40593a5..0cebde5838 100644 --- a/test/raster/test_raster_constructor.cpp +++ b/test/raster/test_raster_constructor.cpp @@ -78,6 +78,7 @@ TEST(clsRasterDataTestBlankCtor, ValidateAccess) { EXPECT_EQ(nullptr, rs->GetRasterDataPointer()); // m_rasterData EXPECT_EQ(nullptr, rs->Get2DRasterDataPointer()); // m_raster2DData EXPECT_EQ(nullptr, rs->GetRasterPositionDataPointer()); // m_rasterPositionData + EXPECT_EQ(nullptr, rs->GetRasterPositionIndexPointer()); // m_rasterPositionIndex /** Get metadata, m_headers **/ EXPECT_EQ(-9999, rs->GetRows());