23int main(
int argc,
char* argv[])
26 "Takes two DEMs located at the exact same spatial position (but at "
27 "different elevation) and calculates n raster DEMs located at "
28 "equidistant intervals between them (i.e. for n=1, one new raster "
29 "located precisely in the middle will be created).\n\n"
30 "OpenGeoSys-6 software, version " +
33 "Copyright (c) 2012-2025, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36 TCLAP::ValueArg<std::size_t> number_arg(
38 "number of rasters to be calculated, "
42 TCLAP::ValueArg<std::string> output_arg(
"o",
"output-file",
43 "Output (.asc). Raster output file",
44 true,
"",
"OUTPUT_FILE");
46 TCLAP::ValueArg<std::string> input2_arg(
47 "",
"file2",
"Input (.asc). Second DEM-raster input file",
true,
"",
50 TCLAP::ValueArg<std::string> input1_arg(
51 "",
"file1",
"Input (.asc) First DEM-raster input file",
true,
"",
55 cmd.add(log_level_arg);
57 cmd.parse(argc, argv);
62 std::unique_ptr<GeoLib::Raster> dem1(
64 std::unique_ptr<GeoLib::Raster> dem2(
67 if (dem1 ==
nullptr || dem2 ==
nullptr)
75 bool errors_found(
false);
78 ERR(
"Origin x-coordinate is not the same in both raster files.\n");
83 ERR(
"Origin y-coordinate is not the same in both raster files.\n");
88 ERR(
"Cellsize is not the same in both raster files.\n");
93 ERR(
"Raster width is not the same in both raster files.\n");
98 ERR(
"Raster height is not the same in both raster files.\n");
107 std::size_t
const n = number_arg.getValue();
108 std::vector<std::vector<double>> raster;
109 for (std::size_t i = 0; i < n; ++i)
111 std::vector<double> r;
116 auto it2 = dem2->begin();
117 for (
auto it1 = dem1->begin(); it1 != dem1->end(); ++it1)
119 if (it2 == dem2->end())
121 ERR(
"Error: File 2 is shorter than File 1.");
126 for (std::size_t i = 0; i < n; ++i)
128 raster[i].push_back(h1.
no_data);
133 double const min = std::min(*it1, *it2);
134 double const max = std::max(*it1, *it2);
135 double const step = (max - min) /
static_cast<double>(n + 1);
136 for (std::size_t i = 0; i < n; ++i)
138 raster[i].push_back(max - ((i + 1) * step));
143 if (it2 != dem2->end())
145 ERR(
"Error: File 1 is shorter than File 2.");
149 std::string
const filename = output_arg.getValue();
150 for (std::size_t i = 0; i < n; ++i)
157 r, basename + std::to_string(i) + ext);
158 INFO(
"Layer {:d} written.", i + 1);