diff --git a/Applications/Utils/FileConverter/CMakeLists.txt b/Applications/Utils/FileConverter/CMakeLists.txt index ae8eceb3284555752cbbd88a2e4624fee9a70376..761d8a6e8f8352e372aad047e94b1b16860a5298 100644 --- a/Applications/Utils/FileConverter/CMakeLists.txt +++ b/Applications/Utils/FileConverter/CMakeLists.txt @@ -18,6 +18,10 @@ if(OGS_BUILD_GUI) list(APPEND TOOLS FEFLOW2OGS) endif() +if(Shapelib_FOUND) + list(APPEND TOOLS Mesh2Shape) +endif() + foreach(TOOL ${TOOLS}) add_executable(${TOOL} ${TOOL}.cpp) target_link_libraries(${TOOL} ApplicationsFileIO GitInfoLib MeshLib) @@ -28,3 +32,8 @@ install(TARGETS ${TOOLS} RUNTIME DESTINATION bin COMPONENT Utilities) if(TARGET ConvertSHPToGLI) target_link_libraries(ConvertSHPToGLI GeoLib Qt5::Xml ${Shapelib_LIBRARIES}) endif() + +if(TARGET Mesh2Shape) + target_link_libraries(Mesh2Shape ${Shapelib_LIBRARIES}) +endif() + diff --git a/Applications/Utils/FileConverter/Mesh2Shape.cpp b/Applications/Utils/FileConverter/Mesh2Shape.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8fda2f7fccfb4aaadd177e917b1ffa3594aa6c3b --- /dev/null +++ b/Applications/Utils/FileConverter/Mesh2Shape.cpp @@ -0,0 +1,51 @@ +/** + * + * @copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +#include <tclap/CmdLine.h> + +#include "Applications/ApplicationsLib/LogogSetup.h" +#include "Applications/FileIO/SHPInterface.h" +#include "InfoLib/GitInfo.h" +#include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/Mesh.h" + +int main(int argc, char* argv[]) +{ + ApplicationsLib::LogogSetup logog_setup; + + TCLAP::CmdLine cmd( + "Converts 2D mesh file into shapfile such that each element is " + "represented by a polygon. Cell attributes are transferred onto shape " + "polygons while point attributes are ignored.\n\n" + "OpenGeoSys-6 software, version " + + GitInfoLib::GitInfo::ogs_version + + ".\n" + "Copyright (c) 2012-2019, OpenGeoSys Community " + "(http://www.opengeosys.org)", + ' ', GitInfoLib::GitInfo::ogs_version); + + TCLAP::ValueArg<std::string> output_arg("o", "output-file", + "Esri Shapefile (*.shp)", true, "", + "output_file.shp"); + cmd.add(output_arg); + + TCLAP::ValueArg<std::string> input_arg("i", "input-file", + "OGS mesh file (*.vtu, *.msh)", true, + "", "input_file.vtu"); + cmd.add(input_arg); + + cmd.parse(argc, argv); + + std::string const file_name(input_arg.getValue()); + std::unique_ptr<MeshLib::Mesh> const mesh( + MeshLib::IO::readMeshFromFile(file_name)); + if (FileIO::SHPInterface::write2dMeshToSHP(output_arg.getValue(), *mesh)) + return EXIT_SUCCESS; + return EXIT_FAILURE; +}