Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Hierarchical Data Format Release 5 (HDF5) 4 : * Purpose: Header file for HDF5 HDFEOS parser 5 : * Author: Even Rouault 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef HDF5EOSPARSER_H_INCLUDED 14 : #define HDF5EOSPARSER_H_INCLUDED 15 : 16 : #include "hdf5_api.h" 17 : 18 : #include "cpl_json.h" 19 : #include "gdal_priv.h" 20 : #include "ogr_spatialref.h" 21 : 22 : #include <map> 23 : #include <string> 24 : #include <vector> 25 : 26 : /************************************************************************/ 27 : /* HDF5EOSParser */ 28 : /************************************************************************/ 29 : 30 : class HDF5EOSParser 31 : { 32 : public: 33 191 : HDF5EOSParser() = default; 34 : 35 : enum class DataModel 36 : { 37 : INVALID, 38 : GRID, 39 : SWATH, 40 : }; 41 : 42 : struct Dimension 43 : { 44 : std::string osName{}; 45 : int nSize = 0; 46 : 47 108 : inline bool operator==(const Dimension &otherDim) const 48 : { 49 108 : return osName == otherDim.osName; 50 : } 51 : }; 52 : 53 : struct GridMetadata 54 : { 55 : std::string osGridName{}; 56 : std::vector<Dimension> aoDimensions{}; // all dimensions of the grid 57 : std::string osProjection{}; // e.g HE5_GCTP_SNSOID 58 : int nProjCode = -1; // GTCP numeric value for osProjection 59 : std::string osGridOrigin{}; // e.g HE5_HDFE_GD_UL 60 : std::vector<double> 61 : adfProjParams{}; // e.g (6371007.181000,0,0,0,0,0,0,0,0,0,0,0,0) 62 : int nZone = 0; // for HE5_GCTP_UTM and HE5_GCTP_SPCS 63 : int nSphereCode = 0; 64 : std::vector<double> 65 : adfUpperLeftPointMeters{}; // e.g (-1111950.519667,5559752.598333) 66 : std::vector<double> 67 : adfLowerRightPointMeters{}; // e.g (0.000000,4447802.078667) 68 : 69 : bool GetGeoTransform(GDALGeoTransform >) const; 70 : std::unique_ptr<OGRSpatialReference> GetSRS() const; 71 : }; 72 : 73 : struct GridDataFieldMetadata 74 : { 75 : std::vector<Dimension> aoDimensions{}; // dimensions of the data field 76 : const GridMetadata *poGridMetadata = nullptr; 77 : }; 78 : 79 : struct SwathMetadata 80 : { 81 : std::string osSwathName{}; 82 : std::vector<Dimension> aoDimensions{}; // all dimensions of the swath 83 : }; 84 : 85 : struct SwathFieldMetadata 86 : { 87 : std::vector<Dimension> 88 : aoDimensions{}; // dimensions of the geolocation/data field 89 : const SwathMetadata *poSwathMetadata = nullptr; 90 : 91 : int iXDim = -1; 92 : int iYDim = -1; 93 : int iOtherDim = -1; 94 : 95 : std::string osLongitudeSubdataset{}; 96 : std::string osLatitudeSubdataset{}; 97 : int nLineOffset = 0; 98 : int nLineStep = 0; 99 : int nPixelOffset = 0; 100 : int nPixelStep = 0; 101 : }; 102 : 103 : static bool HasHDFEOS(hid_t hRoot); 104 : bool Parse(hid_t hRoot); 105 : 106 352 : DataModel GetDataModel() const 107 : { 108 352 : return m_eDataModel; 109 : } 110 : 111 : bool GetGridMetadata(const std::string &osGridName, 112 : GridMetadata &gridMetadataOut) const; 113 : bool GetGridDataFieldMetadata( 114 : const char *pszSubdatasetName, 115 : GridDataFieldMetadata &gridDataFieldMetadataOut) const; 116 : bool GetSwathMetadata(const std::string &osSwathName, 117 : SwathMetadata &swathMetadataOut) const; 118 : bool GetSwathFieldMetadata(const char *pszSubdatasetName, 119 : SwathFieldMetadata &swathFieldMetadataOut) const; 120 : 121 : private: 122 : DataModel m_eDataModel = DataModel::INVALID; 123 : std::map<std::string, std::unique_ptr<GridMetadata>> 124 : m_oMapGridNameToGridMetadata{}; 125 : std::map<std::string, GridDataFieldMetadata> 126 : m_oMapSubdatasetNameToGridDataFieldMetadata{}; 127 : std::map<std::string, std::unique_ptr<SwathMetadata>> 128 : m_oMapSwathNameToSwathMetadata{}; 129 : std::map<std::string, SwathFieldMetadata> 130 : m_oMapSubdatasetNameToSwathFieldMetadata{}; 131 : 132 : void ParseGridStructure(const CPLJSONObject &oGridStructure); 133 : void ParseSwathStructure(const CPLJSONObject &oSwathStructure); 134 : }; 135 : 136 : #endif // HDF5EOSPARSER_H_INCLUDED