69{
70 TCLAP::CmdLine cmd(
71 "Add values to raster.\n\n"
72 "OpenGeoSys-6 software, version " +
74 ".\n"
75 "Copyright (c) 2012-2025, OpenGeoSys Community "
76 "(http://www.opengeosys.org)",
78
79 TCLAP::ValueArg<std::string> out_raster_arg(
80 "o",
81 "output_raster",
82 "Output (.asc). The output raster is stored to a file of this name",
83 true,
84 "",
85 "OUTPUT_FILE");
86 cmd.add(out_raster_arg);
87
88 TCLAP::ValueArg<double> scaling_arg(
89 "",
90 "scaling_value",
91 "value the function sin(x pi) sin(y pi) will be scaled with",
92 false,
93 1,
94 "SCALING");
95 cmd.add(scaling_arg);
96
97 TCLAP::ValueArg<double> offset_arg(
98 "",
99 "offset_value",
100 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
101 false,
102 0,
103 "OFFSET");
104 cmd.add(offset_arg);
105
106 TCLAP::ValueArg<double> ll_x_arg(
107 "",
108 "ll_x",
109 "x coordinate of lower left point of axis aligned rectangular region",
110 false,
111 0,
112 "LL_X");
113 cmd.add(ll_x_arg);
114 TCLAP::ValueArg<double> ll_y_arg(
115 "",
116 "ll_y",
117 "y coordinate of lower left point of axis aligned rectangular region",
118 false,
119 0,
120 "LL_Y");
121 cmd.add(ll_y_arg);
122 TCLAP::ValueArg<double> ur_x_arg("",
123 "ur_x",
124 "x coordinate of the upper right point of "
125 "axis aligned rectangular region",
126 false,
127 0,
128 "UR_X");
129 cmd.add(ur_x_arg);
130 TCLAP::ValueArg<double> ur_y_arg("",
131 "ur_y",
132 "y coordinate of the upper right point of "
133 "axis aligned rectangular region",
134 false,
135 0,
136 "UR_Y");
137
138 cmd.add(ur_y_arg);
139 std::vector<std::string> allowed_functions_vector{"sinxsiny", "exp",
140 "step"};
141 TCLAP::ValuesConstraint<std::string> allowed_functions(
142 allowed_functions_vector);
143 TCLAP::ValueArg<std::string> function_arg(
144 "f", "function", "Name of the function used to modify the raster", true,
145 "", &allowed_functions);
146 cmd.add(function_arg);
147 TCLAP::ValueArg<std::string> input_arg("i", "input",
148 "Input (.asc). "
149 "Name of the input raster file",
150 true, "", "INPUT_FILE");
151 cmd.add(input_arg);
152
154 cmd.add(log_level_arg);
155 cmd.parse(argc, argv);
156
159
160 std::array input_points = {
161 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
162 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
163 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
164
165 auto const s = scaling_arg.getValue();
166 auto const offset = offset_arg.getValue();
167
168 std::unique_ptr<GeoLib::Raster> const raster(
170 input_arg.getValue()));
171 auto const& header = raster->getHeader();
172 auto const& origin = header.origin;
173
174 auto function_selector = [](std::string const& function_string)
177 {
178 if (function_string == "sinxsiny")
179 {
181 }
182 if (function_string == "exp")
183 {
185 }
186 if (function_string == "step")
187 {
189 }
190 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
191 };
193 computeFunctionValue = function_selector(function_arg.getValue());
194
195 for (std::size_t r = 0; r < header.n_rows; r++)
196 {
197 for (std::size_t c = 0;
c < header.n_cols;
c++)
198 {
200 origin[1] + header.cell_size * (r + 0.5),
201 0.0}};
202 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
203 {
204 continue;
205 }
206
207 (*raster)(r,
c) += offset + s * computeFunctionValue(p, aabb);
208 }
209 }
210
212 out_raster_arg.getValue());
213 return EXIT_SUCCESS;
214}
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