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 #ifndef VIRTUALDATASET_H_INCLUDED
00092 #define VIRTUALDATASET_H_INCLUDED
00093
00094 #include "gdal_priv.h"
00095 #include "cpl_minixml.h"
00096
00097 CPL_C_START
00098 void GDALRegister_VRT(void);
00099 typedef CPLErr
00100 (*VRTImageReadFunc)( void *hCBData,
00101 int nXOff, int nYOff, int nXSize, int nYSize,
00102 void *pData );
00103 CPL_C_END
00104
00105 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00106 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00107
00108
00109
00110
00111
00112 class VRTSource
00113 {
00114 public:
00115 virtual ~VRTSource();
00116
00117 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00118 void *pData, int nBufXSize, int nBufYSize,
00119 GDALDataType eBufType,
00120 int nPixelSpace, int nLineSpace ) = 0;
00121
00122 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00123 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00124 };
00125
00126 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00127
00128 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00129 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00130
00131
00132
00133
00134
00135 class CPL_DLL VRTDataset : public GDALDataset
00136 {
00137 char *pszProjection;
00138
00139 int bGeoTransformSet;
00140 double adfGeoTransform[6];
00141
00142 int nGCPCount;
00143 GDAL_GCP *pasGCPList;
00144 char *pszGCPProjection;
00145
00146 int bNeedsFlush;
00147
00148 char *pszVRTPath;
00149
00150 public:
00151 VRTDataset(int nXSize, int nYSize);
00152 ~VRTDataset();
00153
00154 void SetNeedsFlush() { bNeedsFlush = TRUE; }
00155 virtual void FlushCache();
00156
00157 virtual const char *GetProjectionRef(void);
00158 virtual CPLErr SetProjection( const char * );
00159 virtual CPLErr GetGeoTransform( double * );
00160 virtual CPLErr SetGeoTransform( double * );
00161
00162 virtual int GetGCPCount();
00163 virtual const char *GetGCPProjection();
00164 virtual const GDAL_GCP *GetGCPs();
00165 virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00166 const char *pszGCPProjection );
00167
00168 virtual CPLErr AddBand( GDALDataType eType,
00169 char **papszOptions=NULL );
00170
00171 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00172 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00173
00174 static GDALDataset *Open( GDALOpenInfo * );
00175 static GDALDataset *OpenXML( const char *, const char * );
00176 static GDALDataset *Create( const char * pszName,
00177 int nXSize, int nYSize, int nBands,
00178 GDALDataType eType, char ** papszOptions );
00179 };
00180
00181
00182
00183
00184
00185 class GDALWarpOperation;
00186 class VRTWarpedRasterBand;
00187
00188 class CPL_DLL VRTWarpedDataset : public VRTDataset
00189 {
00190 int nBlockXSize;
00191 int nBlockYSize;
00192 GDALWarpOperation *poWarper;
00193
00194 public:
00195 int nOverviewCount;
00196 VRTWarpedDataset **papoOverviews;
00197
00198 public:
00199 VRTWarpedDataset( int nXSize, int nYSize );
00200 ~VRTWarpedDataset();
00201
00202 CPLErr Initialize( void * );
00203
00204 virtual CPLErr IBuildOverviews( const char *, int, int *,
00205 int, int *, GDALProgressFunc, void * );
00206
00207 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00208 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00209
00210 virtual CPLErr AddBand( GDALDataType eType,
00211 char **papszOptions=NULL );
00212
00213 CPLErr ProcessBlock( int iBlockX, int iBlockY );
00214
00215 void GetBlockSize( int *, int * );
00216 };
00217
00218
00219
00220
00221
00222
00223
00224
00225 class CPL_DLL VRTRasterBand : public GDALRasterBand
00226 {
00227 protected:
00228 int bNoDataValueSet;
00229 double dfNoDataValue;
00230
00231 GDALColorTable *poColorTable;
00232
00233 GDALColorInterp eColorInterp;
00234
00235 char *pszUnitType;
00236 char **papszCategoryNames;
00237
00238 double dfOffset;
00239 double dfScale;
00240
00241 void Initialize( int nXSize, int nYSize );
00242
00243 public:
00244
00245 VRTRasterBand();
00246 virtual ~VRTRasterBand();
00247
00248 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00249 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00250
00251 #define VRT_NODATA_UNSET -1234.56
00252
00253 virtual CPLErr SetNoDataValue( double );
00254 virtual double GetNoDataValue( int *pbSuccess = NULL );
00255
00256 virtual CPLErr SetColorTable( GDALColorTable * );
00257 virtual GDALColorTable *GetColorTable();
00258
00259 virtual CPLErr SetColorInterpretation( GDALColorInterp );
00260 virtual GDALColorInterp GetColorInterpretation();
00261
00262 virtual const char *GetUnitType();
00263 CPLErr SetUnitType( const char * );
00264
00265 virtual char **GetCategoryNames();
00266 virtual CPLErr SetCategoryNames( char ** );
00267
00268 virtual double GetOffset( int *pbSuccess = NULL );
00269 CPLErr SetOffset( double );
00270 virtual double GetScale( int *pbSuccess = NULL );
00271 CPLErr SetScale( double );
00272
00273 CPLErr CopyCommonInfoFrom( GDALRasterBand * );
00274 };
00275
00276
00277
00278
00279
00280 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00281 {
00282 int nSources;
00283 VRTSource **papoSources;
00284
00285 int bEqualAreas;
00286
00287 void Initialize( int nXSize, int nYSize );
00288
00289 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00290 void *, int, int, GDALDataType,
00291 int, int );
00292 public:
00293
00294 VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00295 VRTSourcedRasterBand( GDALDataType eType,
00296 int nXSize, int nYSize );
00297 VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
00298 GDALDataType eType,
00299 int nXSize, int nYSize );
00300 virtual ~VRTSourcedRasterBand();
00301
00302 virtual char **GetMetadata( const char * pszDomain = "" );
00303 virtual CPLErr SetMetadata( char ** papszMetadata,
00304 const char * pszDomain = "" );
00305
00306 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00307 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00308
00309 CPLErr AddSource( VRTSource * );
00310 CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
00311 int nSrcXOff=-1, int nSrcYOff=-1,
00312 int nSrcXSize=-1, int nSrcYSize=-1,
00313 int nDstXOff=-1, int nDstYOff=-1,
00314 int nDstXSize=-1, int nDstYSize=-1,
00315 const char *pszResampling = "near",
00316 double dfNoDataValue = VRT_NODATA_UNSET);
00317 CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
00318 int nSrcXOff=-1, int nSrcYOff=-1,
00319 int nSrcXSize=-1, int nSrcYSize=-1,
00320 int nDstXOff=-1, int nDstYOff=-1,
00321 int nDstXSize=-1, int nDstYSize=-1,
00322 double dfScaleOff=0.0,
00323 double dfScaleRatio=1.0,
00324 double dfNoDataValue = VRT_NODATA_UNSET);
00325
00326 CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00327 double dfNoDataValue = VRT_NODATA_UNSET );
00328
00329
00330 virtual CPLErr IReadBlock( int, int, void * );
00331 };
00332
00333
00334
00335
00336
00337 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00338 {
00339 public:
00340 VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00341 GDALDataType eType = GDT_Unknown );
00342 virtual ~VRTWarpedRasterBand();
00343
00344 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00345 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00346
00347 virtual CPLErr IReadBlock( int, int, void * );
00348
00349 virtual int GetOverviewCount();
00350 virtual GDALRasterBand *GetOverview(int);
00351 };
00352
00353
00354
00355
00356
00357 class RawRasterBand;
00358
00359 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00360 {
00361 RawRasterBand *poRawRaster;
00362
00363 char *pszSourceFilename;
00364 int bRelativeToVRT;
00365
00366 public:
00367 VRTRawRasterBand( GDALDataset *poDS, int nBand,
00368 GDALDataType eType = GDT_Unknown );
00369 virtual ~VRTRawRasterBand();
00370
00371 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00372 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00373
00374 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00375 void *, int, int, GDALDataType,
00376 int, int );
00377
00378 virtual CPLErr IReadBlock( int, int, void * );
00379 virtual CPLErr IWriteBlock( int, int, void * );
00380
00381 CPLErr SetRawLink( const char *pszFilename,
00382 const char *pszVRTPath,
00383 int bRelativeToVRT,
00384 vsi_l_offset nImageOffset,
00385 int nPixelOffset, int nLineOffset,
00386 const char *pszByteOrder );
00387
00388 void ClearRawLink();
00389
00390 };
00391
00392
00393
00394
00395
00396 class VRTDriver : public GDALDriver
00397 {
00398 public:
00399 VRTDriver();
00400 ~VRTDriver();
00401
00402 char **papszSourceParsers;
00403
00404 virtual char **GetMetadata( const char * pszDomain = "" );
00405 virtual CPLErr SetMetadata( char ** papszMetadata,
00406 const char * pszDomain = "" );
00407
00408 VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00409 void AddSourceParser( const char *pszElementName,
00410 VRTSourceParser pfnParser );
00411 };
00412
00413
00414
00415
00416
00417 class VRTSimpleSource : public VRTSource
00418 {
00419 protected:
00420 GDALRasterBand *poRasterBand;
00421
00422 int nSrcXOff;
00423 int nSrcYOff;
00424 int nSrcXSize;
00425 int nSrcYSize;
00426
00427 int nDstXOff;
00428 int nDstYOff;
00429 int nDstXSize;
00430 int nDstYSize;
00431
00432 int bNoDataSet;
00433 double dfNoDataValue;
00434
00435 public:
00436 VRTSimpleSource();
00437 virtual ~VRTSimpleSource();
00438
00439 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00440 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00441
00442 void SetSrcBand( GDALRasterBand * );
00443 void SetSrcWindow( int, int, int, int );
00444 void SetDstWindow( int, int, int, int );
00445 void SetNoDataValue( double dfNoDataValue );
00446
00447 int GetSrcDstWindow( int, int, int, int, int, int,
00448 int *, int *, int *, int *,
00449 int *, int *, int *, int * );
00450
00451 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00452 void *pData, int nBufXSize, int nBufYSize,
00453 GDALDataType eBufType,
00454 int nPixelSpace, int nLineSpace );
00455
00456 void DstToSrc( double dfX, double dfY,
00457 double &dfXOut, double &dfYOut );
00458 void SrcToDst( double dfX, double dfY,
00459 double &dfXOut, double &dfYOut );
00460
00461 };
00462
00463
00464
00465
00466
00467 class VRTAveragedSource : public VRTSimpleSource
00468 {
00469 public:
00470 VRTAveragedSource();
00471 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00472 void *pData, int nBufXSize, int nBufYSize,
00473 GDALDataType eBufType,
00474 int nPixelSpace, int nLineSpace );
00475 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00476 };
00477
00478
00479
00480
00481
00482 class VRTComplexSource : public VRTSimpleSource
00483 {
00484 public:
00485 VRTComplexSource();
00486 virtual ~VRTComplexSource();
00487
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 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00494
00495 int bDoScaling;
00496 double dfScaleOff;
00497 double dfScaleRatio;
00498
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