GDAL
vrtdataset.h
1 /******************************************************************************
2  * $Id: vrtdataset.h 35350 2016-09-07 07:21:52Z rouault $
3  *
4  * Project: Virtual GDAL Datasets
5  * Purpose: Declaration of virtual gdal dataset classes.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com>
10  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
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 VIRTUALDATASET_H_INCLUDED
32 #define VIRTUALDATASET_H_INCLUDED
33 
34 #include "cpl_hash_set.h"
35 #include "gdal_pam.h"
36 #include "gdal_priv.h"
37 #include "gdal_vrt.h"
38 
39 #include <map>
40 #include <vector>
41 
42 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
43 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
44 
45 #if 0
46 int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
47  int nPointCount,
48  double *padfX, double *padfY, double *padfZ,
49  int *panSuccess );
50 void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
51 #endif
52 
53 /************************************************************************/
54 /* VRTOverviewInfo() */
55 /************************************************************************/
57 {
58 public:
59  CPLString osFilename;
60  int nBand;
61  GDALRasterBand *poBand;
62  int bTriedToOpen;
63 
64  VRTOverviewInfo() : nBand(0), poBand(NULL), bTriedToOpen(FALSE) {}
65  ~VRTOverviewInfo() {
66  if( poBand == NULL )
67  /* do nothing */;
68  else if( poBand->GetDataset()->GetShared() )
69  GDALClose( (GDALDatasetH) poBand->GetDataset() );
70  else
71  poBand->GetDataset()->Dereference();
72  }
73 };
74 
75 
76 /************************************************************************/
77 /* VRTSource */
78 /************************************************************************/
79 
80 class CPL_DLL VRTSource
81 {
82 public:
83  virtual ~VRTSource();
84 
85  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
86  void *pData, int nBufXSize, int nBufYSize,
87  GDALDataType eBufType,
88  GSpacing nPixelSpace, GSpacing nLineSpace,
89  GDALRasterIOExtraArg* psExtraArg ) = 0;
90 
91  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
92  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
93  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0;
94  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
95  int bApproxOK,
96  double *pdfMin, double *pdfMax,
97  double *pdfMean, double *pdfStdDev,
98  GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
99  virtual CPLErr GetHistogram( int nXSize, int nYSize,
100  double dfMin, double dfMax,
101  int nBuckets, GUIntBig * panHistogram,
102  int bIncludeOutOfRange, int bApproxOK,
103  GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
104 
105  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
106  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
107 
108  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
109  int *pnMaxSize, CPLHashSet* hSetFiles);
110 
111  virtual int IsSimpleSource() { return FALSE; }
112 };
113 
114 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
115 
116 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
117 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
118 
119 /************************************************************************/
120 /* VRTDataset */
121 /************************************************************************/
122 
123 class VRTRasterBand;
124 
125 class CPL_DLL VRTDataset : public GDALDataset
126 {
127  friend class VRTRasterBand;
128 
129  char *m_pszProjection;
130 
131  int m_bGeoTransformSet;
132  double m_adfGeoTransform[6];
133 
134  int m_nGCPCount;
135  GDAL_GCP *m_pasGCPList;
136  char *m_pszGCPProjection;
137 
138  int m_bNeedsFlush;
139  int m_bWritable;
140 
141  char *m_pszVRTPath;
142 
143  VRTRasterBand *m_poMaskBand;
144 
145  int m_bCompatibleForDatasetIO;
146  int CheckCompatibleForDatasetIO();
147  std::vector<GDALDataset*> m_apoOverviews;
148  std::vector<GDALDataset*> m_apoOverviewsBak;
149 
150  protected:
151  virtual int CloseDependentDatasets();
152 
153  public:
154  VRTDataset(int nXSize, int nYSize);
155  virtual ~VRTDataset();
156 
157  void SetNeedsFlush() { m_bNeedsFlush = TRUE; }
158  virtual void FlushCache();
159 
160  void SetWritable(int bWritableIn) { m_bWritable = bWritableIn; }
161 
162  virtual CPLErr CreateMaskBand( int nFlags );
163  void SetMaskBand(VRTRasterBand* poMaskBand);
164 
165  virtual const char *GetProjectionRef(void);
166  virtual CPLErr SetProjection( const char * );
167  virtual CPLErr GetGeoTransform( double * );
168  virtual CPLErr SetGeoTransform( double * );
169 
170  virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
171  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
172  const char *pszDomain = "" );
173 
174  virtual char** GetMetadata( const char *pszDomain = "" );
175 
176  virtual int GetGCPCount();
177  virtual const char *GetGCPProjection();
178  virtual const GDAL_GCP *GetGCPs();
179  virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
180  const char *pszGCPProjection );
181 
182  virtual CPLErr AddBand( GDALDataType eType,
183  char **papszOptions=NULL );
184 
185  virtual char **GetFileList();
186 
187  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
188  int nXOff, int nYOff, int nXSize, int nYSize,
189  void * pData, int nBufXSize, int nBufYSize,
190  GDALDataType eBufType,
191  int nBandCount, int *panBandMap,
192  GSpacing nPixelSpace, GSpacing nLineSpace,
193  GSpacing nBandSpace,
194  GDALRasterIOExtraArg* psExtraArg);
195 
196  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
197  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
198 
199  virtual CPLErr IBuildOverviews( const char *, int, int *,
200  int, int *, GDALProgressFunc, void * );
201 
202  /* Used by PDF driver for example */
203  GDALDataset* GetSingleSimpleSource();
204  void BuildVirtualOverviews();
205 
206  void UnsetPreservedRelativeFilenames();
207 
208  static int Identify( GDALOpenInfo * );
209  static GDALDataset *Open( GDALOpenInfo * );
210  static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
211  static GDALDataset *Create( const char * pszName,
212  int nXSize, int nYSize, int nBands,
213  GDALDataType eType, char ** papszOptions );
214  static CPLErr Delete( const char * pszFilename );
215 };
216 
217 /************************************************************************/
218 /* VRTWarpedDataset */
219 /************************************************************************/
220 
221 class GDALWarpOperation;
222 class VRTWarpedRasterBand;
223 
224 class CPL_DLL VRTWarpedDataset : public VRTDataset
225 {
226  int m_nBlockXSize;
227  int m_nBlockYSize;
228  GDALWarpOperation *m_poWarper;
229 
230  int m_nOverviewCount;
231  VRTWarpedDataset **m_papoOverviews;
232  int m_nSrcOvrLevel;
233 
234  void CreateImplicitOverviews();
235 
236  friend class VRTWarpedRasterBand;
237 
238  protected:
239  virtual int CloseDependentDatasets();
240 
241 public:
242  VRTWarpedDataset( int nXSize, int nYSize );
243  virtual ~VRTWarpedDataset();
244 
245  CPLErr Initialize( /* GDALWarpOptions */ void * );
246 
247  virtual CPLErr IBuildOverviews( const char *, int, int *,
248  int, int *, GDALProgressFunc, void * );
249 
250  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
251  const char *pszDomain = "" );
252 
253  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
254  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
255 
256  virtual CPLErr AddBand( GDALDataType eType,
257  char **papszOptions=NULL );
258 
259  virtual char **GetFileList();
260 
261  CPLErr ProcessBlock( int iBlockX, int iBlockY );
262 
263  void GetBlockSize( int *, int * );
264 };
265 
266 /************************************************************************/
267 /* VRTPansharpenedDataset */
268 /************************************************************************/
269 
271 
272 typedef enum
273 {
274  GTAdjust_Union,
275  GTAdjust_Intersection,
276  GTAdjust_None,
277  GTAdjust_NoneWithoutWarning
278 } GTAdjustment;
279 
281 {
282  friend class VRTPansharpenedRasterBand;
283 
284  int m_nBlockXSize;
285  int m_nBlockYSize;
286  GDALPansharpenOperation* m_poPansharpener;
287  VRTPansharpenedDataset* m_poMainDataset;
288  std::vector<VRTPansharpenedDataset*> m_apoOverviewDatasets;
289  std::map<CPLString,CPLString> m_oMapToRelativeFilenames; // map from absolute to relative
290 
291  int m_bLoadingOtherBands;
292 
293  GByte *m_pabyLastBufferBandRasterIO;
294  int m_nLastBandRasterIOXOff;
295  int m_nLastBandRasterIOYOff;
296  int m_nLastBandRasterIOXSize;
297  int m_nLastBandRasterIOYSize;
298  GDALDataType m_eLastBandRasterIODataType;
299 
300  GTAdjustment m_eGTAdjustment;
301  int m_bNoDataDisabled;
302 
303  std::vector<GDALDataset*> m_apoDatasetsToClose;
304 
305  protected:
306  virtual int CloseDependentDatasets();
307 
308 public:
309  VRTPansharpenedDataset( int nXSize, int nYSize );
311 
312  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
313  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
314 
315  CPLErr XMLInit( CPLXMLNode *psTree, const char *pszVRTPath,
316  GDALRasterBandH hPanchroBandIn,
317  int nInputSpectralBandsIn,
318  GDALRasterBandH* pahInputSpectralBandsIn );
319 
320  virtual CPLErr AddBand( GDALDataType eType,
321  char **papszOptions=NULL );
322 
323  virtual char **GetFileList();
324 
325  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
326  int nXOff, int nYOff, int nXSize, int nYSize,
327  void * pData, int nBufXSize, int nBufYSize,
328  GDALDataType eBufType,
329  int nBandCount, int *panBandMap,
330  GSpacing nPixelSpace, GSpacing nLineSpace,
331  GSpacing nBandSpace,
332  GDALRasterIOExtraArg* psExtraArg);
333 
334  void GetBlockSize( int *, int * );
335 
336  GDALPansharpenOperation* GetPansharpener() { return m_poPansharpener; }
337 };
338 
339 /************************************************************************/
340 /* VRTRasterBand */
341 /* */
342 /* Provides support for all the various kinds of metadata but */
343 /* no raster access. That is handled by derived classes. */
344 /************************************************************************/
345 
346 class CPL_DLL VRTRasterBand : public GDALRasterBand
347 {
348  protected:
349  int m_bIsMaskBand;
350 
351  int m_bNoDataValueSet;
352  int m_bHideNoDataValue; // If set to true, will not report the existence of nodata
353  double m_dfNoDataValue;
354 
355  GDALColorTable *m_poColorTable;
356 
357  GDALColorInterp m_eColorInterp;
358 
359  char *m_pszUnitType;
360  char **m_papszCategoryNames;
361 
362  double m_dfOffset;
363  double m_dfScale;
364 
365  CPLXMLNode *m_psSavedHistograms;
366 
367  void Initialize( int nXSize, int nYSize );
368 
369  std::vector<VRTOverviewInfo> m_apoOverviews;
370 
371  VRTRasterBand *m_poMaskBand;
372 
373  public:
374 
375  VRTRasterBand();
376  virtual ~VRTRasterBand();
377 
378  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
379  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
380 
381  virtual CPLErr SetNoDataValue( double );
382  virtual double GetNoDataValue( int *pbSuccess = NULL );
383  virtual CPLErr DeleteNoDataValue();
384 
385  virtual CPLErr SetColorTable( GDALColorTable * );
386  virtual GDALColorTable *GetColorTable();
387 
388  virtual CPLErr SetColorInterpretation( GDALColorInterp );
389  virtual GDALColorInterp GetColorInterpretation();
390 
391  virtual const char *GetUnitType();
392  CPLErr SetUnitType( const char * );
393 
394  virtual char **GetCategoryNames();
395  virtual CPLErr SetCategoryNames( char ** );
396 
397  virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
398  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
399  const char *pszDomain = "" );
400 
401  virtual double GetOffset( int *pbSuccess = NULL );
402  CPLErr SetOffset( double );
403  virtual double GetScale( int *pbSuccess = NULL );
404  CPLErr SetScale( double );
405 
406  virtual int GetOverviewCount();
407  virtual GDALRasterBand *GetOverview(int);
408 
409  virtual CPLErr GetHistogram( double dfMin, double dfMax,
410  int nBuckets, GUIntBig * panHistogram,
411  int bIncludeOutOfRange, int bApproxOK,
412  GDALProgressFunc, void *pProgressData );
413 
414  virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
415  int *pnBuckets, GUIntBig ** ppanHistogram,
416  int bForce,
417  GDALProgressFunc, void *pProgressData);
418 
419  virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
420  int nBuckets, GUIntBig *panHistogram );
421 
422  CPLErr CopyCommonInfoFrom( GDALRasterBand * );
423 
424  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
425  int *pnMaxSize, CPLHashSet* hSetFiles);
426 
427  virtual void SetDescription( const char * );
428 
429  virtual GDALRasterBand *GetMaskBand();
430  virtual int GetMaskFlags();
431 
432  virtual CPLErr CreateMaskBand( int nFlags );
433 
434  void SetMaskBand(VRTRasterBand* poMaskBand);
435 
436  void SetIsMaskBand();
437 
438  CPLErr UnsetNoDataValue();
439 
440  virtual int CloseDependentDatasets();
441 
442  virtual int IsSourcedRasterBand() { return FALSE; }
443  virtual int IsPansharpenRasterBand() { return FALSE; }
444 };
445 
446 /************************************************************************/
447 /* VRTSourcedRasterBand */
448 /************************************************************************/
449 
450 class VRTSimpleSource;
451 
452 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
453 {
454  private:
455  int m_nRecursionCounter;
456  CPLString m_osLastLocationInfo;
457  char **m_papszSourceList;
458 
459  void Initialize( int nXSize, int nYSize );
460 
461  int CanUseSourcesMinMaxImplementations();
462 
463  public:
464  int nSources;
465  VRTSource **papoSources;
466  int bEqualAreas;
467 
468  VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
470  int nXSize, int nYSize );
471  VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
472  GDALDataType eType,
473  int nXSize, int nYSize );
474  virtual ~VRTSourcedRasterBand();
475 
476  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
477  void *, int, int, GDALDataType,
478  GSpacing nPixelSpace, GSpacing nLineSpace,
479  GDALRasterIOExtraArg* psExtraArg);
480 
481  virtual char **GetMetadataDomainList();
482  virtual const char *GetMetadataItem( const char * pszName,
483  const char * pszDomain = "" );
484  virtual char **GetMetadata( const char * pszDomain = "" );
485  virtual CPLErr SetMetadata( char ** papszMetadata,
486  const char * pszDomain = "" );
487  virtual CPLErr SetMetadataItem( const char * pszName,
488  const char * pszValue,
489  const char * pszDomain = "" );
490 
491  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
492  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
493 
494  virtual double GetMinimum( int *pbSuccess = NULL );
495  virtual double GetMaximum(int *pbSuccess = NULL );
496  virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax );
497  virtual CPLErr ComputeStatistics( int bApproxOK,
498  double *pdfMin, double *pdfMax,
499  double *pdfMean, double *pdfStdDev,
500  GDALProgressFunc pfnProgress, void *pProgressData );
501  virtual CPLErr GetHistogram( double dfMin, double dfMax,
502  int nBuckets, GUIntBig * panHistogram,
503  int bIncludeOutOfRange, int bApproxOK,
504  GDALProgressFunc pfnProgress, void *pProgressData );
505 
506  CPLErr AddSource( VRTSource * );
507  CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
508  double dfSrcXOff=-1, double dfSrcYOff=-1,
509  double dfSrcXSize=-1, double dfSrcYSize=-1,
510  double dfDstXOff=-1, double dfDstYOff=-1,
511  double dfDstXSize=-1, double dfDstYSize=-1,
512  const char *pszResampling = "near",
513  double dfNoDataValue = VRT_NODATA_UNSET);
514  CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
515  double dfSrcXOff=-1, double dfSrcYOff=-1,
516  double dfSrcXSize=-1, double dfSrcYSize=-1,
517  double dfDstXOff=-1, double dfDstYOff=-1,
518  double dfDstXSize=-1, double dfDstYSize=-1,
519  double dfScaleOff=0.0,
520  double dfScaleRatio=1.0,
521  double dfNoDataValue = VRT_NODATA_UNSET,
522  int nColorTableComponent = 0);
523 
524  CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
525  double dfSrcXOff=-1, double dfSrcYOff=-1,
526  double dfSrcXSize=-1, double dfSrcYSize=-1,
527  double dfDstXOff=-1, double dfDstYOff=-1,
528  double dfDstXSize=-1, double dfDstYSize=-1 );
529 
530  CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
531  double dfNoDataValue = VRT_NODATA_UNSET );
532 
533  void ConfigureSource(VRTSimpleSource *poSimpleSource,
534  GDALRasterBand *poSrcBand,
535  int bAddAsMaskBand,
536  double dfSrcXOff, double dfSrcYOff,
537  double dfSrcXSize, double dfSrcYSize,
538  double dfDstXOff, double dfDstYOff,
539  double dfDstXSize, double dfDstYSize);
540 
541  virtual CPLErr IReadBlock( int, int, void * );
542 
543  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
544  int *pnMaxSize, CPLHashSet* hSetFiles);
545 
546  virtual int CloseDependentDatasets();
547 
548  virtual int IsSourcedRasterBand() { return TRUE; }
549 };
550 
551 /************************************************************************/
552 /* VRTWarpedRasterBand */
553 /************************************************************************/
554 
555 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
556 {
557  public:
558  VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
559  GDALDataType eType = GDT_Unknown );
560  virtual ~VRTWarpedRasterBand();
561 
562  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
563  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
564 
565  virtual CPLErr IReadBlock( int, int, void * );
566  virtual CPLErr IWriteBlock( int, int, void * );
567 
568  virtual int GetOverviewCount();
569  virtual GDALRasterBand *GetOverview(int);
570 };
571 /************************************************************************/
572 /* VRTPansharpenedRasterBand */
573 /************************************************************************/
574 
576 {
577  int m_nIndexAsPansharpenedBand;
578 
579  public:
580  VRTPansharpenedRasterBand( GDALDataset *poDS, int nBand,
581  GDALDataType eDataType = GDT_Unknown );
582  virtual ~VRTPansharpenedRasterBand();
583 
584  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
585  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
586 
587  virtual CPLErr IReadBlock( int, int, void * );
588 
589  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
590  int nXOff, int nYOff, int nXSize, int nYSize,
591  void * pData, int nBufXSize, int nBufYSize,
592  GDALDataType eBufType,
593  GSpacing nPixelSpace, GSpacing nLineSpace,
594  GDALRasterIOExtraArg* psExtraArg);
595 
596  virtual int GetOverviewCount();
597  virtual GDALRasterBand *GetOverview(int);
598 
599  virtual int IsPansharpenRasterBand() { return TRUE; }
600 
601  void SetIndexAsPansharpenedBand(int nIdx) { m_nIndexAsPansharpenedBand = nIdx; }
602  int GetIndexAsPansharpenedBand() const { return m_nIndexAsPansharpenedBand; }
603 };
604 
605 /************************************************************************/
606 /* VRTDerivedRasterBand */
607 /************************************************************************/
608 
610 {
611 
612  public:
613  char *pszFuncName;
614  GDALDataType eSourceTransferType;
615 
616  VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
617  VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
618  GDALDataType eType, int nXSize, int nYSize);
619  virtual ~VRTDerivedRasterBand();
620 
621  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
622  void *, int, int, GDALDataType,
623  GSpacing nPixelSpace, GSpacing nLineSpace,
624  GDALRasterIOExtraArg* psExtraArg );
625 
626  static CPLErr AddPixelFunction
627  (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
628  static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
629 
630  void SetPixelFunctionName(const char *pszFuncName);
631  void SetSourceTransferType(GDALDataType eDataType);
632 
633  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
634  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
635 
636 };
637 
638 /************************************************************************/
639 /* VRTRawRasterBand */
640 /************************************************************************/
641 
642 class RawRasterBand;
643 
644 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
645 {
646  RawRasterBand *m_poRawRaster;
647 
648  char *m_pszSourceFilename;
649  int m_bRelativeToVRT;
650 
651  public:
652  VRTRawRasterBand( GDALDataset *poDS, int nBand,
653  GDALDataType eType = GDT_Unknown );
654  virtual ~VRTRawRasterBand();
655 
656  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
657  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
658 
659  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
660  void *, int, int, GDALDataType,
661  GSpacing nPixelSpace, GSpacing nLineSpace,
662  GDALRasterIOExtraArg* psExtraArg );
663 
664  virtual CPLErr IReadBlock( int, int, void * );
665  virtual CPLErr IWriteBlock( int, int, void * );
666 
667  CPLErr SetRawLink( const char *pszFilename,
668  const char *pszVRTPath,
669  int bRelativeToVRT,
670  vsi_l_offset nImageOffset,
671  int nPixelOffset, int nLineOffset,
672  const char *pszByteOrder );
673 
674  void ClearRawLink();
675 
676  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
677  int *pnMaxSize, CPLHashSet* hSetFiles);
678 };
679 
680 /************************************************************************/
681 /* VRTDriver */
682 /************************************************************************/
683 
684 class VRTDriver : public GDALDriver
685 {
686  void *m_pDeserializerData;
687 
688  public:
689  VRTDriver();
690  ~VRTDriver();
691 
692  char **papszSourceParsers;
693 
694  virtual char **GetMetadataDomainList();
695  virtual char **GetMetadata( const char * pszDomain = "" );
696  virtual CPLErr SetMetadata( char ** papszMetadata,
697  const char * pszDomain = "" );
698 
699  VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
700  void AddSourceParser( const char *pszElementName,
701  VRTSourceParser pfnParser );
702 };
703 
704 /************************************************************************/
705 /* VRTSimpleSource */
706 /************************************************************************/
707 
708 class CPL_DLL VRTSimpleSource : public VRTSource
709 {
710 protected:
711  GDALRasterBand *m_poRasterBand;
712 
713  /* when poRasterBand is a mask band, poMaskBandMainBand is the band */
714  /* from which the mask band is taken */
715  GDALRasterBand *m_poMaskBandMainBand;
716 
717  double m_dfSrcXOff;
718  double m_dfSrcYOff;
719  double m_dfSrcXSize;
720  double m_dfSrcYSize;
721 
722  double m_dfDstXOff;
723  double m_dfDstYOff;
724  double m_dfDstXSize;
725  double m_dfDstYSize;
726 
727  int m_bNoDataSet;
728  double m_dfNoDataValue;
729  CPLString m_osResampling;
730 
731  int m_nMaxValue;
732 
733  int m_bRelativeToVRTOri;
734  CPLString m_osSourceFileNameOri;
735 
736  int NeedMaxValAdjustment() const;
737 
738 public:
739  VRTSimpleSource();
740  VRTSimpleSource(const VRTSimpleSource* poSrcSource,
741  double dfXDstRatio, double dfYDstRatio);
742  virtual ~VRTSimpleSource();
743 
744  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
745  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
746 
747  void SetSrcBand( GDALRasterBand * );
748  void SetSrcMaskBand( GDALRasterBand * );
749  void SetSrcWindow( double, double, double, double );
750  void SetDstWindow( double, double, double, double );
751  void SetNoDataValue( double dfNoDataValue );
752  const CPLString& GetResampling() const { return m_osResampling; }
753  void SetResampling( const char* pszResampling );
754 
755  int GetSrcDstWindow( int, int, int, int, int, int,
756  double *pdfReqXOff, double *pdfReqYOff,
757  double *pdfReqXSize, double *pdfReqYSize,
758  int *, int *, int *, int *,
759  int *, int *, int *, int * );
760 
761  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
762  void *pData, int nBufXSize, int nBufYSize,
763  GDALDataType eBufType,
764  GSpacing nPixelSpace, GSpacing nLineSpace,
765  GDALRasterIOExtraArg* psExtraArg );
766 
767  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
768  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
769  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
770  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
771  int bApproxOK,
772  double *pdfMin, double *pdfMax,
773  double *pdfMean, double *pdfStdDev,
774  GDALProgressFunc pfnProgress, void *pProgressData );
775  virtual CPLErr GetHistogram( int nXSize, int nYSize,
776  double dfMin, double dfMax,
777  int nBuckets, GUIntBig * panHistogram,
778  int bIncludeOutOfRange, int bApproxOK,
779  GDALProgressFunc pfnProgress, void *pProgressData );
780 
781  void DstToSrc( double dfX, double dfY,
782  double &dfXOut, double &dfYOut );
783  void SrcToDst( double dfX, double dfY,
784  double &dfXOut, double &dfYOut );
785 
786  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
787  int *pnMaxSize, CPLHashSet* hSetFiles);
788 
789  virtual int IsSimpleSource() { return TRUE; }
790  virtual const char* GetType() { return "SimpleSource"; }
791 
792  GDALRasterBand* GetBand();
793  int IsSameExceptBandNumber(VRTSimpleSource* poOtherSource);
794  CPLErr DatasetRasterIO(
795  int nXOff, int nYOff, int nXSize, int nYSize,
796  void * pData, int nBufXSize, int nBufYSize,
797  GDALDataType eBufType,
798  int nBandCount, int *panBandMap,
799  GSpacing nPixelSpace, GSpacing nLineSpace,
800  GSpacing nBandSpace,
801  GDALRasterIOExtraArg* psExtraArg);
802 
803  void UnsetPreservedRelativeFilenames();
804 
805  void SetMaxValue(int nVal) { m_nMaxValue = nVal; }
806 };
807 
808 /************************************************************************/
809 /* VRTAveragedSource */
810 /************************************************************************/
811 
813 {
814 public:
816  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
817  void *pData, int nBufXSize, int nBufYSize,
818  GDALDataType eBufType,
819  GSpacing nPixelSpace, GSpacing nLineSpace,
820  GDALRasterIOExtraArg* psExtraArg );
821 
822  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
823  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
824  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
825  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
826  int bApproxOK,
827  double *pdfMin, double *pdfMax,
828  double *pdfMean, double *pdfStdDev,
829  GDALProgressFunc pfnProgress, void *pProgressData );
830  virtual CPLErr GetHistogram( int nXSize, int nYSize,
831  double dfMin, double dfMax,
832  int nBuckets, GUIntBig * panHistogram,
833  int bIncludeOutOfRange, int bApproxOK,
834  GDALProgressFunc pfnProgress, void *pProgressData );
835 
836  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
837  virtual const char* GetType() { return "AveragedSource"; }
838 };
839 
840 /************************************************************************/
841 /* VRTComplexSource */
842 /************************************************************************/
843 
844 typedef enum
845 {
846  VRT_SCALING_NONE,
847  VRT_SCALING_LINEAR,
848  VRT_SCALING_EXPONENTIAL,
849 } VRTComplexSourceScaling;
850 
851 class CPL_DLL VRTComplexSource : public VRTSimpleSource
852 {
853 protected:
854  VRTComplexSourceScaling m_eScalingType;
855  double m_dfScaleOff; /* for linear scaling */
856  double m_dfScaleRatio; /* for linear scaling */
857 
858  /* For non-linear scaling with a power function. */
859  int m_bSrcMinMaxDefined;
860  double m_dfSrcMin;
861  double m_dfSrcMax;
862  double m_dfDstMin;
863  double m_dfDstMax;
864  double m_dfExponent;
865 
866  int m_nColorTableComponent;
867 
868  template <class WorkingDT>
869  CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
870  int nReqXSize, int nReqYSize,
871  void *pData, int nOutXSize, int nOutYSize,
872  GDALDataType eBufType,
873  GSpacing nPixelSpace, GSpacing nLineSpace,
874  GDALRasterIOExtraArg* psExtraArg,
875  GDALDataType eWrkDataType );
876 
877 public:
879  VRTComplexSource(const VRTComplexSource* poSrcSource,
880  double dfXDstRatio, double dfYDstRatio);
881  virtual ~VRTComplexSource();
882 
883  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
884  void *pData, int nBufXSize, int nBufYSize,
885  GDALDataType eBufType,
886  GSpacing nPixelSpace, GSpacing nLineSpace,
887  GDALRasterIOExtraArg* psExtraArg );
888 
889  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
890  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
891  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
892  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
893  int bApproxOK,
894  double *pdfMin, double *pdfMax,
895  double *pdfMean, double *pdfStdDev,
896  GDALProgressFunc pfnProgress, void *pProgressData );
897  virtual CPLErr GetHistogram( int nXSize, int nYSize,
898  double dfMin, double dfMax,
899  int nBuckets, GUIntBig * panHistogram,
900  int bIncludeOutOfRange, int bApproxOK,
901  GDALProgressFunc pfnProgress, void *pProgressData );
902 
903  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
904  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
905  virtual const char* GetType() { return "ComplexSource"; }
906 
907  double LookupValue( double dfInput );
908 
909  void SetLinearScaling(double dfOffset, double dfScale);
910  void SetPowerScaling(double dfExponent,
911  double dfSrcMin,
912  double dfSrcMax,
913  double dfDstMin,
914  double dfDstMax);
915  void SetColorTableComponent(int nComponent);
916 
917  double *m_padfLUTInputs;
918  double *m_padfLUTOutputs;
919  int m_nLUTItemCount;
920 
921 };
922 
923 /************************************************************************/
924 /* VRTFilteredSource */
925 /************************************************************************/
926 
928 {
929 private:
930  int IsTypeSupported( GDALDataType eType );
931 
932 protected:
933  int m_nSupportedTypesCount;
934  GDALDataType m_aeSupportedTypes[20];
935 
936  int m_nExtraEdgePixels;
937 
938 public:
940  virtual ~VRTFilteredSource();
941 
942  void SetExtraEdgePixels( int );
943  void SetFilteringDataTypesSupported( int, GDALDataType * );
944 
945  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
946  GByte *pabySrcData, GByte *pabyDstData ) = 0;
947 
948  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
949  void *pData, int nBufXSize, int nBufYSize,
950  GDALDataType eBufType,
951  GSpacing nPixelSpace, GSpacing nLineSpace,
952  GDALRasterIOExtraArg* psExtraArg );
953 };
954 
955 /************************************************************************/
956 /* VRTKernelFilteredSource */
957 /************************************************************************/
958 
960 {
961 protected:
962  int m_nKernelSize;
963 
964  double *m_padfKernelCoefs;
965 
966  int m_bNormalized;
967 
968 public:
970  virtual ~VRTKernelFilteredSource();
971 
972  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
973  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
974 
975  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
976  GByte *pabySrcData, GByte *pabyDstData );
977 
978  CPLErr SetKernel( int nKernelSize, double *padfCoefs );
979  void SetNormalized( int );
980 };
981 
982 /************************************************************************/
983 /* VRTAverageFilteredSource */
984 /************************************************************************/
985 
987 {
988 public:
989  explicit VRTAverageFilteredSource( int nKernelSize );
990  virtual ~VRTAverageFilteredSource();
991 
992  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
993  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
994 };
995 
996 /************************************************************************/
997 /* VRTFuncSource */
998 /************************************************************************/
999 class VRTFuncSource : public VRTSource
1000 {
1001 public:
1002  VRTFuncSource();
1003  virtual ~VRTFuncSource();
1004 
1005  virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
1006  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
1007 
1008  virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
1009  void *pData, int nBufXSize, int nBufYSize,
1010  GDALDataType eBufType,
1011  GSpacing nPixelSpace, GSpacing nLineSpace,
1012  GDALRasterIOExtraArg* psExtraArg );
1013 
1014  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
1015  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
1016  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
1017  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1018  int bApproxOK,
1019  double *pdfMin, double *pdfMax,
1020  double *pdfMean, double *pdfStdDev,
1021  GDALProgressFunc pfnProgress, void *pProgressData );
1022  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1023  double dfMin, double dfMax,
1024  int nBuckets, GUIntBig * panHistogram,
1025  int bIncludeOutOfRange, int bApproxOK,
1026  GDALProgressFunc pfnProgress, void *pProgressData );
1027 
1028  VRTImageReadFunc pfnReadFunc;
1029  void *pCBData;
1030  GDALDataType eType;
1031 
1032  float fNoDataValue;
1033 };
1034 
1035 #endif /* ndef VIRTUALDATASET_H_INCLUDED */
GDALDataType
Definition: gdal.h:57
Document node structure.
Definition: cpl_minixml.h:65
Definition: vrtdataset.h:959
Definition: vrtdataset.h:812
C++ GDAL entry points.
Definition: vrtdataset.h:346
virtual CPLErr SetMetadata(char **papszMD, const char *pszDomain="")
Set metadata.
Definition: vrtrasterband.cpp:148
Definition: vrtdataset.h:575
Definition: vrtdataset.h:80
Definition: vrtdataset.h:927
GDALRWFlag
Definition: gdal.h:104
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:230
Definition: vrtdataset.h:452
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:233
Definition: vrtdataset.h:125
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition: gdalmajorobject.cpp:243
void GetBlockSize(int *, int *)
Fetch the "natural" block size of this band.
Definition: gdalrasterband.cpp:689
int GetShared()
Returns shared flag.
Definition: gdaldataset.cpp:1157
Pansharpening operation class.
Definition: gdalpansharpen.h:184
Definition: vrtdataset.h:56
Convenient string class based on std::string.
Definition: cpl_string.h:283
Hash set implementation.
Definition: gdal.h:58
Definition: vrtdataset.h:986
virtual CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain="")
Set single metadata item.
Definition: vrtrasterband.cpp:161
Definition: vrtdataset.h:280
virtual CPLErr FlushCache()
Flush raster data cache.
Definition: gdalrasterband.cpp:849
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:248
Definition: vrtdataset.h:644
int Dereference()
Subtract one from dataset reference count.
Definition: gdaldataset.cpp:1123
Definition: vrtdataset.h:555
Definition: vrtdataset.h:609
Definition: gdal_priv.h:238
Structure to pass extra arguments to RasterIO() method.
Definition: gdal.h:132
High level image warping class.
Definition: gdalwarper.h:355
Definition: vrtdataset.h:999
Definition: vrtdataset.h:851
void GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:2981
Definition: vrtdataset.h:708
Object with metadata.
Definition: gdal_priv.h:122
virtual CPLErr CreateMaskBand(int nFlags)
Adds a mask band to the current band.
Definition: vrtrasterband.cpp:1086
GDALDataset * GetDataset()
Fetch the owning dataset handle.
Definition: gdalrasterband.cpp:2618
A single raster band (or channel).
Definition: gdal_priv.h:736
GDALAccess
Definition: gdal.h:98
Definition: vrtdataset.h:684
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:296
Definition: vrtdataset.h:224
GDALColorInterp
Definition: gdal.h:173
Public (C callable) entry points for virtual GDAL dataset objects.
Definition: gdal.h:99
Format specific driver.
Definition: gdal_priv.h:1036
Definition: gdal_priv.h:660
Ground Control Point.
Definition: gdal.h:492

Generated for GDAL by doxygen 1.8.11.