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

Commit

Permalink
Merge pull request #42 from umr-dbs/no-raster-for-given-time-un-confi…
Browse files Browse the repository at this point in the history
…dential

make NoRasterForGivenTimeException visible to the user
  • Loading branch information
jdroenner authored Jun 25, 2020
2 parents ffdef62 + 5bef6bd commit 1651e1c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/rasterdb/backend_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ RasterDBBackend::RasterDescription LocalRasterDBBackend::getClosestRaster(int ch
stmt.bind(1, channelid);
stmt.bind(2, t1);
stmt.bind(3, t2);
if (!stmt.next())
throw NoRasterForGivenTimeException( concat("No raster found for the given time (source=", sourcename, ", channel=", channelid, ", time=", t1, "-", t2, ")"));
if (!stmt.next()) {
throw NoRasterForGivenTimeException(
concat("No raster found for the given time (source=", sourcename, ", channel=", channelid, ", time=", t1, "-", t2, ")"),
MappingExceptionType::PERMANENT
);
}

auto rasterid = stmt.getInt64(0);
double time_start = stmt.getDouble(1);
Expand Down
25 changes: 16 additions & 9 deletions src/util/gdal_timesnap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ ptime GDALTimesnap::snapToInterval(TimeUnit snapUnit, int intervalValue, ptime s



// calculates the filename for queried time by snapping the wanted time to the
// calculates the filename for queried time by snapping the wanted time to the
// nearest smaller timestamp that exists for the dataset
// TODO: move general parameter parsing to a more appropriate function
GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value datasetJson, int channel, const TemporalReference &tref)
{
// get parameters
Json::Value channelJson = datasetJson["channels"][channel];

// get parameters
std::string time_format = channelJson.get("time_format", datasetJson.get("time_format", "")).asString();
std::string time_start = channelJson.get("time_start", datasetJson.get("time_start", "")).asString();
Expand All @@ -129,7 +129,7 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
", fileName: ", fileName
)
);

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

// resolve time
Expand All @@ -154,8 +154,12 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d

//check if requested time is in range of dataset timestamps
//a dataset only has start not end time. if wantedtime is past the last file of dataset, it can simply not be loaded.
if(wantedTimeUnix < time_start_mapping || wantedTimeUnix > time_end_mapping)
throw NoRasterForGivenTimeException("Requested time is not in range of dataset");
if(wantedTimeUnix < time_start_mapping || wantedTimeUnix > time_end_mapping) {
throw NoRasterForGivenTimeException(
"Requested time is not in range of dataset",
MappingExceptionType::PERMANENT
);
}

if(datasetJson.isMember("time_interval") || channelJson.isMember("time_interval")) {
Json::Value timeInterval = channelJson.get("time_interval", datasetJson.get("time_interval", Json::Value(Json::objectValue)));
Expand Down Expand Up @@ -231,11 +235,14 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
break;
}
}

if (time_channel <= 0) {
throw NoRasterForGivenTimeException("No channel corresponds to the requested time");
throw NoRasterForGivenTimeException(
"No channel corresponds to the requested time",
MappingExceptionType::PERMANENT
);
}

Log::debug(concat("getDataLoadingInfo: setting channel to: ", time_channel, " (was: ", channel,") for time: ", wantedTimeUnix));
channel = time_channel;
}
Expand All @@ -259,7 +266,7 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
boost::filesystem::path file_path(path);
file_path /= fileName;
std::string dataset_file_path = file_path.string();
Log::debug(concat("getDataLoadingInfo: file_path: ", file_path));
Log::debug(concat("getDataLoadingInfo: file_path: ", file_path));

// Handle NetCDF subdatasets
if (channelJson.isMember("netcdf_subdataset") || datasetJson.isMember("netcdf_subdataset")) {
Expand Down

0 comments on commit 1651e1c

Please sign in to comment.