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

Commit ffdef62

Browse files
authored
add method to handle channels as time (#41)
* add method to handle channels as time * add NoRasterForGivenTimeException if no match
1 parent 9e17c55 commit ffdef62

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/util/gdal_timesnap.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,30 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
214214
fileName = fileName.replace(placeholderPos, placeholder.length(), snappedTimeString);
215215
Log::debug(concat("getDataLoadingInfo: resulting time fileName: ", fileName.c_str()));
216216

217+
} else if (
218+
datasetJson.isMember("channel_start_time_list")
219+
&& datasetJson["channel_start_time_list"].isArray()
220+
) {
221+
222+
Log::debug(concat("getDataLoadingInfo: using channels as time"));
223+
224+
auto time_channel = 0;
225+
const auto channel_time_strings = datasetJson.get("channel_start_time_list", Json::Value(Json::ValueType::arrayValue));
226+
for (const auto &time_string : channel_time_strings) {
227+
auto const channel_time = timeParser->parse(time_string.asString());
228+
if (wantedTimeUnix >= channel_time) {
229+
time_channel += 1;
230+
} else {
231+
break;
232+
}
233+
}
234+
235+
if (time_channel <= 0) {
236+
throw NoRasterForGivenTimeException("No channel corresponds to the requested time");
237+
}
238+
239+
Log::debug(concat("getDataLoadingInfo: setting channel to: ", time_channel, " (was: ", channel,") for time: ", wantedTimeUnix));
240+
channel = time_channel;
217241
}
218242

219243

0 commit comments

Comments
 (0)