26{
27 TCLAP::CmdLine cmd(
28 "Assigns the pixel information of a raster file to a scalar array of a "
29 "specified 2D mesh. Data will be assigned to a node array by default. "
30 "Adding information to cell arrays is also possible, pixel values at "
31 "the centre of the cell will be used in this case. Note that large "
32 "differences in resolution between cell size of the mesh and pixel "
33 "size of the raster can give unexpected results. A no-data value will "
34 "be added in case of missing or transparent values.\n\n"
35 "OpenGeoSys-6 software, version " +
37 ".\n"
38 "Copyright (c) 2012-2024, OpenGeoSys Community "
39 "(http://www.opengeosys.org)",
41
42 TCLAP::ValueArg<double> nodata_arg(
43 "e", "nodata", "The no data value used for missing values", false, 0,
44 "a number");
45 cmd.add(nodata_arg);
46
47 TCLAP::SwitchArg set_cells_arg("c", "cell-array",
48 "Assigns raster data to cell array");
49 cmd.add(set_cells_arg);
50
51 TCLAP::SwitchArg set_nodes_arg(
52 "n", "node-array", "Assigns raster data to node array (default)");
53 cmd.add(set_nodes_arg);
54
55 TCLAP::ValueArg<std::string> array_name_arg(
56 "s", "scalar-name", "The name of the newly created scalar array.", true,
57 "", "scalar array name");
58 cmd.add(array_name_arg);
59 TCLAP::ValueArg<std::string> raster_arg("r", "raster",
60 "Name of the input raster (*.asc)",
61 true, "", "raster file name");
62 cmd.add(raster_arg);
63
64 TCLAP::ValueArg<std::string> output_arg("o", "output",
65 "Name of the output mesh (*.vtu)",
66 true, "", "output file name");
67 cmd.add(output_arg);
68 TCLAP::ValueArg<std::string> input_arg("i", "input",
69 "Name of the input mesh (*.vtu)",
70 true, "", "input file name");
71 cmd.add(input_arg);
72 cmd.parse(argc, argv);
73
75
76 bool const create_cell_array(set_cells_arg.isSet());
77 bool const create_node_array =
78 (create_cell_array) ? set_nodes_arg.isSet() : true;
79
80 std::string const& mesh_name = input_arg.getValue();
81 std::string const& output_name = output_arg.getValue();
82 std::string const& raster_name = raster_arg.getValue();
83
84 std::unique_ptr<MeshLib::Mesh> const mesh(
86 if (mesh->getDimension() > 2)
87 {
88 ERR(
"Method can not be applied to 3D meshes.");
89 return EXIT_FAILURE;
90 }
91
92 std::unique_ptr<GeoLib::Raster> const raster(
94
95 if (create_node_array)
96 {
98 *mesh, *raster, nodata_arg.getValue(), array_name_arg.getValue());
99
100 if (!assigned)
101 {
102 ERR(
"Error assigning raster data to scalar node array");
103 return EXIT_FAILURE;
104 }
105 INFO(
"Created node array {:s}", array_name_arg.getValue());
106 }
107
108 if (create_cell_array)
109 {
111 *mesh, *raster, nodata_arg.getValue(), array_name_arg.getValue());
112
113 if (!assigned)
114 {
115 ERR(
"Error assigning raster data to scalar cell array");
116 return EXIT_FAILURE;
117 }
118 INFO(
"Created cell array {:s}", array_name_arg.getValue());
119 }
120
122 vtu.writeToFile(output_name);
123 return EXIT_SUCCESS;
124}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... 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 const compute_element_neighbors)