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