gdal_pam.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /******************************************************************************
  2. * $Id: gdal_pam.h 28899 2015-04-14 09:27:00Z rouault $
  3. *
  4. * Project: GDAL Core
  5. * Purpose: Declaration for Peristable Auxiliary Metadata classes.
  6. * Author: Frank Warmerdam, warmerdam@pobox.com
  7. *
  8. ******************************************************************************
  9. * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.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. #ifndef GDAL_PAM_H_INCLUDED
  30. #define GDAL_PAM_H_INCLUDED
  31. #include "gdal_priv.h"
  32. class GDALPamRasterBand;
  33. /* Clone Info Flags */
  34. #define GCIF_GEOTRANSFORM 0x01
  35. #define GCIF_PROJECTION 0x02
  36. #define GCIF_METADATA 0x04
  37. #define GCIF_GCPS 0x08
  38. #define GCIF_NODATA 0x001000
  39. #define GCIF_CATEGORYNAMES 0x002000
  40. #define GCIF_MINMAX 0x004000
  41. #define GCIF_SCALEOFFSET 0x008000
  42. #define GCIF_UNITTYPE 0x010000
  43. #define GCIF_COLORTABLE 0x020000
  44. #define GCIF_COLORINTERP 0x020000
  45. #define GCIF_BAND_METADATA 0x040000
  46. #define GCIF_RAT 0x080000
  47. #define GCIF_MASK 0x100000
  48. #define GCIF_BAND_DESCRIPTION 0x200000
  49. #define GCIF_ONLY_IF_MISSING 0x10000000
  50. #define GCIF_PROCESS_BANDS 0x20000000
  51. #define GCIF_PAM_DEFAULT (GCIF_GEOTRANSFORM | GCIF_PROJECTION | \
  52. GCIF_METADATA | GCIF_GCPS | \
  53. GCIF_NODATA | GCIF_CATEGORYNAMES | \
  54. GCIF_MINMAX | GCIF_SCALEOFFSET | \
  55. GCIF_UNITTYPE | GCIF_COLORTABLE | \
  56. GCIF_COLORINTERP | GCIF_BAND_METADATA | \
  57. GCIF_RAT | GCIF_MASK | \
  58. GCIF_ONLY_IF_MISSING | GCIF_PROCESS_BANDS|\
  59. GCIF_BAND_DESCRIPTION)
  60. /* GDAL PAM Flags */
  61. /* ERO 2011/04/13 : GPF_AUXMODE seems to be unimplemented */
  62. #define GPF_DIRTY 0x01 // .pam file needs to be written on close
  63. #define GPF_TRIED_READ_FAILED 0x02 // no need to keep trying to read .pam.
  64. #define GPF_DISABLED 0x04 // do not try any PAM stuff.
  65. #define GPF_AUXMODE 0x08 // store info in .aux (HFA) file.
  66. #define GPF_NOSAVE 0x10 // do not try to save pam info.
  67. /* ==================================================================== */
  68. /* GDALDatasetPamInfo */
  69. /* */
  70. /* We make these things a seperate structure of information */
  71. /* primarily so we can modify it without altering the size of */
  72. /* the GDALPamDataset. It is an effort to reduce ABI churn for */
  73. /* driver plugins. */
  74. /* ==================================================================== */
  75. class GDALDatasetPamInfo
  76. {
  77. public:
  78. char *pszPamFilename;
  79. char *pszProjection;
  80. int bHaveGeoTransform;
  81. double adfGeoTransform[6];
  82. int nGCPCount;
  83. GDAL_GCP *pasGCPList;
  84. char *pszGCPProjection;
  85. CPLString osPhysicalFilename;
  86. CPLString osSubdatasetName;
  87. CPLString osAuxFilename;
  88. int bHasMetadata;
  89. };
  90. /* ******************************************************************** */
  91. /* GDALPamDataset */
  92. /* ******************************************************************** */
  93. class CPL_DLL GDALPamDataset : public GDALDataset
  94. {
  95. friend class GDALPamRasterBand;
  96. private:
  97. int IsPamFilenameAPotentialSiblingFile();
  98. protected:
  99. GDALPamDataset(void);
  100. int nPamFlags;
  101. GDALDatasetPamInfo *psPam;
  102. virtual CPLXMLNode *SerializeToXML( const char *);
  103. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  104. virtual CPLErr TryLoadXML(char **papszSiblingFiles = NULL);
  105. virtual CPLErr TrySaveXML();
  106. CPLErr TryLoadAux(char **papszSiblingFiles = NULL);
  107. CPLErr TrySaveAux();
  108. virtual const char *BuildPamFilename();
  109. void PamInitialize();
  110. void PamClear();
  111. void SetPhysicalFilename( const char * );
  112. const char *GetPhysicalFilename();
  113. void SetSubdatasetName( const char *);
  114. const char *GetSubdatasetName();
  115. public:
  116. virtual ~GDALPamDataset();
  117. virtual void FlushCache(void);
  118. virtual const char *GetProjectionRef(void);
  119. virtual CPLErr SetProjection( const char * );
  120. virtual CPLErr GetGeoTransform( double * );
  121. virtual CPLErr SetGeoTransform( double * );
  122. virtual int GetGCPCount();
  123. virtual const char *GetGCPProjection();
  124. virtual const GDAL_GCP *GetGCPs();
  125. virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
  126. const char *pszGCPProjection );
  127. virtual CPLErr SetMetadata( char ** papszMetadata,
  128. const char * pszDomain = "" );
  129. virtual CPLErr SetMetadataItem( const char * pszName,
  130. const char * pszValue,
  131. const char * pszDomain = "" );
  132. virtual char **GetMetadata( const char * pszDomain = "" );
  133. virtual const char *GetMetadataItem( const char * pszName,
  134. const char * pszDomain = "" );
  135. virtual char **GetFileList(void);
  136. virtual CPLErr CloneInfo( GDALDataset *poSrcDS, int nCloneInfoFlags );
  137. virtual CPLErr IBuildOverviews( const char *pszResampling,
  138. int nOverviews, int *panOverviewList,
  139. int nListBands, int *panBandList,
  140. GDALProgressFunc pfnProgress,
  141. void * pProgressData );
  142. // "semi private" methods.
  143. void MarkPamDirty() { nPamFlags |= GPF_DIRTY; }
  144. GDALDatasetPamInfo *GetPamInfo() { return psPam; }
  145. int GetPamFlags() { return nPamFlags; }
  146. void SetPamFlags(int nValue ) { nPamFlags = nValue; }
  147. };
  148. /* ==================================================================== */
  149. /* GDALRasterBandPamInfo */
  150. /* */
  151. /* We make these things a seperate structure of information */
  152. /* primarily so we can modify it without altering the size of */
  153. /* the GDALPamDataset. It is an effort to reduce ABI churn for */
  154. /* driver plugins. */
  155. /* ==================================================================== */
  156. typedef struct {
  157. GDALPamDataset *poParentDS;
  158. int bNoDataValueSet;
  159. double dfNoDataValue;
  160. GDALColorTable *poColorTable;
  161. GDALColorInterp eColorInterp;
  162. char *pszUnitType;
  163. char **papszCategoryNames;
  164. double dfOffset;
  165. double dfScale;
  166. int bHaveMinMax;
  167. double dfMin;
  168. double dfMax;
  169. int bHaveStats;
  170. double dfMean;
  171. double dfStdDev;
  172. CPLXMLNode *psSavedHistograms;
  173. GDALRasterAttributeTable *poDefaultRAT;
  174. } GDALRasterBandPamInfo;
  175. /* ******************************************************************** */
  176. /* GDALPamRasterBand */
  177. /* ******************************************************************** */
  178. class CPL_DLL GDALPamRasterBand : public GDALRasterBand
  179. {
  180. friend class GDALPamDataset;
  181. protected:
  182. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  183. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  184. void PamInitialize();
  185. void PamClear();
  186. GDALRasterBandPamInfo *psPam;
  187. public:
  188. GDALPamRasterBand();
  189. virtual ~GDALPamRasterBand();
  190. virtual void SetDescription( const char * );
  191. virtual CPLErr SetNoDataValue( double );
  192. virtual double GetNoDataValue( int *pbSuccess = NULL );
  193. virtual CPLErr SetColorTable( GDALColorTable * );
  194. virtual GDALColorTable *GetColorTable();
  195. virtual CPLErr SetColorInterpretation( GDALColorInterp );
  196. virtual GDALColorInterp GetColorInterpretation();
  197. virtual const char *GetUnitType();
  198. CPLErr SetUnitType( const char * );
  199. virtual char **GetCategoryNames();
  200. virtual CPLErr SetCategoryNames( char ** );
  201. virtual double GetOffset( int *pbSuccess = NULL );
  202. CPLErr SetOffset( double );
  203. virtual double GetScale( int *pbSuccess = NULL );
  204. CPLErr SetScale( double );
  205. virtual CPLErr GetHistogram( double dfMin, double dfMax,
  206. int nBuckets, GUIntBig * panHistogram,
  207. int bIncludeOutOfRange, int bApproxOK,
  208. GDALProgressFunc, void *pProgressData );
  209. virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
  210. int *pnBuckets, GUIntBig ** ppanHistogram,
  211. int bForce,
  212. GDALProgressFunc, void *pProgressData);
  213. virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
  214. int nBuckets, GUIntBig *panHistogram );
  215. virtual CPLErr SetMetadata( char ** papszMetadata,
  216. const char * pszDomain = "" );
  217. virtual CPLErr SetMetadataItem( const char * pszName,
  218. const char * pszValue,
  219. const char * pszDomain = "" );
  220. virtual GDALRasterAttributeTable *GetDefaultRAT();
  221. virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
  222. // new in GDALPamRasterBand.
  223. virtual CPLErr CloneInfo( GDALRasterBand *poSrcBand, int nCloneInfoFlags );
  224. // "semi private" methods.
  225. GDALRasterBandPamInfo *GetPamInfo() { return psPam; }
  226. };
  227. // These are mainly helper functions for internal use.
  228. int CPL_DLL PamParseHistogram( CPLXMLNode *psHistItem,
  229. double *pdfMin, double *pdfMax,
  230. int *pnBuckets, GUIntBig **ppanHistogram,
  231. int *pbIncludeOutOfRange, int *pbApproxOK );
  232. CPLXMLNode CPL_DLL *
  233. PamFindMatchingHistogram( CPLXMLNode *psSavedHistograms,
  234. double dfMin, double dfMax, int nBuckets,
  235. int bIncludeOutOfRange, int bApproxOK );
  236. CPLXMLNode CPL_DLL *
  237. PamHistogramToXMLTree( double dfMin, double dfMax,
  238. int nBuckets, GUIntBig * panHistogram,
  239. int bIncludeOutOfRange, int bApprox );
  240. // For managing the proxy file database.
  241. const char CPL_DLL * PamGetProxy( const char * );
  242. const char CPL_DLL * PamAllocateProxy( const char * );
  243. const char CPL_DLL * PamDeallocateProxy( const char * );
  244. void CPL_DLL PamCleanProxyDB( void );
  245. #endif /* ndef GDAL_PAM_H_INCLUDED */