OGS
Raster2ASC.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#include "BaseLib/MPI.h"
16#include "GeoLib/Raster.h"
17#include "InfoLib/GitInfo.h"
18
19int main(int argc, char* argv[])
20{
21 TCLAP::CmdLine cmd(
22 "Converts ascii raster files (e.g. Surfer *.grd files or *.xyz files) "
23 "into ASC raster files.\n\n"
24 "OpenGeoSys-6 software, version " +
26 ".\n"
27 "Copyright (c) 2012-2025, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30
31 TCLAP::ValueArg<std::string> output_arg(
32 "o", "output", "Output (.asc). Filename for output raster", true, "",
33 "OUTPUT_FILE");
34 cmd.add(output_arg);
35
36 TCLAP::ValueArg<std::string> input_arg(
37 "i", "input", "Input (.grd | .xyz). Filename for input raster", true,
38 "", "INPUT_FILE");
39 cmd.add(input_arg);
40
41 cmd.parse(argc, argv);
42
43 BaseLib::MPI::Setup mpi_setup(argc, argv);
44
45 std::unique_ptr<GeoLib::Raster> raster(
46 FileIO::AsciiRasterInterface::readRaster(input_arg.getValue()));
47
48 if (raster == nullptr)
49 {
50 ERR("Couldn't read input raster file.");
51 return EXIT_FAILURE;
52 }
53
54 std::string output_name = output_arg.getValue();
55 if (output_name.substr(output_name.length() - 4, 4) != ".asc")
56 {
57 output_name = output_name.append(".asc");
58 }
59
61 return EXIT_SUCCESS;
62}
Definition of the AsciiRasterInterface class.
Git information.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
int main(int argc, char *argv[])
Definition of the GeoLib::Raster class.
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * readRaster(std::string const &fname)
GITINFOLIB_EXPORT const std::string ogs_version