diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp index 353e134bc565320d2f6fb87caad3247c6ef0de0e..3400a123b50de930e7cf4e479c1a6fd14c334f4d 100644 --- a/FileIO/AsciiRasterInterface.cpp +++ b/FileIO/AsciiRasterInterface.cpp @@ -14,6 +14,7 @@ #include "AsciiRasterInterface.h" #include <logog/include/logog.hpp> +#include <boost/optional.hpp> #include "BaseLib/FileTools.h" #include "BaseLib/StringTools.h" @@ -226,4 +227,16 @@ bool allRastersExist(std::vector<std::string> const& raster_paths) } return true; } + +boost::optional<std::vector<GeoLib::Raster const*>> readRasters( + std::vector<std::string> const& raster_paths) +{ + if (!allRastersExist(raster_paths)) return boost::none; + + std::vector<GeoLib::Raster const*> rasters; + rasters.reserve(raster_paths.size()); + for (auto const& path : raster_paths) + rasters.push_back(FileIO::AsciiRasterInterface::readRaster(path)); + return boost::make_optional(rasters); +} } diff --git a/FileIO/AsciiRasterInterface.h b/FileIO/AsciiRasterInterface.h index 5243f522a5b403c4fb4fcfac7019e7aaa6ad4419..6f87111b0dfd1dc7dfa758d67a59f44a296df63b 100644 --- a/FileIO/AsciiRasterInterface.h +++ b/FileIO/AsciiRasterInterface.h @@ -15,6 +15,9 @@ #define ASCIIRASTERINTERFACE_H_ #include <fstream> +#include <vector> +#include <string> +#include <boost/optional.hpp> #include "GeoLib/Raster.h" @@ -49,6 +52,11 @@ private: double &min, double &max); }; +/// Reads a vector of rasters given by file names. On error nothing is returned, +/// otherwise the returned vector contains pointers to the read rasters. +boost::optional<std::vector<GeoLib::Raster const*>> readRasters( + std::vector<std::string> const& raster_paths); + /// Checks if all raster files actually exist bool allRastersExist(std::vector<std::string> const& raster_paths);