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