QGIS/external/mdal/frmts/mdal_hec2d.hpp

107 lines
3.9 KiB
C++
Raw Normal View History

2018-12-14 14:59:53 +01:00
/*
MDAL - Mesh Data Abstraction Library (MIT License)
Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
*/
#ifndef MDAL_HEC2D_HPP
#define MDAL_HEC2D_HPP
#include <string>
#include "mdal_data_model.hpp"
#include "mdal_memory_data_model.hpp"
#include "mdal.h"
#include "mdal_hdf5.hpp"
#include "mdal_driver.hpp"
namespace MDAL
{
/**
* HEC-RAS 2D format.
*
* This is a HDF5-based format to store mesh and datasets
* in a single file. The format supports meshes is multiple
* (disconnected) areas.
*
* There is a small change in the format in HEC-RAS 5.0.5+, where
* - Header File Type is different (HEC-RAS Results vs HEC-RAS Geometry)
* - Names or areas are stored in different place (names array vs attributes array)
2019-10-14 09:19:14 +02:00
*
* Time data unit should be present in Time dataset and Time or Variable attribute for given dataset root,
* Since MDAL API is reporting times in float hours, the original values need to be corrected
* based on value found in the Time attribute.
*
* All reference times can be found in Time Data Stamp dataset.
* First value in the dataset is reported by MDAL as reference time
*
*/
2018-12-14 14:59:53 +01:00
class DriverHec2D: public Driver
{
public:
DriverHec2D();
~DriverHec2D( ) override = default;
DriverHec2D *create() override;
bool canReadMesh( const std::string &uri ) override;
std::unique_ptr< Mesh > load( const std::string &resultsFile, const std::string &meshName = "" ) override;
2018-12-14 14:59:53 +01:00
private:
std::unique_ptr< MDAL::MemoryMesh > mMesh;
std::string mFileName;
std::vector<MDAL::RelativeTimestamp> mTimes ;
DateTime mReferenceTime;
// Pre 5.0.5 format
bool canReadOldFormat( const std::string &fileType ) const;
std::vector<std::string> read2DFlowAreasNamesOld( HdfGroup gGeom2DFlowAreas ) const;
// 5.0.5 + format
bool canReadFormat505( const std::string &fileType ) const;
std::vector<std::string> read2DFlowAreasNames505( HdfGroup gGeom2DFlowAreas ) const;
// Common functions
2018-12-14 14:59:53 +01:00
void readFaceOutput( const HdfFile &hdfFile,
const HdfGroup &rootGroup,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<MDAL::RelativeTimestamp> &times,
const DateTime &referenceTime );
2018-12-14 14:59:53 +01:00
void readFaceResults( const HdfFile &hdfFile,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames );
std::shared_ptr<MDAL::MemoryDataset2D> readElemOutput(
2018-12-14 14:59:53 +01:00
const HdfGroup &rootGroup,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<MDAL::RelativeTimestamp> &times,
std::shared_ptr<MDAL::MemoryDataset2D> bed_elevation,
const DateTime &referenceTime );
std::shared_ptr<MDAL::MemoryDataset2D> readBedElevation(
2018-12-14 14:59:53 +01:00
const HdfGroup &gGeom2DFlowAreas,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames );
2018-12-14 14:59:53 +01:00
void setProjection( HdfFile hdfFile );
2018-12-14 14:59:53 +01:00
void parseMesh( HdfGroup gGeom2DFlowAreas,
std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames );
2018-12-14 14:59:53 +01:00
void readElemResults(
const HdfFile &hdfFile,
std::shared_ptr<MDAL::MemoryDataset2D> bed_elevation,
2018-12-14 14:59:53 +01:00
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames );
};
} // namespace MDAL
#endif //MDAL_HEC2D_HPP