21int main(
int argc,
char* argv[])
24 "Takes two DEMs located at the exact same spatial position (but at "
25 "different elevation) and calculates n raster DEMs located at "
26 "equidistant intervals between them (i.e. for n=1, one new raster "
27 "located precisely in the middle will be created).\n\n"
28 "OpenGeoSys-6 software, version " +
31 "Copyright (c) 2012-2025, OpenGeoSys Community "
32 "(http://www.opengeosys.org)",
34 TCLAP::ValueArg<std::size_t> number_arg(
35 "n",
"number",
"number of rasters to be calculated",
false, 1,
"int");
37 TCLAP::ValueArg<std::string> output_arg(
"o",
"output-file",
38 "Raster output file (*.asc)",
true,
41 TCLAP::ValueArg<std::string> input2_arg(
42 "",
"file2",
"Second DEM-raster file",
true,
"",
"file2.asc");
44 TCLAP::ValueArg<std::string> input1_arg(
45 "",
"file1",
"First DEM-raster file",
true,
"",
"file1.asc");
48 cmd.parse(argc, argv);
52 std::unique_ptr<GeoLib::Raster> dem1(
54 std::unique_ptr<GeoLib::Raster> dem2(
57 if (dem1 ==
nullptr || dem2 ==
nullptr)
65 bool errors_found(
false);
68 ERR(
"Origin x-coordinate is not the same in both raster files.\n");
73 ERR(
"Origin y-coordinate is not the same in both raster files.\n");
78 ERR(
"Cellsize is not the same in both raster files.\n");
83 ERR(
"Raster width is not the same in both raster files.\n");
88 ERR(
"Raster height is not the same in both raster files.\n");
97 std::size_t
const n = number_arg.getValue();
98 std::vector<std::vector<double>> raster;
99 for (std::size_t i = 0; i < n; ++i)
101 std::vector<double> r;
106 auto it2 = dem2->begin();
107 for (
auto it1 = dem1->begin(); it1 != dem1->end(); ++it1)
109 if (it2 == dem2->end())
111 ERR(
"Error: File 2 is shorter than File 1.");
116 for (std::size_t i = 0; i < n; ++i)
118 raster[i].push_back(h1.
no_data);
123 double const min = std::min(*it1, *it2);
124 double const max = std::max(*it1, *it2);
125 double const step = (max - min) /
static_cast<double>(n + 1);
126 for (std::size_t i = 0; i < n; ++i)
128 raster[i].push_back(max - ((i + 1) * step));
133 if (it2 != dem2->end())
135 ERR(
"Error: File 1 is shorter than File 2.");
139 std::string
const filename = output_arg.getValue();
140 for (std::size_t i = 0; i < n; ++i)
147 r, basename + std::to_string(i) + ext);
148 INFO(
"Layer {:d} written.", i + 1);