62{
63 TCLAP::CmdLine cmd(
64 "Add values to raster.\n\n"
65 "OpenGeoSys-6 software, version " +
67 ".\n"
68 "Copyright (c) 2012-2026, OpenGeoSys Community "
69 "(http://www.opengeosys.org)",
71
72 TCLAP::ValueArg<std::string> out_raster_arg(
73 "o",
74 "output_raster",
75 "Output (.asc). The output raster is stored to a file of this name",
76 true,
77 "",
78 "OUTPUT_FILE");
79 cmd.add(out_raster_arg);
80
81 TCLAP::ValueArg<double> scaling_arg(
82 "",
83 "scaling_value",
84 "value the function sin(x pi) sin(y pi) will be scaled with",
85 false,
86 1,
87 "SCALING");
88 cmd.add(scaling_arg);
89
90 TCLAP::ValueArg<double> offset_arg(
91 "",
92 "offset_value",
93 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
94 false,
95 0,
96 "OFFSET");
97 cmd.add(offset_arg);
98
99 TCLAP::ValueArg<double> ll_x_arg(
100 "",
101 "ll_x",
102 "x coordinate of lower left point of axis aligned rectangular region",
103 false,
104 0,
105 "LL_X");
106 cmd.add(ll_x_arg);
107 TCLAP::ValueArg<double> ll_y_arg(
108 "",
109 "ll_y",
110 "y coordinate of lower left point of axis aligned rectangular region",
111 false,
112 0,
113 "LL_Y");
114 cmd.add(ll_y_arg);
115 TCLAP::ValueArg<double> ur_x_arg("",
116 "ur_x",
117 "x coordinate of the upper right point of "
118 "axis aligned rectangular region",
119 false,
120 0,
121 "UR_X");
122 cmd.add(ur_x_arg);
123 TCLAP::ValueArg<double> ur_y_arg("",
124 "ur_y",
125 "y coordinate of the upper right point of "
126 "axis aligned rectangular region",
127 false,
128 0,
129 "UR_Y");
130
131 cmd.add(ur_y_arg);
132 std::vector<std::string> allowed_functions_vector{"sinxsiny", "exp",
133 "step"};
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",
141 "Input (.asc). "
142 "Name of the input raster file",
143 true, "", "INPUT_FILE");
144 cmd.add(input_arg);
145
147 cmd.add(log_level_arg);
148 cmd.parse(argc, argv);
149
152
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)};
157
158 auto const s = scaling_arg.getValue();
159 auto const offset = offset_arg.getValue();
160
161 std::unique_ptr<GeoLib::Raster> const raster(
163 input_arg.getValue()));
164 auto const& header = raster->getHeader();
165 auto const& origin = header.origin;
166
167 auto function_selector = [](std::string const& function_string)
170 {
171 if (function_string == "sinxsiny")
172 {
174 }
175 if (function_string == "exp")
176 {
178 }
179 if (function_string == "step")
180 {
182 }
183 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
184 };
186 computeFunctionValue = function_selector(function_arg.getValue());
187
188 for (std::size_t r = 0; r < header.n_rows; r++)
189 {
190 for (std::size_t c = 0;
c < header.n_cols;
c++)
191 {
193 origin[1] + header.cell_size * (r + 0.5),
194 0.0}};
195 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
196 {
197 continue;
198 }
199
200 (*raster)(r,
c) += offset + s * computeFunctionValue(p, aabb);
201 }
202 }
203
205 out_raster_arg.getValue());
206 return EXIT_SUCCESS;
207}
double computeSinXSinY(GeoLib::Point const &point, GeoLib::AABB const &aabb)
double compute2DGaussBellCurveValues(GeoLib::Point const &point, GeoLib::AABB const &aabb)
double computeStepFunction(GeoLib::Point const &point, GeoLib::AABB const &aabb)
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
bool containsPoint(T const &pnt, double eps) const
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version