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 int bHideNoDataValue;
00181 double dfNoDataValue;
00182
00183 GDALColorTable *poColorTable;
00184
00185 GDALColorInterp eColorInterp;
00186
00187 char *pszUnitType;
00188 char **papszCategoryNames;
00189
00190 double dfOffset;
00191 double dfScale;
00192
00193 CPLXMLNode *psSavedHistograms;
00194
00195 void Initialize( int nXSize, int nYSize );
00196
00197 public:
00198
00199 VRTRasterBand();
00200 virtual ~VRTRasterBand();
00201
00202 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00203 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00204
00205 virtual CPLErr SetNoDataValue( double );
00206 virtual double GetNoDataValue( int *pbSuccess = NULL );
00207
00208 virtual CPLErr SetColorTable( GDALColorTable * );
00209 virtual GDALColorTable *GetColorTable();
00210
00211 virtual CPLErr SetColorInterpretation( GDALColorInterp );
00212 virtual GDALColorInterp GetColorInterpretation();
00213
00214 virtual const char *GetUnitType();
00215 CPLErr SetUnitType( const char * );
00216
00217 virtual char **GetCategoryNames();
00218 virtual CPLErr SetCategoryNames( char ** );
00219
00220 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00221 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00222 const char *pszDomain = "" );
00223
00224 virtual double GetOffset( int *pbSuccess = NULL );
00225 CPLErr SetOffset( double );
00226 virtual double GetScale( int *pbSuccess = NULL );
00227 CPLErr SetScale( double );
00228
00229 virtual CPLErr GetHistogram( double dfMin, double dfMax,
00230 int nBuckets, int * panHistogram,
00231 int bIncludeOutOfRange, int bApproxOK,
00232 GDALProgressFunc, void *pProgressData );
00233
00234 virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00235 int *pnBuckets, int ** ppanHistogram,
00236 int bForce,
00237 GDALProgressFunc, void *pProgressData);
00238
00239 virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00240 int nBuckets, int *panHistogram );
00241
00242 CPLErr CopyCommonInfoFrom( GDALRasterBand * );
00243
00244 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00245 int *pnMaxSize, CPLHashSet* hSetFiles);
00246
00247 virtual void SetDescription( const char * );
00248 };
00249
00250
00251
00252
00253
00254 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00255 {
00256 int bAlreadyInIRasterIO;
00257
00258 void Initialize( int nXSize, int nYSize );
00259
00260 public:
00261 int nSources;
00262 VRTSource **papoSources;
00263 int bEqualAreas;
00264
00265 VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00266 VRTSourcedRasterBand( GDALDataType eType,
00267 int nXSize, int nYSize );
00268 VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
00269 GDALDataType eType,
00270 int nXSize, int nYSize );
00271 virtual ~VRTSourcedRasterBand();
00272
00273 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00274 void *, int, int, GDALDataType,
00275 int, int );
00276
00277 virtual char **GetMetadata( const char * pszDomain = "" );
00278 virtual CPLErr SetMetadata( char ** papszMetadata,
00279 const char * pszDomain = "" );
00280 virtual CPLErr SetMetadataItem( const char * pszName,
00281 const char * pszValue,
00282 const char * pszDomain = "" );
00283
00284 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00285 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00286
00287 CPLErr AddSource( VRTSource * );
00288 CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
00289 int nSrcXOff=-1, int nSrcYOff=-1,
00290 int nSrcXSize=-1, int nSrcYSize=-1,
00291 int nDstXOff=-1, int nDstYOff=-1,
00292 int nDstXSize=-1, int nDstYSize=-1,
00293 const char *pszResampling = "near",
00294 double dfNoDataValue = VRT_NODATA_UNSET);
00295 CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
00296 int nSrcXOff=-1, int nSrcYOff=-1,
00297 int nSrcXSize=-1, int nSrcYSize=-1,
00298 int nDstXOff=-1, int nDstYOff=-1,
00299 int nDstXSize=-1, int nDstYSize=-1,
00300 double dfScaleOff=0.0,
00301 double dfScaleRatio=1.0,
00302 double dfNoDataValue = VRT_NODATA_UNSET,
00303 int nColorTableComponent = 0);
00304
00305 CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00306 double dfNoDataValue = VRT_NODATA_UNSET );
00307
00308
00309 virtual CPLErr IReadBlock( int, int, void * );
00310
00311 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00312 int *pnMaxSize, CPLHashSet* hSetFiles);
00313 };
00314
00315
00316
00317
00318
00319 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00320 {
00321 public:
00322 VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00323 GDALDataType eType = GDT_Unknown );
00324 virtual ~VRTWarpedRasterBand();
00325
00326 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00327 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00328
00329 virtual CPLErr IReadBlock( int, int, void * );
00330 virtual CPLErr IWriteBlock( int, int, void * );
00331
00332 virtual int GetOverviewCount();
00333 virtual GDALRasterBand *GetOverview(int);
00334 };
00335
00336
00337
00338
00339
00340 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
00341 {
00342
00343 public:
00344 char *pszFuncName;
00345 GDALDataType eSourceTransferType;
00346
00347 VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
00348 VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
00349 GDALDataType eType, int nXSize, int nYSize);
00350 virtual ~VRTDerivedRasterBand();
00351
00352 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00353 void *, int, int, GDALDataType,
00354 int, int );
00355
00356 static CPLErr AddPixelFunction
00357 (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
00358 static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
00359
00360 void SetPixelFunctionName(const char *pszFuncName);
00361 void SetSourceTransferType(GDALDataType eDataType);
00362
00363 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00364 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00365
00366 };
00367
00368
00369
00370
00371
00372 class RawRasterBand;
00373
00374 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00375 {
00376 RawRasterBand *poRawRaster;
00377
00378 char *pszSourceFilename;
00379 int bRelativeToVRT;
00380
00381 public:
00382 VRTRawRasterBand( GDALDataset *poDS, int nBand,
00383 GDALDataType eType = GDT_Unknown );
00384 virtual ~VRTRawRasterBand();
00385
00386 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00387 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00388
00389 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00390 void *, int, int, GDALDataType,
00391 int, int );
00392
00393 virtual CPLErr IReadBlock( int, int, void * );
00394 virtual CPLErr IWriteBlock( int, int, void * );
00395
00396 CPLErr SetRawLink( const char *pszFilename,
00397 const char *pszVRTPath,
00398 int bRelativeToVRT,
00399 vsi_l_offset nImageOffset,
00400 int nPixelOffset, int nLineOffset,
00401 const char *pszByteOrder );
00402
00403 void ClearRawLink();
00404
00405 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00406 int *pnMaxSize, CPLHashSet* hSetFiles);
00407 };
00408
00409
00410
00411
00412
00413 class VRTDriver : public GDALDriver
00414 {
00415 public:
00416 VRTDriver();
00417 ~VRTDriver();
00418
00419 char **papszSourceParsers;
00420
00421 virtual char **GetMetadata( const char * pszDomain = "" );
00422 virtual CPLErr SetMetadata( char ** papszMetadata,
00423 const char * pszDomain = "" );
00424
00425 VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00426 void AddSourceParser( const char *pszElementName,
00427 VRTSourceParser pfnParser );
00428 };
00429
00430
00431
00432
00433
00434 class VRTSimpleSource : public VRTSource
00435 {
00436 protected:
00437 GDALRasterBand *poRasterBand;
00438
00439 int nSrcXOff;
00440 int nSrcYOff;
00441 int nSrcXSize;
00442 int nSrcYSize;
00443
00444 int nDstXOff;
00445 int nDstYOff;
00446 int nDstXSize;
00447 int nDstYSize;
00448
00449 int bNoDataSet;
00450 double dfNoDataValue;
00451
00452 public:
00453 VRTSimpleSource();
00454 virtual ~VRTSimpleSource();
00455
00456 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00457 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00458
00459 void SetSrcBand( GDALRasterBand * );
00460 void SetSrcWindow( int, int, int, int );
00461 void SetDstWindow( int, int, int, int );
00462 void SetNoDataValue( double dfNoDataValue );
00463
00464 int GetSrcDstWindow( int, int, int, int, int, int,
00465 int *, int *, int *, int *,
00466 int *, int *, int *, int * );
00467
00468 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00469 void *pData, int nBufXSize, int nBufYSize,
00470 GDALDataType eBufType,
00471 int nPixelSpace, int nLineSpace );
00472
00473 void DstToSrc( double dfX, double dfY,
00474 double &dfXOut, double &dfYOut );
00475 void SrcToDst( double dfX, double dfY,
00476 double &dfXOut, double &dfYOut );
00477
00478 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00479 int *pnMaxSize, CPLHashSet* hSetFiles);
00480 };
00481
00482
00483
00484
00485
00486 class VRTAveragedSource : public VRTSimpleSource
00487 {
00488 public:
00489 VRTAveragedSource();
00490 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00491 void *pData, int nBufXSize, int nBufYSize,
00492 GDALDataType eBufType,
00493 int nPixelSpace, int nLineSpace );
00494 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00495 };
00496
00497
00498
00499
00500
00501 class VRTComplexSource : public VRTSimpleSource
00502 {
00503 public:
00504 VRTComplexSource();
00505 virtual ~VRTComplexSource();
00506
00507 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00508 void *pData, int nBufXSize, int nBufYSize,
00509 GDALDataType eBufType,
00510 int nPixelSpace, int nLineSpace );
00511 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00512 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00513 double LookupValue( double dfInput );
00514
00515 int bDoScaling;
00516 double dfScaleOff;
00517 double dfScaleRatio;
00518 double *padfLUTInputs;
00519 double *padfLUTOutputs;
00520 int nLUTItemCount;
00521 int nColorTableComponent;
00522 };
00523
00524
00525
00526
00527
00528 class VRTFilteredSource : public VRTComplexSource
00529 {
00530 private:
00531 int IsTypeSupported( GDALDataType eType );
00532
00533 protected:
00534 int nSupportedTypesCount;
00535 GDALDataType aeSupportedTypes[20];
00536
00537 int nExtraEdgePixels;
00538
00539 public:
00540 VRTFilteredSource();
00541 virtual ~VRTFilteredSource();
00542
00543 void SetExtraEdgePixels( int );
00544 void SetFilteringDataTypesSupported( int, GDALDataType * );
00545
00546 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00547 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00548
00549 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00550 void *pData, int nBufXSize, int nBufYSize,
00551 GDALDataType eBufType,
00552 int nPixelSpace, int nLineSpace );
00553 };
00554
00555
00556
00557
00558
00559 class VRTKernelFilteredSource : public VRTFilteredSource
00560 {
00561 protected:
00562 int nKernelSize;
00563
00564 double *padfKernelCoefs;
00565
00566 int bNormalized;
00567
00568 public:
00569 VRTKernelFilteredSource();
00570 virtual ~VRTKernelFilteredSource();
00571
00572 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00573 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00574
00575 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00576 GByte *pabySrcData, GByte *pabyDstData );
00577
00578 CPLErr SetKernel( int nKernelSize, double *padfCoefs );
00579 void SetNormalized( int );
00580 };
00581
00582
00583
00584
00585
00586 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00587 {
00588 public:
00589 VRTAverageFilteredSource( int nKernelSize );
00590 virtual ~VRTAverageFilteredSource();
00591
00592 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00593 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00594 };
00595
00596
00597
00598
00599 class VRTFuncSource : public VRTSource
00600 {
00601 public:
00602 VRTFuncSource();
00603 virtual ~VRTFuncSource();
00604
00605 virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
00606 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00607
00608 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00609 void *pData, int nBufXSize, int nBufYSize,
00610 GDALDataType eBufType,
00611 int nPixelSpace, int nLineSpace );
00612
00613 VRTImageReadFunc pfnReadFunc;
00614 void *pCBData;
00615 GDALDataType eType;
00616
00617 float fNoDataValue;
00618 };
00619
00620 #endif