Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: Hierarchical Data Format Release 5 (HDF5)
5 : * Purpose: Header file for HDF5 HDFEOS parser
6 : * Author: Even Rouault
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2023, Even Rouault <even dot rouault at spatialys.com>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef HDF5EOSPARSER_H_INCLUDED
31 : #define HDF5EOSPARSER_H_INCLUDED
32 :
33 : #include "hdf5_api.h"
34 :
35 : #include "cpl_json.h"
36 : #include "ogr_spatialref.h"
37 :
38 : #include <map>
39 : #include <string>
40 : #include <vector>
41 :
42 : /************************************************************************/
43 : /* HDF5EOSParser */
44 : /************************************************************************/
45 :
46 : class HDF5EOSParser
47 : {
48 : public:
49 173 : HDF5EOSParser() = default;
50 :
51 : enum class DataModel
52 : {
53 : INVALID,
54 : GRID,
55 : SWATH,
56 : };
57 :
58 : struct Dimension
59 : {
60 : std::string osName{};
61 : int nSize = 0;
62 :
63 40 : inline bool operator==(const Dimension &otherDim) const
64 : {
65 40 : return osName == otherDim.osName;
66 : }
67 : };
68 :
69 : struct GridMetadata
70 : {
71 : std::string osGridName{};
72 : std::vector<Dimension> aoDimensions; // all dimensions of the grid
73 : std::string osProjection{}; // e.g HE5_GCTP_SNSOID
74 : int nProjCode = -1; // GTCP numeric value for osProjection
75 : std::string osGridOrigin{}; // e.g HE5_HDFE_GD_UL
76 : std::vector<double>
77 : adfProjParams{}; // e.g (6371007.181000,0,0,0,0,0,0,0,0,0,0,0,0)
78 : int nZone = 0; // for HE5_GCTP_UTM and HE5_GCTP_SPCS
79 : int nSphereCode = 0;
80 : std::vector<double>
81 : adfUpperLeftPointMeters{}; // e.g (-1111950.519667,5559752.598333)
82 : std::vector<double>
83 : adfLowerRightPointMeters{}; // e.g (0.000000,4447802.078667)
84 :
85 : bool GetGeoTransform(double adfGeoTransform[6]) const;
86 : std::unique_ptr<OGRSpatialReference> GetSRS() const;
87 : };
88 :
89 : struct GridDataFieldMetadata
90 : {
91 : std::vector<Dimension> aoDimensions{}; // dimensions of the data field
92 : const GridMetadata *poGridMetadata = nullptr;
93 : };
94 :
95 : struct SwathMetadata
96 : {
97 : std::string osSwathName{};
98 : std::vector<Dimension> aoDimensions{}; // all dimensions of the swath
99 : };
100 :
101 : struct SwathGeolocationFieldMetadata
102 : {
103 : std::vector<Dimension>
104 : aoDimensions{}; // dimensions of the geolocation field
105 : const SwathMetadata *poSwathMetadata = nullptr;
106 : };
107 :
108 : struct SwathDataFieldMetadata
109 : {
110 : std::vector<Dimension> aoDimensions{}; // dimensions of the data field
111 : const SwathMetadata *poSwathMetadata = nullptr;
112 :
113 : int iXDim = -1;
114 : int iYDim = -1;
115 : int iOtherDim = -1;
116 :
117 : std::string osLongitudeSubdataset;
118 : std::string osLatitudeSubdataset;
119 : int nLineOffset = 0;
120 : int nLineStep = 0;
121 : int nPixelOffset = 0;
122 : int nPixelStep = 0;
123 : };
124 :
125 : static bool HasHDFEOS(hid_t hRoot);
126 : bool Parse(hid_t hRoot);
127 :
128 431 : DataModel GetDataModel() const
129 : {
130 431 : return m_eDataModel;
131 : }
132 :
133 : bool GetGridMetadata(const std::string &osGridName,
134 : GridMetadata &gridMetadataOut) const;
135 : bool GetGridDataFieldMetadata(
136 : const char *pszSubdatasetName,
137 : GridDataFieldMetadata &gridDataFieldMetadataOut) const;
138 : bool GetSwathMetadata(const std::string &osSwathName,
139 : SwathMetadata &swathMetadataOut) const;
140 : bool GetSwathDataFieldMetadata(
141 : const char *pszSubdatasetName,
142 : SwathDataFieldMetadata &swathDataFieldMetadataOut) const;
143 : bool GetSwathGeolocationFieldMetadata(
144 : const char *pszSubdatasetName,
145 : SwathGeolocationFieldMetadata &swathGeolocationFieldMetadataOut) const;
146 :
147 : private:
148 : DataModel m_eDataModel = DataModel::INVALID;
149 : std::map<std::string, std::unique_ptr<GridMetadata>>
150 : m_oMapGridNameToGridMetadata{};
151 : std::map<std::string, GridDataFieldMetadata>
152 : m_oMapSubdatasetNameToGridDataFieldMetadata{};
153 : std::map<std::string, std::unique_ptr<SwathMetadata>>
154 : m_oMapSwathNameToSwathMetadata{};
155 : std::map<std::string, SwathDataFieldMetadata>
156 : m_oMapSubdatasetNameToSwathDataFieldMetadata{};
157 : std::map<std::string, SwathGeolocationFieldMetadata>
158 : m_oMapSubdatasetNameToSwathGeolocationFieldMetadata{};
159 :
160 : void ParseGridStructure(const CPLJSONObject &oGridStructure);
161 : void ParseSwathStructure(const CPLJSONObject &oSwathStructure);
162 : };
163 :
164 : #endif // HDF5EOSPARSER_H_INCLUDED
|