Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Hierarchical Data Format Release 4 (HDF4) 4 : * Purpose: Header file for HDF4 datasets reader. 5 : * Author: Andrey Kiselev, dron@ak4719.spb.edu 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2002, Andrey Kiselev <dron@ak4719.spb.edu> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef HDF4DATASET_H_INCLUDED_ 14 : #define HDF4DATASET_H_INCLUDED_ 15 : 16 : #include "hdf.h" 17 : #include "mfhdf.h" 18 : 19 : #include "cpl_list.h" 20 : #include "gdal_pam.h" 21 : 22 : constexpr int HDF4_SDS_MAXNAMELEN = 65; 23 : 24 : constexpr int N_BUF_SIZE = 8192; 25 : 26 : typedef enum // Types of dataset: 27 : { 28 : HDF4_SDS, // Scientific Dataset 29 : HDF4_GR, // General Raster Image 30 : HDF4_EOS, // HDF EOS 31 : HDF4_UNKNOWN 32 : } HDF4DatasetType; 33 : 34 : typedef enum // Types of data products: 35 : { 36 : H4ST_GDAL, // HDF written by GDAL 37 : H4ST_EOS_GRID, // HDF-EOS Grid 38 : H4ST_EOS_SWATH, // HDF-EOS Swath 39 : H4ST_EOS_SWATH_GEOL, // HDF-EOS Swath Geolocation Array 40 : H4ST_SEAWIFS_L1A, // SeaWiFS Level-1A Data 41 : H4ST_SEAWIFS_L2, // SeaWiFS Level-2 Data 42 : H4ST_SEAWIFS_L3, // SeaWiFS Level-3 Standard Mapped Image 43 : H4ST_HYPERION_L1, // Hyperion L1 Data Product 44 : H4ST_UNKNOWN 45 : } HDF4SubdatasetType; 46 : 47 : /************************************************************************/ 48 : /* ==================================================================== */ 49 : /* HDF4Dataset */ 50 : /* ==================================================================== */ 51 : /************************************************************************/ 52 : 53 : class HDF4Dataset CPL_NON_FINAL : public GDALPamDataset 54 : { 55 : 56 : private: 57 : bool bIsHDFEOS; 58 : std::shared_ptr<GDALGroup> m_poRootGroup{}; 59 : 60 : static char **HDF4EOSTokenizeAttrs(const char *pszString); 61 : static char **HDF4EOSGetObject(char **papszAttrList, char **ppszAttrName, 62 : char **ppszAttrClass, char **ppszAttrValue); 63 : 64 : void OpenMultiDim(const char *pszFilename, CSLConstList papszOpenOptionsIn); 65 : 66 : CPL_DISALLOW_COPY_ASSIGN(HDF4Dataset) 67 : 68 : protected: 69 : int32 hGR; 70 : int32 hSD; 71 : int32 nImages; 72 : HDF4SubdatasetType iSubdatasetType; 73 : const char *pszSubdatasetType; 74 : 75 : char **papszGlobalMetadata; 76 : char **papszSubDatasets; 77 : 78 : CPLErr ReadGlobalAttributes(int32); 79 : 80 : public: 81 : static GDALDataType GetDataType(int32); 82 : static const char *GetDataTypeName(int32); 83 : static int GetDataTypeSize(int32); 84 : static double AnyTypeToDouble(int32, void *); 85 : static char **TranslateHDF4Attributes(int32, int32, char *, int32, int32, 86 : char **); 87 : static char **TranslateHDF4EOSAttributes(int32, int32, int32, char **); 88 : 89 : public: 90 : HDF4Dataset(); 91 : ~HDF4Dataset() override; 92 : 93 12 : std::shared_ptr<GDALGroup> GetRootGroup() const override 94 : { 95 12 : return m_poRootGroup; 96 : } 97 : 98 : char **GetMetadataDomainList() override; 99 : CSLConstList GetMetadata(const char *pszDomain = "") override; 100 : static GDALDataset *Open(GDALOpenInfo *); 101 : }; 102 : 103 : /************************************************************************/ 104 : /* ==================================================================== */ 105 : /* HDF4ImageDataset */ 106 : /* ==================================================================== */ 107 : /************************************************************************/ 108 : 109 : constexpr int N_COLOR_ENTRIES = 256; 110 : 111 : class HDF4ImageDataset final : public HDF4Dataset 112 : { 113 : friend class HDF4ImageRasterBand; 114 : 115 : char *pszFilename; 116 : int32 hHDF4; 117 : int32 iGR; 118 : int32 iPal; 119 : int32 iDataset; 120 : int32 iRank; 121 : int32 iNumType; 122 : int32 nAttrs; 123 : int32 iInterlaceMode; 124 : int32 iPalInterlaceMode; 125 : int32 iPalDataType; 126 : int32 nComps; 127 : int32 nPalEntries; 128 : int32 aiDimSizes[H4_MAX_VAR_DIMS]; 129 : int iXDim; 130 : int iYDim; 131 : int iBandDim; 132 : int i4Dim; 133 : int nBandCount; 134 : char **papszLocalMetadata{}; 135 : uint8 aiPaletteData[N_COLOR_ENTRIES][3]; // XXX: Static array for now 136 : char szName[HDF4_SDS_MAXNAMELEN]; 137 : char *pszSubdatasetName; 138 : char *pszFieldName; 139 : 140 : GDALColorTable *poColorTable; 141 : 142 : OGRSpatialReference m_oSRS{}; 143 : OGRSpatialReference m_oGCPSRS{}; 144 : bool bHasGeoTransform; 145 : GDALGeoTransform m_gt{}; 146 : std::vector<gdal::GCP> m_aoGCPs{}; 147 : 148 : HDF4DatasetType iDatasetType; 149 : 150 : int32 iSDS; 151 : 152 : int nBlockPreferredXSize; 153 : int nBlockPreferredYSize; 154 : bool bReadTile; 155 : 156 : void ToGeoref(double *, double *); 157 : void GetImageDimensions(char *); 158 : void GetSwatAttrs(int32); 159 : void GetGridAttrs(int32 hGD); 160 : void CaptureNRLGeoTransform(void); 161 : void CaptureL1GMTLInfo(void); 162 : void CaptureCoastwatchGCTPInfo(void); 163 : void ProcessModisSDSGeolocation(void); 164 : int ProcessSwathGeolocation(int32, char **); 165 : 166 : static long USGSMnemonicToCode(const char *); 167 : static void ReadCoordinates(const char *, double *, double *); 168 : 169 : CPL_DISALLOW_COPY_ASSIGN(HDF4ImageDataset) 170 : 171 : public: 172 : HDF4ImageDataset(); 173 : ~HDF4ImageDataset() override; 174 : 175 : static GDALDataset *Open(GDALOpenInfo *); 176 : static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, 177 : int nBandsIn, GDALDataType eType, 178 : CSLConstList papszParamList); 179 : CPLErr FlushCache(bool bAtClosing) override; 180 : CPLErr GetGeoTransform(GDALGeoTransform >) const override; 181 : CPLErr SetGeoTransform(const GDALGeoTransform >) override; 182 : const OGRSpatialReference *GetSpatialRef() const override; 183 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; 184 : int GetGCPCount() override; 185 : const OGRSpatialReference *GetGCPSpatialRef() const override; 186 : const GDAL_GCP *GetGCPs() override; 187 : }; 188 : 189 : char *SPrintArray(GDALDataType eDataType, const void *paDataArray, int nValues, 190 : const char *pszDelimiter); 191 : 192 : #endif /* HDF4DATASET_H_INCLUDED_ */