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