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