27 "Assigns the pixel information of a raster file to a scalar array of a "
28 "specified 2D mesh. Data will be assigned to a node array by default. "
29 "Adding information to cell arrays is also possible, pixel values at "
30 "the centre of the cell will be used in this case. Note that large "
31 "differences in resolution between cell size of the mesh and pixel "
32 "size of the raster can give unexpected results. A no-data value will "
33 "be added in case of missing or transparent values.\n\n"
34 "OpenGeoSys-6 software, version " +
37 "Copyright (c) 2012-2021, OpenGeoSys Community "
38 "(http://www.opengeosys.org)",
41 TCLAP::ValueArg<double> nodata_arg(
42 "e",
"nodata",
"The no data value used for missing values",
false, 0,
46 TCLAP::SwitchArg set_cells_arg(
"c",
"cell-array",
47 "Assigns raster data to cell array");
48 cmd.add(set_cells_arg);
50 TCLAP::SwitchArg set_nodes_arg(
51 "n",
"node-array",
"Assigns raster data to node array (default)");
52 cmd.add(set_nodes_arg);
54 TCLAP::ValueArg<std::string> array_name_arg(
55 "s",
"scalar-name",
"The name of the newly created scalar array.",
true,
56 "",
"scalar array name");
57 cmd.add(array_name_arg);
58 TCLAP::ValueArg<std::string> raster_arg(
"r",
"raster",
59 "Name of the input raster (*.asc)",
60 true,
"",
"raster file name");
63 TCLAP::ValueArg<std::string> output_arg(
"o",
"output",
64 "Name of the output mesh (*.vtu)",
65 true,
"",
"output file name");
67 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
68 "Name of the input mesh (*.vtu)",
69 true,
"",
"input file name");
71 cmd.parse(argc, argv);
73 bool const create_cell_array(set_cells_arg.isSet());
74 bool const create_node_array =
75 (create_cell_array) ? set_nodes_arg.isSet() :
true;
77 std::string
const& mesh_name = input_arg.getValue();
78 std::string
const& output_name = output_arg.getValue();
79 std::string
const& raster_name = raster_arg.getValue();
81 std::unique_ptr<MeshLib::Mesh>
const mesh(
83 if (mesh->getDimension() > 2)
85 ERR(
"Method can not be applied to 3D meshes.");
89 std::unique_ptr<GeoLib::Raster>
const raster(
92 if (create_node_array)
95 *mesh, *raster, nodata_arg.getValue(), array_name_arg.getValue());
99 ERR(
"Error assigning raster data to scalar node array");
102 INFO(
"Created node array {:s}", array_name_arg.getValue());
105 if (create_cell_array)
108 *mesh, *raster, nodata_arg.getValue(), array_name_arg.getValue());
112 ERR(
"Error assigning raster data to scalar cell array");
115 INFO(
"Created cell array {:s}", array_name_arg.getValue());
119 vtu.writeToFile(output_name);
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
bool projectToElements(MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name)
bool projectToNodes(MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name)