Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: GDAL Core
5 : * Purpose: Read metadata (mainly the remote sensing imagery) from files of
6 : * different providers like DigitalGlobe, GeoEye etc.
7 : * Author: Dmitry Baryshnikov, polimax@mail.ru
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2014-2015, NextGIS info@nextgis.ru
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #ifndef GDAL_MDREADER_H_INCLUDED
32 : #define GDAL_MDREADER_H_INCLUDED
33 :
34 : #include "cpl_port.h"
35 : #include "gdal_priv.h"
36 :
37 : #include <map>
38 :
39 : #define MD_DOMAIN_IMD "IMD" /**< image metadata section */
40 : #define MD_DOMAIN_RPC "RPC" /**< rpc metadata section */
41 : #define MD_DOMAIN_IMAGERY "IMAGERY" /**< imagery metadata section */
42 : #define MD_DOMAIN_DEFAULT "" /**< default metadata section */
43 :
44 : #define MD_NAME_ACQDATETIME \
45 : "ACQUISITIONDATETIME" /**< Acquisition Date Time property name. The time \
46 : should be in UTC */
47 : #define MD_NAME_SATELLITE \
48 : "SATELLITEID" /**< Satellite identificator property name */
49 : #define MD_NAME_CLOUDCOVER \
50 : "CLOUDCOVER" /**< Cloud coverage property name. The value between 0 - 100 \
51 : or 999 if n/a */
52 : #define MD_NAME_MDTYPE \
53 : "METADATATYPE" /**< Metadata reader type property name. The reader \
54 : processed this metadata */
55 :
56 : #define MD_DATETIMEFORMAT "%Y-%m-%d %H:%M:%S" /**< Date time format */
57 : #define MD_CLOUDCOVER_NA "999" /**< The value if cloud cover is n/a */
58 :
59 : /**
60 : * RPC/RPB specific defines
61 : */
62 :
63 : #define RPC_ERR_BIAS "ERR_BIAS"
64 : #define RPC_ERR_RAND "ERR_RAND"
65 : #define RPC_LINE_OFF "LINE_OFF"
66 : #define RPC_SAMP_OFF "SAMP_OFF"
67 : #define RPC_LAT_OFF "LAT_OFF"
68 : #define RPC_LONG_OFF "LONG_OFF"
69 : #define RPC_HEIGHT_OFF "HEIGHT_OFF"
70 : #define RPC_LINE_SCALE "LINE_SCALE"
71 : #define RPC_SAMP_SCALE "SAMP_SCALE"
72 : #define RPC_LAT_SCALE "LAT_SCALE"
73 : #define RPC_LONG_SCALE "LONG_SCALE"
74 : #define RPC_HEIGHT_SCALE "HEIGHT_SCALE"
75 : #define RPC_LINE_NUM_COEFF "LINE_NUM_COEFF"
76 : #define RPC_LINE_DEN_COEFF "LINE_DEN_COEFF"
77 : #define RPC_SAMP_NUM_COEFF "SAMP_NUM_COEFF"
78 : #define RPC_SAMP_DEN_COEFF "SAMP_DEN_COEFF"
79 :
80 : /* Optional */
81 : #define RPC_MIN_LONG "MIN_LONG"
82 : #define RPC_MIN_LAT "MIN_LAT"
83 : #define RPC_MAX_LONG "MAX_LONG"
84 : #define RPC_MAX_LAT "MAX_LAT"
85 :
86 : /* Pleiades Neo nomenclature */
87 : #define RPC_LAT_NUM_COEFF "LAT_NUM_COEFF"
88 : #define RPC_LAT_DEN_COEFF "LAT_DEN_COEFF"
89 : #define RPC_LON_NUM_COEFF "LON_NUM_COEFF"
90 : #define RPC_LON_DEN_COEFF "LON_DEN_COEFF"
91 :
92 : /**
93 : * Enumerator of metadata readers
94 : */
95 :
96 : typedef enum
97 : {
98 : MDR_None = 0x00000000, /**< no reader */
99 : MDR_DG = 0x00000001, /**< Digital Globe, METADATATYPE=DG */
100 : MDR_GE = 0x00000002, /**< Geo Eye, METADATATYPE=GE */
101 : MDR_OV = 0x00000004, /**< Orb View, METADATATYPE=OV */
102 : MDR_PLEIADES = 0x00000008, /**< Pleiades, METADATATYPE=DIMAP */
103 : MDR_SPOT = 0x00000010, /**< Spot, METADATATYPE=DIMAP */
104 : MDR_RDK1 = 0x00000020, /**< Resurs DK1, METADATATYPE=MSP */
105 : MDR_LS = 0x00000040, /**< Landsat, METADATATYPE=ODL */
106 : MDR_RE = 0x00000080, /**< RapidEye, METADATATYPE=RE */
107 : MDR_KOMPSAT = 0x00000100, /**< Kompsat, METADATATYPE=KARI */
108 : MDR_EROS = 0x00000200, /**< EROS, METADATATYPE=EROS */
109 : MDR_ALOS = 0x00000400, /**< ALOS, METADATATYPE=ALOS */
110 : MDR_ANY = MDR_DG | MDR_GE | MDR_OV | MDR_PLEIADES | MDR_SPOT | MDR_RDK1 |
111 : MDR_LS | MDR_RE | MDR_KOMPSAT | MDR_EROS |
112 : MDR_ALOS /**< any reader */
113 : } MDReaders;
114 :
115 : /**
116 : * The base class for all metadata readers
117 : */
118 : class CPL_DLL GDALMDReaderBase
119 : {
120 :
121 : CPL_DISALLOW_COPY_ASSIGN(GDALMDReaderBase)
122 :
123 : static bool
124 : ReadXMLToListFirstPass(const CPLXMLNode *psNode,
125 : std::map<std::string, int> &oMapCountKeysFull,
126 : const std::string &osPrefixFull, int nDepth);
127 :
128 : char **ReadXMLToList(const CPLXMLNode *psNode, char **papszList,
129 : const std::map<std::string, int> &oMapCountKeysFullRef,
130 : std::map<std::string, int> &oMapCountKeysFull,
131 : std::map<std::string, int> &oMapCountKeys,
132 : const std::string &osPrefix,
133 : const std::string &osPrefixFull);
134 :
135 : public:
136 : GDALMDReaderBase(const char *pszPath, char **papszSiblingFiles);
137 : virtual ~GDALMDReaderBase();
138 :
139 : /**
140 : * @brief Get specified metadata domain
141 : * @param pszDomain The metadata domain to return
142 : * @return List of metadata items
143 : */
144 : virtual char **GetMetadataDomain(const char *pszDomain);
145 : /**
146 : * @brief Fill provided metadata store class
147 : * @param poMDMD Metadata store class
148 : * @return true on success or false
149 : */
150 : virtual bool FillMetadata(GDALMultiDomainMetadata *poMDMD);
151 : /**
152 : * @brief Determine whether the input parameter correspond to the particular
153 : * provider of remote sensing data completely
154 : * @return True if all needed sources files found
155 : */
156 : virtual bool HasRequiredFiles() const = 0;
157 : /**
158 : * @brief Get metadata file names. The caller become owner of returned list
159 : * and have to free it via CSLDestroy.
160 : * @return A file name list
161 : */
162 : virtual char **GetMetadataFiles() const = 0;
163 :
164 : protected:
165 : /**
166 : * @brief Load metadata to the correspondent IMD, RPB, IMAGERY and DEFAULT
167 : * domains
168 : */
169 : virtual void LoadMetadata();
170 : /**
171 : * @brief Convert string like 2012-02-25T00:25:59.9440000Z to time
172 : * @param pszDateTime String to convert
173 : * @return value in second sinc epoch 1970-01-01 00:00:00
174 : */
175 : virtual GIntBig GetAcquisitionTimeFromString(const char *pszDateTime);
176 : /**
177 : * @brief ReadXMLToList Transform xml to list of NULL terminated name=value
178 : * strings
179 : * @param psNode A xml node to process
180 : * @param papszList A list to fill with name=value strings
181 : * @param pszName A name of parent node. For root xml node should be empty.
182 : * If name is not empty, the sibling nodes will not proceed
183 : * @return An input list filled with values
184 : */
185 : virtual char **ReadXMLToList(CPLXMLNode *psNode, char **papszList,
186 : const char *pszName = "");
187 : /**
188 : * @brief AddXMLNameValueToList Execute from ReadXMLToList to add name and
189 : * value to list. One can override this function for special
190 : * processing input values before add to list.
191 : * @param papszList A list to fill with name=value strings
192 : * @param pszName A name to add
193 : * @param pszValue A value to add
194 : * @return An input list filled with values
195 : */
196 : virtual char **AddXMLNameValueToList(char **papszList, const char *pszName,
197 : const char *pszValue);
198 :
199 : protected:
200 : //! @cond Doxygen_Suppress
201 : char **m_papszIMDMD = nullptr;
202 : char **m_papszRPCMD = nullptr;
203 : char **m_papszIMAGERYMD = nullptr;
204 : char **m_papszDEFAULTMD = nullptr;
205 : bool m_bIsMetadataLoad = false;
206 : //! @endcond
207 : };
208 :
209 : /**
210 : * The metadata reader main class.
211 : * The main purpose of this class is to provide an correspondent reader
212 : * for provided path.
213 : */
214 5166 : class CPL_DLL GDALMDReaderManager
215 : {
216 :
217 : CPL_DISALLOW_COPY_ASSIGN(GDALMDReaderManager)
218 :
219 : public:
220 : GDALMDReaderManager();
221 : virtual ~GDALMDReaderManager();
222 :
223 : /**
224 : * @brief Try to detect metadata reader correspondent to the provided
225 : * datasource path
226 : * @param pszPath a path to GDALDataset
227 : * @param papszSiblingFiles file list for metadata search purposes
228 : * @param nType a preferable reader type (may be the OR of MDReaders)
229 : * @return an appropriate reader or NULL if no such reader or error.
230 : * The pointer delete by the GDALMDReaderManager, so the user have not
231 : * delete it.
232 : */
233 : virtual GDALMDReaderBase *GetReader(const char *pszPath,
234 : char **papszSiblingFiles,
235 : GUInt32 nType = MDR_ANY);
236 :
237 : protected:
238 : //! @cond Doxygen_Suppress
239 : GDALMDReaderBase *m_pReader = nullptr;
240 : //! @endcond
241 : };
242 :
243 : // misc
244 : CPLString CPLStrip(const CPLString &osString, const char cChar);
245 : CPLString CPLStripQuotes(const CPLString &osString);
246 : char **GDALLoadRPBFile(const CPLString &osFilePath);
247 : char CPL_DLL **GDALLoadRPCFile(const CPLString &osFilePath);
248 : char **GDALLoadIMDFile(const CPLString &osFilePath);
249 : bool GDALCheckFileHeader(const CPLString &soFilePath, const char *pszTestString,
250 : int nBufferSize = 256);
251 :
252 : CPLErr GDALWriteRPBFile(const char *pszFilename, char **papszMD);
253 : CPLErr CPL_DLL GDALWriteRPCTXTFile(const char *pszFilename, char **papszMD);
254 : CPLErr GDALWriteIMDFile(const char *pszFilename, char **papszMD);
255 :
256 : #endif // GDAL_MDREADER_H_INCLUDED
|