24int main(
int argc,
char* argv[])
27 "Takes two DEMs located at the exact same spatial position (but at "
28 "different elevation) and calculates n raster DEMs located at "
29 "equidistant intervals between them (i.e. for n=1, one new raster "
30 "located precisely in the middle will be created).\n\n"
31 "OpenGeoSys-6 software, version " +
34 "Copyright (c) 2012-2024, OpenGeoSys Community "
35 "(http://www.opengeosys.org)",
37 TCLAP::ValueArg<std::size_t> number_arg(
38 "n",
"number",
"number of rasters to be calculated",
false, 1,
"int");
40 TCLAP::ValueArg<std::string> output_arg(
"o",
"output-file",
41 "Raster output file (*.asc)",
true,
44 TCLAP::ValueArg<std::string> input2_arg(
45 "",
"file2",
"Second DEM-raster file",
true,
"",
"file2.asc");
47 TCLAP::ValueArg<std::string> input1_arg(
48 "",
"file1",
"First DEM-raster file",
true,
"",
"file1.asc");
51 cmd.parse(argc, argv);
54 MPI_Init(&argc, &argv);
57 std::unique_ptr<GeoLib::Raster> dem1(
59 std::unique_ptr<GeoLib::Raster> dem2(
62 if (dem1 ==
nullptr || dem2 ==
nullptr)
73 bool errors_found(
false);
76 ERR(
"Origin x-coordinate is not the same in both raster files.\n");
81 ERR(
"Origin y-coordinate is not the same in both raster files.\n");
86 ERR(
"Cellsize is not the same in both raster files.\n");
91 ERR(
"Raster width is not the same in both raster files.\n");
96 ERR(
"Raster height is not the same in both raster files.\n");
108 std::size_t
const n = number_arg.getValue();
109 std::vector<std::vector<double>> raster;
110 for (std::size_t i = 0; i < n; ++i)
112 std::vector<double> r;
117 auto it2 = dem2->begin();
118 for (
auto it1 = dem1->begin(); it1 != dem1->end(); ++it1)
120 if (it2 == dem2->end())
122 ERR(
"Error: File 2 is shorter than File 1.");
130 for (std::size_t i = 0; i < n; ++i)
132 raster[i].push_back(h1.
no_data);
137 double const min = std::min(*it1, *it2);
138 double const max = std::max(*it1, *it2);
139 double const step = (max - min) /
static_cast<double>(n + 1);
140 for (std::size_t i = 0; i < n; ++i)
142 raster[i].push_back(max - ((i + 1) * step));
147 if (it2 != dem2->end())
149 ERR(
"Error: File 1 is shorter than File 2.");
156 std::string
const filename = output_arg.getValue();
157 for (std::size_t i = 0; i < n; ++i)
164 r, basename + std::to_string(i) + ext);
165 INFO(
"Layer {:d} written.", i + 1);