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