Skip to content
Snippets Groups Projects
Commit d4f2094f authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[IO] Add readRasters() for reading all rasters.

parent 659b19c1
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "AsciiRasterInterface.h" #include "AsciiRasterInterface.h"
#include <logog/include/logog.hpp> #include <logog/include/logog.hpp>
#include <boost/optional.hpp>
#include "BaseLib/FileTools.h" #include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.h" #include "BaseLib/StringTools.h"
...@@ -226,4 +227,16 @@ bool allRastersExist(std::vector<std::string> const& raster_paths) ...@@ -226,4 +227,16 @@ bool allRastersExist(std::vector<std::string> const& raster_paths)
} }
return true; 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);
}
} }
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
#define ASCIIRASTERINTERFACE_H_ #define ASCIIRASTERINTERFACE_H_
#include <fstream> #include <fstream>
#include <vector>
#include <string>
#include <boost/optional.hpp>
#include "GeoLib/Raster.h" #include "GeoLib/Raster.h"
...@@ -49,6 +52,11 @@ private: ...@@ -49,6 +52,11 @@ private:
double &min, double &max); 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 /// Checks if all raster files actually exist
bool allRastersExist(std::vector<std::string> const& raster_paths); bool allRastersExist(std::vector<std::string> const& raster_paths);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment