00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef VIRTUALDATASET_H_INCLUDED
00031 #define VIRTUALDATASET_H_INCLUDED
00032
00033 #include "gdal_priv.h"
00034 #include "gdal_pam.h"
00035 #include "gdal_vrt.h"
00036 #include "cpl_hash_set.h"
00037
00038 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00039 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00040
00041
00042
00043
00044 class VRTOverviewInfo
00045 {
00046 public:
00047 CPLString osFilename;
00048 int nBand;
00049 GDALRasterBand *poBand;
00050 int bTriedToOpen;
00051
00052 VRTOverviewInfo() : poBand(NULL), bTriedToOpen(FALSE) {}
00053 ~VRTOverviewInfo() {
00054 if( poBand == NULL )
00055 ;
00056 else if( poBand->GetDataset()->GetShared() )
00057 GDALClose( (GDALDatasetH) poBand->GetDataset() );
00058 else
00059 poBand->GetDataset()->Dereference();
00060 }
00061 };
00062
00063
00064
00065
00066
00067
00068 class VRTSource
00069 {
00070 public:
00071 virtual ~VRTSource();
00072
00073 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00074 void *pData, int nBufXSize, int nBufYSize,
00075 GDALDataType eBufType,
00076 int nPixelSpace, int nLineSpace ) = 0;
00077
00078 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00079 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00080
00081 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00082 int *pnMaxSize, CPLHashSet* hSetFiles);
00083 };
00084
00085 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00086
00087 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00088 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00089
00090
00091
00092
00093
00094 class CPL_DLL VRTDataset : public GDALDataset
00095 {
00096 char *pszProjection;
00097
00098 int bGeoTransformSet;
00099 double adfGeoTransform[6];
00100
00101 int nGCPCount;
00102 GDAL_GCP *pasGCPList;
00103 char *pszGCPProjection;
00104
00105 int bNeedsFlush;
00106 int bWritable;
00107
00108 char *pszVRTPath;
00109
00110 public:
00111 VRTDataset(int nXSize, int nYSize);
00112 ~VRTDataset();
00113
00114 void SetNeedsFlush() { bNeedsFlush = TRUE; }
00115 virtual void FlushCache();
00116
00117 void SetWritable(int bWritable) { this->bWritable = bWritable; }
00118
00119 virtual const char *GetProjectionRef(void);
00120 virtual CPLErr SetProjection( const char * );
00121 virtual CPLErr GetGeoTransform( double * );
00122 virtual CPLErr SetGeoTransform( double * );
00123
00124 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00125 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00126 const char *pszDomain = "" );
00127
00128 virtual int GetGCPCount();
00129 virtual const char *GetGCPProjection();
00130 virtual const GDAL_GCP *GetGCPs();
00131 virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00132 const char *pszGCPProjection );
00133
00134 virtual CPLErr AddBand( GDALDataType eType,
00135 char **papszOptions=NULL );
00136
00137 virtual char **GetFileList();
00138
00139 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00140 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00141
00142 static int Identify( GDALOpenInfo * );
00143 static GDALDataset *Open( GDALOpenInfo * );
00144 static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
00145 static GDALDataset *Create( const char * pszName,
00146 int nXSize, int nYSize, int nBands,
00147 GDALDataType eType, char ** papszOptions );
00148 static CPLErr Delete( const char * pszFilename );
00149 };
00150
00151
00152
00153
00154
00155 class GDALWarpOperation;
00156 class VRTWarpedRasterBand;
00157
00158 class CPL_DLL VRTWarpedDataset : public VRTDataset
00159 {
00160 int nBlockXSize;
00161 int nBlockYSize;
00162 GDALWarpOperation *poWarper;
00163
00164 friend class VRTWarpedRasterBand;
00165
00166 public:
00167 int nOverviewCount;
00168 VRTWarpedDataset **papoOverviews;
00169
00170 public:
00171 VRTWarpedDataset( int nXSize, int nYSize );
00172 ~VRTWarpedDataset();
00173
00174 CPLErr Initialize( void * );
00175
00176 virtual CPLErr IBuildOverviews( const char *, int, int *,
00177 int, int *, GDALProgressFunc, void * );
00178
00179 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00180 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00181
00182 virtual CPLErr AddBand( GDALDataType eType,
00183 char **papszOptions=NULL );
00184
00185 virtual char **GetFileList();
00186
00187 CPLErr ProcessBlock( int iBlockX, int iBlockY );
00188
00189 void GetBlockSize( int *, int * );
00190 };
00191
00192
00193
00194
00195
00196
00197
00198
00199 class CPL_DLL VRTRasterBand : public GDALRasterBand
00200 {
00201 protected:
00202 int bNoDataValueSet;
00203 int bHideNoDataValue;
00204 double dfNoDataValue;
00205
00206 GDALColorTable *poColorTable;
00207
00208 GDALColorInterp eColorInterp;
00209
00210 char *pszUnitType;
00211 char **papszCategoryNames;
00212
00213 double dfOffset;
00214 double dfScale;
00215
00216 CPLXMLNode *psSavedHistograms;
00217
00218 void Initialize( int nXSize, int nYSize );
00219
00220 std::vector<VRTOverviewInfo> apoOverviews;
00221
00222 public:
00223
00224 VRTRasterBand();
00225 virtual ~VRTRasterBand();
00226
00227 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00228 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00229
00230 virtual CPLErr SetNoDataValue( double );
00231 virtual double GetNoDataValue( int *pbSuccess = NULL );
00232
00233 virtual CPLErr SetColorTable( GDALColorTable * );
00234 virtual GDALColorTable *GetColorTable();
00235
00236 virtual CPLErr SetColorInterpretation( GDALColorInterp );
00237 virtual GDALColorInterp GetColorInterpretation();
00238
00239 virtual const char *GetUnitType();
00240 CPLErr SetUnitType( const char * );
00241
00242 virtual char **GetCategoryNames();
00243 virtual CPLErr SetCategoryNames( char ** );
00244
00245 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00246 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00247 const char *pszDomain = "" );
00248
00249 virtual double GetOffset( int *pbSuccess = NULL );
00250 CPLErr SetOffset( double );
00251 virtual double GetScale( int *pbSuccess = NULL );
00252 CPLErr SetScale( double );
00253
00254 virtual int GetOverviewCount();
00255 virtual GDALRasterBand *GetOverview(int);
00256
00257 virtual CPLErr GetHistogram( double dfMin, double dfMax,
00258 int nBuckets, int * panHistogram,
00259 int bIncludeOutOfRange, int bApproxOK,
00260 GDALProgressFunc, void *pProgressData );
00261
00262 virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00263 int *pnBuckets, int ** ppanHistogram,
00264 int bForce,
00265 GDALProgressFunc, void *pProgressData);
00266
00267 virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00268 int nBuckets, int *panHistogram );
00269
00270 CPLErr CopyCommonInfoFrom( GDALRasterBand * );
00271
00272 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00273 int *pnMaxSize, CPLHashSet* hSetFiles);
00274 };
00275
00276
00277
00278
00279
00280 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00281 {
00282 int bAlreadyInIRasterIO;
00283
00284 void Initialize( int nXSize, int nYSize );
00285
00286 public:
00287 int nSources;
00288 VRTSource **papoSources;
00289 int bEqualAreas;
00290
00291 VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00292 VRTSourcedRasterBand( GDALDataType eType,
00293 int nXSize, int nYSize );
00294 VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
00295 GDALDataType eType,
00296 int nXSize, int nYSize );
00297 virtual ~VRTSourcedRasterBand();
00298
00299 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00300 void *, int, int, GDALDataType,
00301 int, int );
00302
00303 virtual char **GetMetadata( const char * pszDomain = "" );
00304 virtual CPLErr SetMetadata( char ** papszMetadata,
00305 const char * pszDomain = "" );
00306 virtual CPLErr SetMetadataItem( const char * pszName,
00307 const char * pszValue,
00308 const char * pszDomain = "" );
00309
00310 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00311 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00312
00313 CPLErr AddSource( VRTSource * );
00314 CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
00315 int nSrcXOff=-1, int nSrcYOff=-1,
00316 int nSrcXSize=-1, int nSrcYSize=-1,
00317 int nDstXOff=-1, int nDstYOff=-1,
00318 int nDstXSize=-1, int nDstYSize=-1,
00319 const char *pszResampling = "near",
00320 double dfNoDataValue = VRT_NODATA_UNSET);
00321 CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
00322 int nSrcXOff=-1, int nSrcYOff=-1,
00323 int nSrcXSize=-1, int nSrcYSize=-1,
00324 int nDstXOff=-1, int nDstYOff=-1,
00325 int nDstXSize=-1, int nDstYSize=-1,
00326 double dfScaleOff=0.0,
00327 double dfScaleRatio=1.0,
00328 double dfNoDataValue = VRT_NODATA_UNSET,
00329 int nColorTableComponent = 0);
00330
00331 CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00332 double dfNoDataValue = VRT_NODATA_UNSET );
00333
00334
00335 virtual CPLErr IReadBlock( int, int, void * );
00336
00337 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00338 int *pnMaxSize, CPLHashSet* hSetFiles);
00339 };
00340
00341
00342
00343
00344
00345 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00346 {
00347 public:
00348 VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00349 GDALDataType eType = GDT_Unknown );
00350 virtual ~VRTWarpedRasterBand();
00351
00352 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00353 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00354
00355 virtual CPLErr IReadBlock( int, int, void * );
00356 virtual CPLErr IWriteBlock( int, int, void * );
00357
00358 virtual int GetOverviewCount();
00359 virtual GDALRasterBand *GetOverview(int);
00360 };
00361
00362
00363
00364
00365
00366 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
00367 {
00368
00369 public:
00370 char *pszFuncName;
00371 GDALDataType eSourceTransferType;
00372
00373 VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
00374 VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
00375 GDALDataType eType, int nXSize, int nYSize);
00376 virtual ~VRTDerivedRasterBand();
00377
00378 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00379 void *, int, int, GDALDataType,
00380 int, int );
00381
00382 static CPLErr AddPixelFunction
00383 (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
00384 static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
00385
00386 void SetPixelFunctionName(const char *pszFuncName);
00387 void SetSourceTransferType(GDALDataType eDataType);
00388
00389 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00390 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00391
00392 };
00393
00394
00395
00396
00397
00398 class RawRasterBand;
00399
00400 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00401 {
00402 RawRasterBand *poRawRaster;
00403
00404 char *pszSourceFilename;
00405 int bRelativeToVRT;
00406
00407 public:
00408 VRTRawRasterBand( GDALDataset *poDS, int nBand,
00409 GDALDataType eType = GDT_Unknown );
00410 virtual ~VRTRawRasterBand();
00411
00412 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00413 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00414
00415 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00416 void *, int, int, GDALDataType,
00417 int, int );
00418
00419 virtual CPLErr IReadBlock( int, int, void * );
00420 virtual CPLErr IWriteBlock( int, int, void * );
00421
00422 CPLErr SetRawLink( const char *pszFilename,
00423 const char *pszVRTPath,
00424 int bRelativeToVRT,
00425 vsi_l_offset nImageOffset,
00426 int nPixelOffset, int nLineOffset,
00427 const char *pszByteOrder );
00428
00429 void ClearRawLink();
00430
00431 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00432 int *pnMaxSize, CPLHashSet* hSetFiles);
00433 };
00434
00435
00436
00437
00438
00439 class VRTDriver : public GDALDriver
00440 {
00441 public:
00442 VRTDriver();
00443 ~VRTDriver();
00444
00445 char **papszSourceParsers;
00446
00447 virtual char **GetMetadata( const char * pszDomain = "" );
00448 virtual CPLErr SetMetadata( char ** papszMetadata,
00449 const char * pszDomain = "" );
00450
00451 VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00452 void AddSourceParser( const char *pszElementName,
00453 VRTSourceParser pfnParser );
00454 };
00455
00456
00457
00458
00459
00460 class VRTSimpleSource : public VRTSource
00461 {
00462 protected:
00463 GDALRasterBand *poRasterBand;
00464
00465 int nSrcXOff;
00466 int nSrcYOff;
00467 int nSrcXSize;
00468 int nSrcYSize;
00469
00470 int nDstXOff;
00471 int nDstYOff;
00472 int nDstXSize;
00473 int nDstYSize;
00474
00475 int bNoDataSet;
00476 double dfNoDataValue;
00477
00478 public:
00479 VRTSimpleSource();
00480 virtual ~VRTSimpleSource();
00481
00482 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00483 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00484
00485 void SetSrcBand( GDALRasterBand * );
00486 void SetSrcWindow( int, int, int, int );
00487 void SetDstWindow( int, int, int, int );
00488 void SetNoDataValue( double dfNoDataValue );
00489
00490 int GetSrcDstWindow( int, int, int, int, int, int,
00491 int *, int *, int *, int *,
00492 int *, int *, int *, int * );
00493
00494 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00495 void *pData, int nBufXSize, int nBufYSize,
00496 GDALDataType eBufType,
00497 int nPixelSpace, int nLineSpace );
00498
00499 void DstToSrc( double dfX, double dfY,
00500 double &dfXOut, double &dfYOut );
00501 void SrcToDst( double dfX, double dfY,
00502 double &dfXOut, double &dfYOut );
00503
00504 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00505 int *pnMaxSize, CPLHashSet* hSetFiles);
00506 };
00507
00508
00509
00510
00511
00512 class VRTAveragedSource : public VRTSimpleSource
00513 {
00514 public:
00515 VRTAveragedSource();
00516 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00517 void *pData, int nBufXSize, int nBufYSize,
00518 GDALDataType eBufType,
00519 int nPixelSpace, int nLineSpace );
00520 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00521 };
00522
00523
00524
00525
00526
00527 class VRTComplexSource : public VRTSimpleSource
00528 {
00529 public:
00530 VRTComplexSource();
00531 virtual ~VRTComplexSource();
00532
00533 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00534 void *pData, int nBufXSize, int nBufYSize,
00535 GDALDataType eBufType,
00536 int nPixelSpace, int nLineSpace );
00537 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00538 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00539 double LookupValue( double dfInput );
00540
00541 int bDoScaling;
00542 double dfScaleOff;
00543 double dfScaleRatio;
00544 double *padfLUTInputs;
00545 double *padfLUTOutputs;
00546 int nLUTItemCount;
00547 int nColorTableComponent;
00548 };
00549
00550
00551
00552
00553
00554 class VRTFilteredSource : public VRTComplexSource
00555 {
00556 private:
00557 int IsTypeSupported( GDALDataType eType );
00558
00559 protected:
00560 int nSupportedTypesCount;
00561 GDALDataType aeSupportedTypes[20];
00562
00563 int nExtraEdgePixels;
00564
00565 public:
00566 VRTFilteredSource();
00567 virtual ~VRTFilteredSource();
00568
00569 void SetExtraEdgePixels( int );
00570 void SetFilteringDataTypesSupported( int, GDALDataType * );
00571
00572 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00573 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00574
00575 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00576 void *pData, int nBufXSize, int nBufYSize,
00577 GDALDataType eBufType,
00578 int nPixelSpace, int nLineSpace );
00579 };
00580
00581
00582
00583
00584
00585 class VRTKernelFilteredSource : public VRTFilteredSource
00586 {
00587 protected:
00588 int nKernelSize;
00589
00590 double *padfKernelCoefs;
00591
00592 int bNormalized;
00593
00594 public:
00595 VRTKernelFilteredSource();
00596 virtual ~VRTKernelFilteredSource();
00597
00598 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00599 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00600
00601 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00602 GByte *pabySrcData, GByte *pabyDstData );
00603
00604 CPLErr SetKernel( int nKernelSize, double *padfCoefs );
00605 void SetNormalized( int );
00606 };
00607
00608
00609
00610
00611
00612 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00613 {
00614 public:
00615 VRTAverageFilteredSource( int nKernelSize );
00616 virtual ~VRTAverageFilteredSource();
00617
00618 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00619 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00620 };
00621
00622
00623
00624
00625 class VRTFuncSource : public VRTSource
00626 {
00627 public:
00628 VRTFuncSource();
00629 virtual ~VRTFuncSource();
00630
00631 virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
00632 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00633
00634 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00635 void *pData, int nBufXSize, int nBufYSize,
00636 GDALDataType eBufType,
00637 int nPixelSpace, int nLineSpace );
00638
00639 VRTImageReadFunc pfnReadFunc;
00640 void *pCBData;
00641 GDALDataType eType;
00642
00643 float fNoDataValue;
00644 };
00645
00646 #endif