gdal_mdreader.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /******************************************************************************
  2. * $Id: gdal_mdreader.h 29190 2015-05-13 21:40:30Z bishop $
  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. #ifndef GDAL_MDREADER_H_INCLUDED
  31. #define GDAL_MDREADER_H_INCLUDED
  32. #include "cpl_port.h"
  33. #include "gdal_priv.h"
  34. #define MD_DOMAIN_IMD "IMD" /**< image metadata section */
  35. #define MD_DOMAIN_RPC "RPC" /**< rpc metadata section */
  36. #define MD_DOMAIN_IMAGERY "IMAGERY" /**< imagery metadata section */
  37. #define MD_DOMAIN_DEFAULT "" /**< default metadata section */
  38. #define MD_NAME_ACQDATETIME "ACQUISITIONDATETIME" /**< Acquisition Date Time property name. The time should be in UTC */
  39. #define MD_NAME_SATELLITE "SATELLITEID" /**< Satellite identificator property name */
  40. #define MD_NAME_CLOUDCOVER "CLOUDCOVER" /**< Cloud coverage property name. The value between 0 - 100 or 999 if n/a */
  41. #define MD_NAME_MDTYPE "METADATATYPE" /**< Metadata reader type property name. The reader processed this metadata */
  42. #define MD_DATETIMEFORMAT "%Y-%m-%d %H:%M:%S" /**< Date time format */
  43. #define MD_CLOUDCOVER_NA "999" /**< The value if cloud cover is n/a */
  44. /**
  45. * RPC/RPB specific defines
  46. */
  47. #define RPC_LINE_OFF "LINE_OFF"
  48. #define RPC_SAMP_OFF "SAMP_OFF"
  49. #define RPC_LAT_OFF "LAT_OFF"
  50. #define RPC_LONG_OFF "LONG_OFF"
  51. #define RPC_HEIGHT_OFF "HEIGHT_OFF"
  52. #define RPC_LINE_SCALE "LINE_SCALE"
  53. #define RPC_SAMP_SCALE "SAMP_SCALE"
  54. #define RPC_LAT_SCALE "LAT_SCALE"
  55. #define RPC_LONG_SCALE "LONG_SCALE"
  56. #define RPC_HEIGHT_SCALE "HEIGHT_SCALE"
  57. #define RPC_LINE_NUM_COEFF "LINE_NUM_COEFF"
  58. #define RPC_LINE_DEN_COEFF "LINE_DEN_COEFF"
  59. #define RPC_SAMP_NUM_COEFF "SAMP_NUM_COEFF"
  60. #define RPC_SAMP_DEN_COEFF "SAMP_DEN_COEFF"
  61. /**
  62. * Enumerator of metadata readers
  63. */
  64. typedef enum {
  65. MDR_None = 0x00000000, /**< no reader */
  66. MDR_DG = 0x00000001, /**< Digital Globe, METADATATYPE=DG */
  67. MDR_GE = 0x00000002, /**< Geo Eye, METADATATYPE=GE */
  68. MDR_OV = 0x00000004, /**< Orb View, METADATATYPE=OV */
  69. MDR_PLEIADES = 0x00000008, /**< Pleiades, METADATATYPE=DIMAP */
  70. MDR_SPOT = 0x00000010, /**< Spot, METADATATYPE=DIMAP */
  71. MDR_RDK1 = 0x00000020, /**< Resurs DK1, METADATATYPE=MSP */
  72. MDR_LS = 0x00000040, /**< Landsat, METADATATYPE=ODL */
  73. MDR_RE = 0x00000080, /**< RapidEye, METADATATYPE=RE */
  74. MDR_KOMPSAT = 0x00000100, /**< Kompsat, METADATATYPE=KARI */
  75. MDR_EROS = 0x00000200, /**< EROS, METADATATYPE=EROS */
  76. MDR_ALOS = 0x00000400, /**< ALOS, METADATATYPE=ALOS */
  77. MDR_ANY = MDR_DG | MDR_GE | MDR_OV | MDR_PLEIADES | MDR_SPOT | MDR_RDK1 |
  78. MDR_LS | MDR_RE | MDR_KOMPSAT | MDR_EROS | MDR_ALOS /**< any reader */
  79. } MDReaders;
  80. /**
  81. * The base class for all metadata readers
  82. */
  83. class GDALMDReaderBase{
  84. public:
  85. GDALMDReaderBase(const char *pszPath, char **papszSiblingFiles);
  86. virtual ~GDALMDReaderBase();
  87. /**
  88. * @brief Get specified metadata domain
  89. * @param pszDomain The metadata domain to return
  90. * @return List of metadata items
  91. */
  92. virtual char ** GetMetadataDomain(const char *pszDomain);
  93. /**
  94. * @brief Fill provided metatada store class
  95. * @param poMDMD Metatada store class
  96. * @return true on success or false
  97. */
  98. virtual bool FillMetadata(GDALMultiDomainMetadata* poMDMD);
  99. /**
  100. * @brief Determine whether the input parameter correspond to the particular
  101. * provider of remote sensing data completely
  102. * @return True if all needed sources files found
  103. */
  104. virtual const bool HasRequiredFiles() const = 0;
  105. /**
  106. * @brief Get metadata file names. The caller become owner of returned list
  107. * and have to free it via CSLDestroy.
  108. * @return A file name list
  109. */
  110. virtual char** GetMetadataFiles() const = 0;
  111. protected:
  112. /**
  113. * @brief Load metadata to the correspondent IMD, RPB, IMAGERY and DEFAULT
  114. * domains
  115. */
  116. virtual void LoadMetadata();
  117. /**
  118. * @brief Convert string like 2012-02-25T00:25:59.9440000Z to time
  119. * @param pszDateTime String to convert
  120. * @return value in time_t
  121. */
  122. virtual const time_t GetAcquisitionTimeFromString(const char* pszDateTime);
  123. /**
  124. * @brief ReadXMLToList Transform xml to list of NULL terminated name=value
  125. * strings
  126. * @param psNode A xml node to process
  127. * @param papszList A list to fill with name=value strings
  128. * @param pszName A name of parent node. For root xml node should be empty.
  129. * If name is not empty, the sibling nodes will not proceed
  130. * @return An input list filled with values
  131. */
  132. virtual char** ReadXMLToList(CPLXMLNode* psNode, char** papszList,
  133. const char* pszName = "");
  134. /**
  135. * @brief AddXMLNameValueToList Execute from ReadXMLToList to add name and
  136. * value to list. One can override this function for special
  137. * processing input values before add to list.
  138. * @param papszList A list to fill with name=value strings
  139. * @param pszName A name to add
  140. * @param pszValue A value to add
  141. * @return An input list filled with values
  142. */
  143. virtual char** AddXMLNameValueToList(char** papszList, const char *pszName,
  144. const char *pszValue);
  145. protected:
  146. char **m_papszIMDMD;
  147. char **m_papszRPCMD;
  148. char **m_papszIMAGERYMD;
  149. char **m_papszDEFAULTMD;
  150. bool m_bIsMetadataLoad;
  151. };
  152. /**
  153. * The metadata reader main class.
  154. * The main purpose of this class is to provide an correspondent reader
  155. * for provided path.
  156. */
  157. class CPL_DLL GDALMDReaderManager{
  158. public:
  159. GDALMDReaderManager();
  160. virtual ~GDALMDReaderManager();
  161. /**
  162. * @brief Try to detect metadata reader correspondent to the provided
  163. * datasource path
  164. * @param pszPath a path to GDALDataset
  165. * @param papszSiblingFiles file list for metadata search purposes
  166. * @param nType a preferable reader type (may be the OR of MDReaders)
  167. * @return an appropriate reader or NULL if no such reader or error.
  168. * The pointer delete by the GDALMDReaderManager, so the user have not
  169. * delete it.
  170. */
  171. virtual GDALMDReaderBase* GetReader(const char *pszPath,
  172. char **papszSiblingFiles,
  173. GUInt32 nType = MDR_ANY);
  174. protected:
  175. GDALMDReaderBase *m_pReader;
  176. };
  177. // misc
  178. CPLString CPLStrip(const CPLString& osString, const char cChar);
  179. CPLString CPLStripQuotes(const CPLString& osString);
  180. char** GDALLoadRPBFile( const CPLString& osFilePath );
  181. char** GDALLoadRPCFile( const CPLString& osFilePath );
  182. char** GDALLoadIMDFile( const CPLString& osFilePath );
  183. const bool GDALCheckFileHeader(const CPLString& soFilePath,
  184. const char * pszTestString,
  185. int nBufferSize = 256);
  186. CPLErr GDALWriteRPBFile( const char *pszFilename, char **papszMD );
  187. CPLErr GDALWriteRPCTXTFile( const char *pszFilename, char **papszMD );
  188. CPLErr GDALWriteIMDFile( const char *pszFilename, char **papszMD );
  189. #endif //GDAL_MDREADER_H_INCLUDED