From d4f2094fe64fc1f49d75a9f442635979d9ffaf76 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Thu, 14 Apr 2016 21:26:01 +0200 Subject: [PATCH] [IO] Add readRasters() for reading all rasters. --- FileIO/AsciiRasterInterface.cpp | 13 +++++++++++++ FileIO/AsciiRasterInterface.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp index 353e134bc56..3400a123b50 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 5243f522a5b..6f87111b0df 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); -- GitLab