Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit f1edc94

Browse files
Merge pull request #39 from umr-dbs/gdal_handle_netcdf_subdataset
gdal source: handle netcdf subdataset and log
2 parents cd4211b + 7826122 commit f1edc94

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/operators/source/gdal_source.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "util/gdal_source_datasets.h"
88
#include "util/gdal_dataset_importer.h"
99
#include "util/configuration.h"
10+
#include "util/log.h"
1011

1112
/**
1213
* Operator that loads raster data via gdal. Loads them from imported GDAL dataset, import via GDAL dataset importer.
@@ -103,8 +104,10 @@ std::unique_ptr<GenericRaster> RasterGDALSourceOperator::getRaster(const QueryRe
103104

104105
if (gdalParams.isMember("channels")) {
105106
datasetJson = gdalParams;
107+
Log::debug("getRaster: Using gdalParams.");
106108
} else {
107109
datasetJson = GDALSourceDataSets::getDataSetDescription(sourcename);
110+
Log::debug("getRaster: Using getDataSetDescription.");
108111
}
109112

110113
GDALTimesnap::GDALDataLoadingInfo loadingInfo = GDALTimesnap::getDataLoadingInfo(datasetJson, channel, rect);
@@ -318,6 +321,7 @@ std::unique_ptr<GenericRaster> RasterGDALSourceOperator::loadDataset(const GDALT
318321
GDAL::init();
319322
std::string fileName = loadingInfo.fileName;
320323
injectParameters(fileName, qrect, tools);
324+
Log::debug(concat("loadDataset: using filename: ", fileName.c_str()));
321325

322326
auto dataset = (GDALDataset *) GDALOpen(fileName.c_str(), GA_ReadOnly);
323327

src/util/gdal_timesnap.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "gdal_timesnap.h"
22
#include <boost/filesystem.hpp>
3+
#include "util/concat.h"
4+
#include "util/log.h"
35

46
constexpr int MAX_FILE_NAME_LENGTH = 255;
57

@@ -110,14 +112,24 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
110112
{
111113
// get parameters
112114
Json::Value channelJson = datasetJson["channels"][channel];
113-
115+
116+
// get parameters
114117
std::string time_format = channelJson.get("time_format", datasetJson.get("time_format", "")).asString();
115118
std::string time_start = channelJson.get("time_start", datasetJson.get("time_start", "")).asString();
116119
std::string time_end = channelJson.get("time_end", datasetJson.get("time_end", "")).asString();
117120

118121
std::string path = channelJson.get("path", datasetJson.get("path", "")).asString();
119122
std::string fileName = channelJson.get("file_name", datasetJson.get("file_name", "")).asString();
120123

124+
Log::debug(
125+
concat("getDataLoadingInfo: time_format: ", time_format,
126+
", time_start: ", time_start,
127+
", time_end: ", time_end,
128+
", path: ", path,
129+
", fileName: ", fileName
130+
)
131+
);
132+
121133
channel = channelJson.get("channel", channel).asInt();
122134

123135
// resolve time
@@ -200,6 +212,8 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
200212
size_t placeholderPos = fileName.find(placeholder);
201213

202214
fileName = fileName.replace(placeholderPos, placeholder.length(), snappedTimeString);
215+
Log::debug(concat("getDataLoadingInfo: resulting time fileName: ", fileName.c_str()));
216+
203217
}
204218

205219

@@ -220,7 +234,17 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
220234

221235
boost::filesystem::path file_path(path);
222236
file_path /= fileName;
223-
return GDALDataLoadingInfo(file_path.string(), channel,
237+
std::string dataset_file_path = file_path.string();
238+
Log::debug(concat("getDataLoadingInfo: file_path: ", file_path));
239+
240+
// Handle NetCDF subdatasets
241+
if (channelJson.isMember("netcdf_subdataset") || datasetJson.isMember("netcdf_subdataset")) {
242+
std::string netcdf_subdataset = channelJson.get("netcdf_subdataset", datasetJson.get("netcdf_subdataset", "")).asString();
243+
dataset_file_path = concat("NETCDF:", dataset_file_path, ":", netcdf_subdataset);
244+
Log::debug(concat("getDataLoadingInfo: found NETCDF subdataset: ", netcdf_subdataset, ". Resulting path: ", dataset_file_path));
245+
}
246+
247+
return GDALDataLoadingInfo(dataset_file_path, channel,
224248
TemporalReference(TIMETYPE_UNIX, time_start_mapping, time_end_mapping),
225249
crsId, nodata, unit);
226250
}

0 commit comments

Comments
 (0)