diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa47dfa29d3c48329b08fcd9966f0df2c5da186f --- /dev/null +++ b/FileIO/AsciiRasterInterface.cpp @@ -0,0 +1,219 @@ +/** + * @file AsciiRasterInterface.cpp + * @author Karsten Rink + * @date 2014-09-10 + * @brief Implementation of the AsciiRasterInterface class. + * + * @copyright + * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + */ + +#include "AsciiRasterInterface.h" + +// ThirdParty/logog +#include "logog/include/logog.hpp" + +#include "Raster.h" + +// BaseLib +#include "FileTools.h" +#include "StringTools.h" + +namespace FileIO { + +GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) +{ + std::string ext (BaseLib::getFileExtension(fname)); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + if (ext.compare("asc") == 0) + return getRasterFromASCFile(fname); + if (ext.compare("grd") == 0) + return getRasterFromSurferFile(fname); + return nullptr; +} + +GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fname) +{ + std::ifstream in(fname.c_str()); + + if (!in.is_open()) { + WARN("Raster::getRasterFromASCFile(): Could not open file %s.", fname.c_str()); + return NULL; + } + + // header information + std::size_t n_cols(0), n_rows(0); + double xllcorner(0.0), yllcorner(0.0), cell_size(0.0), no_data_val(-9999); + + if (readASCHeader(in, n_cols, n_rows, xllcorner, yllcorner, cell_size, no_data_val)) { + double* values = new double[n_cols*n_rows]; + std::string s; + // read the data into the double-array + for (size_t j(0); j < n_rows; ++j) { + const size_t idx ((n_rows - j - 1) * n_cols); + for (size_t i(0); i < n_cols; ++i) { + in >> s; + values[idx+i] = strtod(BaseLib::replaceString(",", ".", s).c_str(),0); + + } + } + in.close(); + GeoLib::Raster *raster(new GeoLib::Raster(n_cols, n_rows, xllcorner, yllcorner, + cell_size, values, values+n_cols*n_rows, no_data_val)); + delete [] values; + return raster; + } else { + WARN("Raster::getRasterFromASCFile(): Could not read header of file %s", fname.c_str()); + return NULL; + } +} + +bool AsciiRasterInterface::readASCHeader(std::ifstream &in, std::size_t &n_cols, std::size_t &n_rows, + double &xllcorner, double &yllcorner, double &cell_size, double &no_data_val) +{ + std::string tag, value; + + in >> tag; + if (tag.compare("ncols") == 0) { + in >> value; + n_cols = atoi(value.c_str()); + } else return false; + + in >> tag; + if (tag.compare("nrows") == 0) { + in >> value; + n_rows = atoi(value.c_str()); + } else return false; + + in >> tag; + if (tag.compare("xllcorner") == 0) { + in >> value; + xllcorner = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); + } else return false; + + in >> tag; + if (tag.compare("yllcorner") == 0) { + in >> value; + yllcorner = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); + } else return false; + + in >> tag; + if (tag.compare("cellsize") == 0) { + in >> value; + cell_size = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); + } else return false; + + in >> tag; + if (tag.compare("NODATA_value") == 0) { + in >> value; + no_data_val = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); + } else return false; + + return true; +} + +GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& fname) +{ + std::ifstream in(fname.c_str()); + + if (!in.is_open()) { + ERR("Raster::getRasterFromSurferFile() - Could not open file %s", fname.c_str()); + return NULL; + } + + // header information + std::size_t n_cols(0), n_rows(0); + double xllcorner(0.0), yllcorner(0.0), cell_size(0.0), min(0.0), max(0.0); + + if (readSurferHeader(in, n_cols, n_rows, xllcorner, yllcorner, cell_size, min, max)) + { + const double no_data_val (min-1); + double* values = new double[n_cols*n_rows]; + std::string s; + // read the data into the double-array + for (size_t j(0); j < n_rows; ++j) + { + const size_t idx (j * n_cols); + for (size_t i(0); i < n_cols; ++i) + { + in >> s; + const double val (strtod(BaseLib::replaceString(",", ".", s).c_str(),0)); + values[idx+i] = (val > max || val < min) ? no_data_val : val; + } + } + in.close(); + GeoLib::Raster *raster(new GeoLib::Raster(n_cols, n_rows, xllcorner, yllcorner, cell_size, + values, values+n_cols*n_rows, no_data_val)); + delete [] values; + return raster; + } else { + ERR("Raster::getRasterFromASCFile() - could not read header of file %s", fname.c_str()); + return NULL; + } +} + +bool AsciiRasterInterface::readSurferHeader(std::ifstream &in, size_t &n_cols, std::size_t &n_rows, + double &xllcorner, double &yllcorner, double &cell_size, double &min, double &max) +{ + std::string tag; + + in >> tag; + + if (tag.compare("DSAA") != 0) + { + ERR("Error in readSurferHeader() - No Surfer file."); + return false; + } + else + { + in >> n_cols >> n_rows; + in >> min >> max; + xllcorner = min; + cell_size = (max-min)/static_cast<double>(n_cols); + + in >> min >> max; + yllcorner = min; + + if (ceil((max-min)/static_cast<double>(n_rows)) == ceil(cell_size)) + cell_size = ceil(cell_size); + else + { + ERR("Error in readSurferHeader() - Anisotropic cellsize detected."); + return 0; + } + in >> min >> max; + } + + return true; +} + +void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::string const& file_name) +{ + GeoLib::Point const& origin (raster.getOrigin()); + unsigned const nCols (raster.getNCols()); + unsigned const nRows (raster.getNRows()); + + // write header + std::ofstream out(file_name); + out << "ncols " << nCols << "\n"; + out << "nrows " << nRows << "\n"; + out << "xllcorner " << origin[0] << "\n"; + out << "yllcorner " << origin[1] << "\n"; + out << "cellsize " << raster.getRasterPixelSize() << "\n"; + out << "NODATA_value " << raster.getNoDataValue() << "\n"; + + // write data + double const*const elevation(raster.begin()); + for (unsigned row(0); row < nRows; ++row) { + for (unsigned col(0); col < nCols; ++col) { + out << elevation[(nRows-row-1) * nCols + col] << " "; + } + out << "\n"; + } + out.close(); +} + +} // end namespace GeoLib diff --git a/FileIO/AsciiRasterInterface.h b/FileIO/AsciiRasterInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..e7e654915700f5b695c8ac31762c3b75e5c1ef0c --- /dev/null +++ b/FileIO/AsciiRasterInterface.h @@ -0,0 +1,57 @@ +/** + * @file AsciiRasterInterface.h + * @author Karsten Rink + * @date 2014-09-10 + * @brief Definition of the AsciiRasterInterface class. + * + * @copyright + * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + */ + +#ifndef ASCIIRASTERINTERFACE_H_ +#define ASCIIRASTERINTERFACE_H_ + +#include <fstream> + +namespace GeoLib { + class Raster; +} + +namespace FileIO { + +/** + * Interface for reading and writing a number of ASCII raster formats. + * Currently supported are reading and writing of Esri asc-files and + * reading of Surfer grd-files. + */ +class AsciiRasterInterface { +public: + /// Reads raster file by detecting type based on extension and then calling the apropriate method + static GeoLib::Raster* readRaster(std::string const& fname); + + /// Reads an ArcGis ASC raster file + static GeoLib::Raster* getRasterFromASCFile(std::string const& fname); + + /// Reads a Surfer GRD raster file + static GeoLib::Raster* getRasterFromSurferFile(std::string const& fname); + + /// Writes an Esri asc-file + static void writeRasterAsASC(GeoLib::Raster const& raster, std::string const& file_name); + + +private: + /// Reads the header of a Esri asc-file. + static bool readASCHeader(std::ifstream &in, std::size_t &n_cols, std::size_t &n_rows, + double &xllcorner, double &yllcorner, double &cell_size, double &no_data_val); + + /// Reads the header of a Surfer grd-file. + static bool readSurferHeader(std::ifstream &in, size_t &n_cols, std::size_t &n_rows, + double &xllcorner, double &yllcorner, double &cell_size, double &min, double &max); +}; + +} + +#endif /* ASCIIRASTERINTERFACE_H_ */ diff --git a/FileIO/CMakeLists.txt b/FileIO/CMakeLists.txt index 00b4bac14000e6b5eea9aab2eb465f7eda856535..3573dab15a0158512aaba9a13c8e90709815dda3 100644 --- a/FileIO/CMakeLists.txt +++ b/FileIO/CMakeLists.txt @@ -1,6 +1,8 @@ # Source files # GET_SOURCE_FILES(SOURCES_FILEIO) SET( SOURCES + AsciiRasterInterface.h + AsciiRasterInterface.cpp GMSInterface.h GMSInterface.cpp GMSHInterface.h diff --git a/GeoLib/Raster.cpp b/GeoLib/Raster.cpp index 3879f675a8b1fd585df78360e871abd7ccb371f2..6616360280d01ccea674f0a9d924f1912f60320d 100644 --- a/GeoLib/Raster.cpp +++ b/GeoLib/Raster.cpp @@ -119,189 +119,4 @@ double Raster::getValueAtPoint(const GeoLib::Point &pnt) return _no_data_val; } -void Raster::writeRasterAsASC(std::ostream &os) const -{ - // write header - os << "ncols " << _n_cols << "\n"; - os << "nrows " << _n_rows << "\n"; - os << "xllcorner " << _ll_pnt[0] << "\n"; - os << "yllcorner " << _ll_pnt[1] << "\n"; - os << "cellsize " << _cell_size << "\n"; - os << "NODATA_value " << _no_data_val << "\n"; - - // write data - for (unsigned row(0); row<_n_rows; row++) { - for (unsigned col(0); col<_n_cols; col++) { - os << _raster_data[(_n_rows-row-1)*_n_cols+col] << " "; - } - os << "\n"; - } -} - -Raster* Raster::readRaster(std::string const& fname) -{ - std::string ext (BaseLib::getFileExtension(fname)); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - if (ext.compare("asc") == 0) - return getRasterFromASCFile(fname); - if (ext.compare("grd") == 0) - return getRasterFromSurferFile(fname); - return nullptr; -} - -Raster* Raster::getRasterFromASCFile(std::string const& fname) -{ - std::ifstream in(fname.c_str()); - - if (!in.is_open()) { - WARN("Raster::getRasterFromASCFile(): Could not open file %s.", fname.c_str()); - return NULL; - } - - // header information - std::size_t n_cols(0), n_rows(0); - double xllcorner(0.0), yllcorner(0.0), cell_size(0.0), no_data_val(-9999); - - if (readASCHeader(in, n_cols, n_rows, xllcorner, yllcorner, cell_size, no_data_val)) { - double* values = new double[n_cols*n_rows]; - std::string s; - // read the data into the double-array - for (size_t j(0); j < n_rows; ++j) { - const size_t idx ((n_rows - j - 1) * n_cols); - for (size_t i(0); i < n_cols; ++i) { - in >> s; - values[idx+i] = strtod(BaseLib::replaceString(",", ".", s).c_str(),0); - - } - } - in.close(); - Raster *raster(new Raster(n_cols, n_rows, xllcorner, yllcorner, - cell_size, values, values+n_cols*n_rows, no_data_val)); - delete [] values; - return raster; - } else { - WARN("Raster::getRasterFromASCFile(): Could not read header of file %s", fname.c_str()); - return NULL; - } -} - -bool Raster::readASCHeader(std::ifstream &in, std::size_t &n_cols, std::size_t &n_rows, - double &xllcorner, double &yllcorner, double &cell_size, double &no_data_val) -{ - std::string tag, value; - - in >> tag; - if (tag.compare("ncols") == 0) { - in >> value; - n_cols = atoi(value.c_str()); - } else return false; - - in >> tag; - if (tag.compare("nrows") == 0) { - in >> value; - n_rows = atoi(value.c_str()); - } else return false; - - in >> tag; - if (tag.compare("xllcorner") == 0) { - in >> value; - xllcorner = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); - } else return false; - - in >> tag; - if (tag.compare("yllcorner") == 0) { - in >> value; - yllcorner = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); - } else return false; - - in >> tag; - if (tag.compare("cellsize") == 0) { - in >> value; - cell_size = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); - } else return false; - - in >> tag; - if (tag.compare("NODATA_value") == 0) { - in >> value; - no_data_val = strtod(BaseLib::replaceString(",", ".", value).c_str(), 0); - } else return false; - - return true; -} - -Raster* Raster::getRasterFromSurferFile(std::string const& fname) -{ - std::ifstream in(fname.c_str()); - - if (!in.is_open()) { - ERR("Raster::getRasterFromSurferFile() - Could not open file %s", fname.c_str()); - return NULL; - } - - // header information - std::size_t n_cols(0), n_rows(0); - double xllcorner(0.0), yllcorner(0.0), cell_size(0.0), min(0.0), max(0.0); - - if (readSurferHeader(in, n_cols, n_rows, xllcorner, yllcorner, cell_size, min, max)) - { - const double no_data_val (min-1); - double* values = new double[n_cols*n_rows]; - std::string s; - // read the data into the double-array - for (size_t j(0); j < n_rows; ++j) - { - const size_t idx (j * n_cols); - for (size_t i(0); i < n_cols; ++i) - { - in >> s; - const double val (strtod(BaseLib::replaceString(",", ".", s).c_str(),0)); - values[idx+i] = (val > max || val < min) ? no_data_val : val; - } - } - in.close(); - Raster *raster(new Raster(n_cols, n_rows, xllcorner, yllcorner, - cell_size, values, values+n_cols*n_rows, no_data_val)); - delete [] values; - return raster; - } else { - ERR("Raster::getRasterFromASCFile() - could not read header of file %s", fname.c_str()); - return NULL; - } -} - -bool Raster::readSurferHeader(std::ifstream &in, size_t &n_cols, std::size_t &n_rows, - double &xllcorner, double &yllcorner, double &cell_size, double &min, double &max) -{ - std::string tag; - - in >> tag; - - if (tag.compare("DSAA") != 0) - { - ERR("Error in readSurferHeader() - No Surfer file."); - return false; - } - else - { - in >> n_cols >> n_rows; - in >> min >> max; - xllcorner = min; - cell_size = (max-min)/static_cast<double>(n_cols); - - in >> min >> max; - yllcorner = min; - - if (ceil((max-min)/static_cast<double>(n_rows)) == ceil(cell_size)) - cell_size = ceil(cell_size); - else - { - ERR("Error in readSurferHeader() - Anisotropic cellsize detected."); - return 0; - } - in >> min >> max; - } - - return true; -} - } // end namespace GeoLib diff --git a/GeoLib/Raster.h b/GeoLib/Raster.h index 52a0c74286d6c2eb14541e9b820d20e65ce62ffe..78406fedc7be37520d1b57e8acd24990d87e70bf 100644 --- a/GeoLib/Raster.h +++ b/GeoLib/Raster.h @@ -70,7 +70,7 @@ public: /** * get the distance between raster pixels */ - double getRasterPixelDistance() const { return _cell_size; } + double getRasterPixelSize() const { return _cell_size; } /** * get the origin of lower left raster cell @@ -103,35 +103,10 @@ public: ~Raster(); - /** - * Write meta data and raw raster data as asci file into the output stream. - * @param os the output stream - */ - void writeRasterAsASC(std::ostream &os) const; - - /// Reads raster file by detecting type based on extension and then calling the apropriate method - static Raster* readRaster(std::string const& fname); - /// Creates a Raster based on a GeoLib::Surface static Raster* getRasterFromSurface(Surface const& sfc, double cell_size, double no_data_val = -9999); - /// Reads an ArcGis ASC raster file - static Raster* getRasterFromASCFile(std::string const& fname); - - /// Reads a Surfer GRD raster file - static Raster* getRasterFromSurferFile(std::string const& fname); private: - static bool readASCHeader(std::ifstream &in, std::size_t &n_cols, std::size_t &n_rows, - double &xllcorner, double &yllcorner, double &cell_size, double &no_data_val); - /** - * Reads the header of a Surfer grd-file. - * \param header The ascHeader-object into which all the information will be written. - * \param in FileInputStream used for reading the data. - * \return True if the header could be read correctly, false otherwise. - */ - static bool readSurferHeader(std::ifstream &in, size_t &n_cols, std::size_t &n_rows, - double &xllcorner, double &yllcorner, double &cell_size, double &min, double &max); - void setCellSize(double cell_size); void setNoDataVal (double no_data_val); diff --git a/Gui/DataView/DirectConditionGenerator.cpp b/Gui/DataView/DirectConditionGenerator.cpp index abb16bb120dda8dfa93d32d5650fbfd13cbce596..89d63df52262a81c0c7cae3fdc7735c86e1baa1e 100644 --- a/Gui/DataView/DirectConditionGenerator.cpp +++ b/Gui/DataView/DirectConditionGenerator.cpp @@ -19,6 +19,8 @@ #include "DirectConditionGenerator.h" +#include "AsciiRasterInterface.h" + #include "Raster.h" #include "MeshSurfaceExtraction.h" #include "PointWithID.h" @@ -32,7 +34,7 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directT { if (_direct_values.empty()) { - GeoLib::Raster* raster (GeoLib::Raster::readRaster(filename)); + GeoLib::Raster* raster (FileIO::AsciiRasterInterface::readRaster(filename)); if (! raster) { ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - could not load raster file."); return _direct_values; @@ -62,7 +64,7 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directW { if (_direct_values.empty()) { - GeoLib::Raster* raster (GeoLib::Raster::readRaster(filename)); + GeoLib::Raster* raster (FileIO::AsciiRasterInterface::readRaster(filename)); if (!raster) { ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration() - could not load raster file."); return _direct_values; diff --git a/Gui/DataView/GeoMapper.cpp b/Gui/DataView/GeoMapper.cpp index 0e58afedbe991ef557ca00c2f20590e4854ed709..658b01cea0e3a9d0253d238563ef4b3aa17e5ded 100644 --- a/Gui/DataView/GeoMapper.cpp +++ b/Gui/DataView/GeoMapper.cpp @@ -19,6 +19,8 @@ #include <numeric> +#include "FileIO/AsciiRasterInterface.h" + #include "AABB.h" #include "Mesh.h" #include "Elements/Element.h" @@ -44,7 +46,7 @@ GeoMapper::~GeoMapper() void GeoMapper::mapOnDEM(const std::string &file_name) { - this->_raster = GeoLib::Raster::getRasterFromASCFile(file_name); + this->_raster = FileIO::AsciiRasterInterface::getRasterFromASCFile(file_name); if (! _raster) { ERR("GeoMapper::mapOnDEM(): failed to load %s", file_name.c_str()); return; @@ -131,7 +133,7 @@ float GeoMapper::getDemElevation(double x, double y) const { const double origin_x(_raster->getOrigin()[0]); const double origin_y(_raster->getOrigin()[1]); - const double cellsize(_raster->getRasterPixelDistance()); + const double cellsize(_raster->getRasterPixelSize()); const std::size_t width(_raster->getNCols()); const std::size_t height(_raster->getNRows()); diff --git a/Gui/VtkVis/VtkRaster.cpp b/Gui/VtkVis/VtkRaster.cpp index 7cfa4db9ce9d204ffd55c5177ae2a9be60c85910..60a7fcbe2f178852c31c0109f89604534f51b9ce 100644 --- a/Gui/VtkVis/VtkRaster.cpp +++ b/Gui/VtkVis/VtkRaster.cpp @@ -27,6 +27,8 @@ #include "StringTools.h" +#include "AsciiRasterInterface.h" + // GeoLib #include "Raster.h" @@ -54,16 +56,16 @@ vtkImageAlgorithm* VtkRaster::loadImage(const std::string &fileName, GeoLib::Raster *raster(nullptr); if (fileInfo.suffix().toLower() == "asc") { - raster = GeoLib::Raster::getRasterFromASCFile(fileName); + raster = FileIO::AsciiRasterInterface::getRasterFromASCFile(fileName); } else if (fileInfo.suffix().toLower() == "grd") { - raster = GeoLib::Raster::getRasterFromSurferFile(fileName); + raster = FileIO::AsciiRasterInterface::getRasterFromSurferFile(fileName); } if (raster) { x0 = raster->getOrigin()[0]; y0 = raster->getOrigin()[1]; - delta = raster->getRasterPixelDistance(); + delta = raster->getRasterPixelSize(); double const*const data (raster->begin()); return VtkRaster::loadImageFromArray(data, x0, y0, raster->getNCols(), raster->getNRows(), delta, diff --git a/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp b/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp index c4d98231c9df6b3e81380976ccc2378c954a0fed..5fcfbfab7e1665a3942933ca2a0e736cfde7551c 100644 --- a/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp +++ b/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp @@ -76,7 +76,7 @@ MeshLib::Mesh* ConvertRasterToMesh::constructMesh(const double* pix_vals, const const size_t height = _raster.getNRows()+1; const size_t width = _raster.getNCols()+1; size_t node_idx_count(0); - const double distance(_raster.getRasterPixelDistance()); + const double distance(_raster.getRasterPixelSize()); const double x_offset(_raster.getOrigin()[0]); // - distance / 2.0); const double y_offset(_raster.getOrigin()[1]); // - distance / 2.0); diff --git a/MeshLib/MeshGenerators/LayeredVolume.cpp b/MeshLib/MeshGenerators/LayeredVolume.cpp index 0e9665b9b12e2be22459777395cf18fb6b90358a..4866b8222a067f8f6fa200b08a475d51f7c34913 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.cpp +++ b/MeshLib/MeshGenerators/LayeredVolume.cpp @@ -19,6 +19,8 @@ #include "Vector3.h" +#include "FileIO/AsciiRasterInterface.h" + #include "GEOObjects.h" #include "PointVec.h" #include "Mesh.h" @@ -46,7 +48,7 @@ bool LayeredVolume::createGeoVolumes(const MeshLib::Mesh &mesh, const std::vecto std::vector<GeoLib::Raster const*> rasters; rasters.reserve(raster_paths.size()); for (auto path = raster_paths.begin(); path != raster_paths.end(); ++path) - rasters.push_back(GeoLib::Raster::getRasterFromASCFile(*path)); + rasters.push_back(FileIO::AsciiRasterInterface::getRasterFromASCFile(*path)); const bool result = this->createGeoVolumes(mesh, rasters, noDataReplacementValue); std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index 51ee03ba327071a61476a70fe0706db83312dd6b..649acf81f714a914f0bbb6be03db3663511f4a09 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -19,6 +19,9 @@ #include "logog/include/logog.hpp" #include "MeshLayerMapper.h" + +#include "FileIO/AsciiRasterInterface.h" + // GeoLib #include "Raster.h" @@ -30,6 +33,8 @@ #include "Elements/Pyramid.h" #include "Elements/Prism.h" #include "MeshSurfaceExtraction.h" + + #include "MathTools.h" MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, std::vector<float> const& layer_thickness_vector, std::string const& mesh_name) const @@ -104,7 +109,7 @@ MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, st bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, const std::string &rasterfile, const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue = 0.0) const { - const GeoLib::Raster *raster(GeoLib::Raster::getRasterFromASCFile(rasterfile)); + const GeoLib::Raster *raster(FileIO::AsciiRasterInterface::getRasterFromASCFile(rasterfile)); if (! raster) { ERR("MshLayerMapper::LayerMapping - could not read raster file %s", rasterfile.c_str()); return false; @@ -125,7 +130,7 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, const GeoLib::Raster const double x0(raster.getOrigin()[0]); const double y0(raster.getOrigin()[1]); - const double delta(raster.getRasterPixelDistance()); + const double delta(raster.getRasterPixelSize()); const double no_data(raster.getNoDataValue()); const std::size_t width(raster.getNCols()); const std::size_t height(raster.getNRows()); diff --git a/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp b/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp index 557d506b6cb6ee5b86ac08d1e07174c036db6412..22b24ad0e1cf50a74eed133f236fe9d5937a9ea6 100644 --- a/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp +++ b/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp @@ -29,6 +29,7 @@ #include "FileTools.h" #include "MeshIO.h" #include "readMeshFromFile.h" +#include "AsciiRasterInterface.h" // GeoLib #include "Raster.h" @@ -122,9 +123,7 @@ int main (int argc, char* argv[]) raster_arg.getValue())); new_raster_fname += "-" + std::to_string(raster->getNRows()) + "x" + std::to_string(raster->getNCols()) + ".asc"; - std::ofstream out(new_raster_fname); - raster->writeRasterAsASC(out); - out.close(); + FileIO::AsciiRasterInterface::writeRasterAsASC(raster, new_raster_fname); } }