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