22{
23 TCLAP::CmdLine cmd(
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 " +
30 ".\n"
31 "Copyright (c) 2012-2024, 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");
36 cmd.add(number_arg);
37 TCLAP::ValueArg<std::string> output_arg("o", "output-file",
38 "Raster output file (*.asc)", true,
39 "", "output.asc");
40 cmd.add(output_arg);
41 TCLAP::ValueArg<std::string> input2_arg(
42 "", "file2", "Second DEM-raster file", true, "", "file2.asc");
43 cmd.add(input2_arg);
44 TCLAP::ValueArg<std::string> input1_arg(
45 "", "file1", "First DEM-raster file", true, "", "file1.asc");
46 cmd.add(input1_arg);
47
48 cmd.parse(argc, argv);
49
51
52 std::unique_ptr<GeoLib::Raster> dem1(
54 std::unique_ptr<GeoLib::Raster> dem2(
56
57 if (dem1 == nullptr || dem2 == nullptr)
58 {
59 return 1;
60 }
61
64
65 bool errors_found(false);
67 {
68 ERR(
"Origin x-coordinate is not the same in both raster files.\n");
69 errors_found = true;
70 }
72 {
73 ERR(
"Origin y-coordinate is not the same in both raster files.\n");
74 errors_found = true;
75 }
77 {
78 ERR(
"Cellsize is not the same in both raster files.\n");
79 errors_found = true;
80 }
82 {
83 ERR(
"Raster width is not the same in both raster files.\n");
84 errors_found = true;
85 }
87 {
88 ERR(
"Raster height is not the same in both raster files.\n");
89 errors_found = true;
90 }
91
92 if (errors_found)
93 {
94 return 2;
95 }
96
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)
100 {
101 std::vector<double> r;
103 raster.push_back(r);
104 }
105
106 auto it2 = dem2->begin();
107 for (auto it1 = dem1->begin(); it1 != dem1->end(); ++it1)
108 {
109 if (it2 == dem2->end())
110 {
111 ERR(
"Error: File 2 is shorter than File 1.");
112 return 3;
113 }
115 {
116 for (std::size_t i = 0; i < n; ++i)
117 {
118 raster[i].push_back(h1.
no_data);
119 }
120 }
121 else
122 {
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)
127 {
128 raster[i].push_back(max - ((i + 1) * step));
129 }
130 }
131 it2++;
132 }
133 if (it2 != dem2->end())
134 {
135 ERR(
"Error: File 1 is shorter than File 2.");
136 return 3;
137 }
138
139 std::string const filename = output_arg.getValue();
140 for (std::size_t i = 0; i < n; ++i)
141 {
144
147 r, basename + std::to_string(i) + ext);
148 INFO(
"Layer {:d} written.", i + 1);
149 }
150 return EXIT_SUCCESS;
151}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
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)
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