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