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

Commit f16833c

Browse files
committed
gdal source: handle netcdf subdataset and log
1 parent 695cd2d commit f16833c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-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: 22 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,13 +112,19 @@ 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();
118+
Log::debug(concat("getDataLoadingInfo: time_format: ", time_format));
115119
std::string time_start = channelJson.get("time_start", datasetJson.get("time_start", "")).asString();
120+
Log::debug(concat("getDataLoadingInfo: time_start: ", time_start));
116121
std::string time_end = channelJson.get("time_end", datasetJson.get("time_end", "")).asString();
122+
Log::debug(concat("getDataLoadingInfo: time_end: ", time_end));
117123

118124
std::string path = channelJson.get("path", datasetJson.get("path", "")).asString();
125+
Log::debug(concat("getDataLoadingInfo: path: ", path));
119126
std::string fileName = channelJson.get("file_name", datasetJson.get("file_name", "")).asString();
127+
Log::debug(concat("getDataLoadingInfo: fileName: ", fileName));
120128

121129
channel = channelJson.get("channel", channel).asInt();
122130

@@ -200,6 +208,8 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
200208
size_t placeholderPos = fileName.find(placeholder);
201209

202210
fileName = fileName.replace(placeholderPos, placeholder.length(), snappedTimeString);
211+
Log::debug(concat("getDataLoadingInfo: resulting time fileName: ", fileName.c_str()));
212+
203213
}
204214

205215

@@ -220,7 +230,17 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
220230

221231
boost::filesystem::path file_path(path);
222232
file_path /= fileName;
223-
return GDALDataLoadingInfo(file_path.string(), channel,
233+
std::string dataset_file_path = file_path.string();
234+
Log::debug(concat("getDataLoadingInfo: file_path: ", file_path));
235+
236+
// Handle NetCDF subdatasets
237+
if (channelJson.isMember("netcdf_subdataset") || datasetJson.isMember("netcdf_subdataset")) {
238+
std::string netcdf_subdataset = channelJson.get("netcdf_subdataset", datasetJson.get("netcdf_subdataset", "")).asString();
239+
dataset_file_path = concat("NETCDF:", dataset_file_path, ":", netcdf_subdataset);
240+
Log::debug(concat("getDataLoadingInfo: found NETCDF subdataset: ", netcdf_subdataset, ". Resulting path: ", dataset_file_path));
241+
}
242+
243+
return GDALDataLoadingInfo(dataset_file_path, channel,
224244
TemporalReference(TIMETYPE_UNIX, time_start_mapping, time_end_mapping),
225245
crsId, nodata, unit);
226246
}

0 commit comments

Comments
 (0)