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