From 21a15566100e6db7fc191eb82427ae0af3cbdf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Mon, 22 Jun 2020 18:46:48 +0200 Subject: [PATCH 1/2] add method to handle channels as time --- src/util/gdal_timesnap.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/util/gdal_timesnap.cpp b/src/util/gdal_timesnap.cpp index 61f0800e..25e4849e 100644 --- a/src/util/gdal_timesnap.cpp +++ b/src/util/gdal_timesnap.cpp @@ -214,6 +214,25 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d fileName = fileName.replace(placeholderPos, placeholder.length(), snappedTimeString); Log::debug(concat("getDataLoadingInfo: resulting time fileName: ", fileName.c_str())); + } else if ( + datasetJson.isMember("channel_start_time_list") + && datasetJson["channel_start_time_list"].isArray() + ) { + + Log::debug(concat("getDataLoadingInfo: using channels as time")); + + auto time_channel = 0; + auto channel_time_strings = datasetJson.get("channel_start_time_list", Json::Value(Json::ValueType::arrayValue)); + for (auto &time_string : channel_time_strings) { + auto channel_time = timeParser->parse(time_string.asString()); + if (wantedTimeUnix >= channel_time) { + time_channel += 1; + } else { + break; + } + } + Log::debug(concat("getDataLoadingInfo: setting channel to: ", time_channel, " (was ", channel,")")); + channel = time_channel; } From 77bef5a75188ab7d9ed28b75b1dcc95af9bdf696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Tue, 23 Jun 2020 15:12:02 +0200 Subject: [PATCH 2/2] add NoRasterForGivenTimeException if no match --- src/util/gdal_timesnap.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/gdal_timesnap.cpp b/src/util/gdal_timesnap.cpp index 25e4849e..6ec18f1c 100644 --- a/src/util/gdal_timesnap.cpp +++ b/src/util/gdal_timesnap.cpp @@ -222,16 +222,21 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d Log::debug(concat("getDataLoadingInfo: using channels as time")); auto time_channel = 0; - auto channel_time_strings = datasetJson.get("channel_start_time_list", Json::Value(Json::ValueType::arrayValue)); - for (auto &time_string : channel_time_strings) { - auto channel_time = timeParser->parse(time_string.asString()); + const auto channel_time_strings = datasetJson.get("channel_start_time_list", Json::Value(Json::ValueType::arrayValue)); + for (const auto &time_string : channel_time_strings) { + auto const channel_time = timeParser->parse(time_string.asString()); if (wantedTimeUnix >= channel_time) { time_channel += 1; } else { break; } } - Log::debug(concat("getDataLoadingInfo: setting channel to: ", time_channel, " (was ", channel,")")); + + if (time_channel <= 0) { + throw NoRasterForGivenTimeException("No channel corresponds to the requested time"); + } + + Log::debug(concat("getDataLoadingInfo: setting channel to: ", time_channel, " (was: ", channel,") for time: ", wantedTimeUnix)); channel = time_channel; }