10 #include <tclap/CmdLine.h>
20 int main(
int argc,
char* argv[])
23 "Takes two DEMs located at the exact same spatial position (but at "
24 "different elevation) and calculates n raster DEMs located at "
25 "equidistant intervals between them (i.e. for n=1, one new raster "
26 "located precisely in the middle will be created).\n\n"
27 "OpenGeoSys-6 software, version " +
30 "Copyright (c) 2012-2021, OpenGeoSys Community "
31 "(http://www.opengeosys.org)",
33 TCLAP::ValueArg<std::size_t> number_arg(
34 "n",
"number",
"number of rasters to be calculated",
false, 1,
"int");
36 TCLAP::ValueArg<std::string> output_arg(
"o",
"output-file",
37 "Raster output file (*.asc)",
true,
40 TCLAP::ValueArg<std::string> input2_arg(
41 "",
"file2",
"Second DEM-raster file",
true,
"",
"file2.asc");
43 TCLAP::ValueArg<std::string> input1_arg(
44 "",
"file1",
"First DEM-raster file",
true,
"",
"file1.asc");
47 cmd.parse(argc, argv);
49 std::unique_ptr<GeoLib::Raster> dem1(
51 std::unique_ptr<GeoLib::Raster> dem2(
54 if (dem1 ==
nullptr || dem2 ==
nullptr)
62 bool errors_found(
false);
65 ERR(
"Origin x-coordinate is not the same in both raster files.\n");
70 ERR(
"Origin y-coordinate is not the same in both raster files.\n");
75 ERR(
"Cellsize is not the same in both raster files.\n");
80 ERR(
"Raster width is not the same in both raster files.\n");
85 ERR(
"Raster height is not the same in both raster files.\n");
94 std::size_t
const n = number_arg.getValue();
95 std::vector<std::vector<double>> raster;
96 for (std::size_t i = 0; i < n; ++i)
98 std::vector<double>
r;
103 auto it2 = dem2->begin();
104 for (
auto it1 = dem1->begin(); it1 != dem1->end(); ++it1)
106 if (it2 == dem2->end())
108 ERR(
"Error: File 2 is shorter than File 1.");
113 for (std::size_t i = 0; i < n; ++i)
115 raster[i].push_back(h1.
no_data);
120 double const min = std::min(*it1, *it2);
121 double const max = std::max(*it1, *it2);
122 double const step = (max - min) /
static_cast<double>(n + 1);
123 for (std::size_t i = 0; i < n; ++i)
125 raster[i].push_back(max - ((i + 1) * step));
130 if (it2 != dem2->end())
132 ERR(
"Error: File 1 is shorter than File 2.");
136 std::string
const filename = output_arg.getValue();
137 for (std::size_t i = 0; i < n; ++i)
144 r, basename + std::to_string(i) + ext);
145 INFO(
"Layer {:d} written.", i + 1);
Definition of the AsciiRasterInterface class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of the GeoLib::Raster class.
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * readRaster(std::string const &fname)
Reads raster file by detecting type based on extension and then calling the appropriate method.
Class Raster is used for managing raster data.
std::string getFileExtension(const std::string &path)
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version