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