61int main(
int argc,
char* argv[])
64 "Add values to raster.\n\n"
65 "OpenGeoSys-6 software, version " +
68 "Copyright (c) 2012-2026, OpenGeoSys Community "
69 "(http://www.opengeosys.org)",
72 TCLAP::ValueArg<std::string> out_raster_arg(
75 "Output (.asc). The output raster is stored to a file of this name",
79 cmd.add(out_raster_arg);
81 TCLAP::ValueArg<double> scaling_arg(
84 "value the function sin(x pi) sin(y pi) will be scaled with",
90 TCLAP::ValueArg<double> offset_arg(
93 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
99 TCLAP::ValueArg<double> ll_x_arg(
102 "x coordinate of lower left point of axis aligned rectangular region",
107 TCLAP::ValueArg<double> ll_y_arg(
110 "y coordinate of lower left point of axis aligned rectangular region",
115 TCLAP::ValueArg<double> ur_x_arg(
"",
117 "x coordinate of the upper right point of "
118 "axis aligned rectangular region",
123 TCLAP::ValueArg<double> ur_y_arg(
"",
125 "y coordinate of the upper right point of "
126 "axis aligned rectangular region",
132 std::vector<std::string> allowed_functions_vector{
"sinxsiny",
"exp",
134 TCLAP::ValuesConstraint<std::string> allowed_functions(
135 allowed_functions_vector);
136 TCLAP::ValueArg<std::string> function_arg(
137 "f",
"function",
"Name of the function used to modify the raster",
true,
138 "", &allowed_functions);
139 cmd.add(function_arg);
140 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
142 "Name of the input raster file",
143 true,
"",
"INPUT_FILE");
147 cmd.add(log_level_arg);
148 cmd.parse(argc, argv);
153 std::array input_points = {
154 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
155 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
156 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
158 auto const s = scaling_arg.getValue();
159 auto const offset = offset_arg.getValue();
161 std::unique_ptr<GeoLib::Raster>
const raster(
163 input_arg.getValue()));
164 auto const& header = raster->getHeader();
165 auto const& origin = header.origin;
167 auto function_selector = [](std::string
const& function_string)
171 if (function_string ==
"sinxsiny")
175 if (function_string ==
"exp")
179 if (function_string ==
"step")
183 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
186 computeFunctionValue = function_selector(function_arg.getValue());
188 for (std::size_t r = 0; r < header.n_rows; r++)
190 for (std::size_t c = 0; c < header.n_cols; c++)
192 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
193 origin[1] + header.cell_size * (r + 0.5),
195 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
200 (*raster)(r, c) += offset + s * computeFunctionValue(p, aabb);
205 out_raster_arg.getValue());