1 /****************************************************************************** 2 * $Id: vrtdataset.h 29294 2015-06-05 08:52:15Z rouault $ 3 * 4 * Project: Virtual GDAL Datasets 5 * Purpose: Declaration of virtual gdal dataset classes. 6 * Author: Frank Warmerdam, warmerdam@pobox.com 7 * 8 ****************************************************************************** 9 * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com> 10 * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org> 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a 13 * copy of this software and associated documentation files (the "Software"), 14 * to deal in the Software without restriction, including without limitation 15 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 * and/or sell copies of the Software, and to permit persons to whom the 17 * Software is furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included 20 * in all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 * DEALINGS IN THE SOFTWARE. 29 ****************************************************************************/ 30 31 #ifndef VIRTUALDATASET_H_INCLUDED 32 #define VIRTUALDATASET_H_INCLUDED 33 34 #include "gdal_priv.h" 35 #include "gdal_pam.h" 36 #include "gdal_vrt.h" 37 #include "cpl_hash_set.h" 38 39 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * ); 40 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * ); 41 42 #if 0 43 int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc, 44 int nPointCount, 45 double *padfX, double *padfY, double *padfZ, 46 int *panSuccess ); 47 void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree ); 48 #endif 49 50 /************************************************************************/ 51 /* VRTOverviewInfo() */ 52 /************************************************************************/ 53 class VRTOverviewInfo 54 { 55 public: 56 CPLString osFilename; 57 int nBand; 58 GDALRasterBand *poBand; 59 int bTriedToOpen; 60 VRTOverviewInfo()61 VRTOverviewInfo() : poBand(NULL), bTriedToOpen(FALSE) {} ~VRTOverviewInfo()62 ~VRTOverviewInfo() { 63 if( poBand == NULL ) 64 /* do nothing */; 65 else if( poBand->GetDataset()->GetShared() ) 66 GDALClose( (GDALDatasetH) poBand->GetDataset() ); 67 else 68 poBand->GetDataset()->Dereference(); 69 } 70 }; 71 72 73 /************************************************************************/ 74 /* VRTSource */ 75 /************************************************************************/ 76 77 class CPL_DLL VRTSource 78 { 79 public: 80 virtual ~VRTSource(); 81 82 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 83 void *pData, int nBufXSize, int nBufYSize, 84 GDALDataType eBufType, 85 GSpacing nPixelSpace, GSpacing nLineSpace, 86 GDALRasterIOExtraArg* psExtraArg ) = 0; 87 88 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0; 89 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0; 90 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0; 91 virtual CPLErr ComputeStatistics( int nXSize, int nYSize, 92 int bApproxOK, 93 double *pdfMin, double *pdfMax, 94 double *pdfMean, double *pdfStdDev, 95 GDALProgressFunc pfnProgress, void *pProgressData ) = 0; 96 virtual CPLErr GetHistogram( int nXSize, int nYSize, 97 double dfMin, double dfMax, 98 int nBuckets, GUIntBig * panHistogram, 99 int bIncludeOutOfRange, int bApproxOK, 100 GDALProgressFunc pfnProgress, void *pProgressData ) = 0; 101 102 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0; 103 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0; 104 105 virtual void GetFileList(char*** ppapszFileList, int *pnSize, 106 int *pnMaxSize, CPLHashSet* hSetFiles); 107 IsSimpleSource()108 virtual int IsSimpleSource() { return FALSE; } 109 }; 110 111 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *); 112 113 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * ); 114 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * ); 115 116 /************************************************************************/ 117 /* VRTDataset */ 118 /************************************************************************/ 119 120 class VRTRasterBand; 121 122 class CPL_DLL VRTDataset : public GDALDataset 123 { 124 friend class VRTRasterBand; 125 126 char *pszProjection; 127 128 int bGeoTransformSet; 129 double adfGeoTransform[6]; 130 131 int nGCPCount; 132 GDAL_GCP *pasGCPList; 133 char *pszGCPProjection; 134 135 int bNeedsFlush; 136 int bWritable; 137 138 char *pszVRTPath; 139 140 VRTRasterBand *poMaskBand; 141 142 int bCompatibleForDatasetIO; 143 int CheckCompatibleForDatasetIO(); 144 145 protected: 146 virtual int CloseDependentDatasets(); 147 148 public: 149 VRTDataset(int nXSize, int nYSize); 150 ~VRTDataset(); 151 SetNeedsFlush()152 void SetNeedsFlush() { bNeedsFlush = TRUE; } 153 virtual void FlushCache(); 154 SetWritable(int bWritable)155 void SetWritable(int bWritable) { this->bWritable = bWritable; } 156 157 virtual CPLErr CreateMaskBand( int nFlags ); 158 void SetMaskBand(VRTRasterBand* poMaskBand); 159 160 virtual const char *GetProjectionRef(void); 161 virtual CPLErr SetProjection( const char * ); 162 virtual CPLErr GetGeoTransform( double * ); 163 virtual CPLErr SetGeoTransform( double * ); 164 165 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" ); 166 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue, 167 const char *pszDomain = "" ); 168 169 virtual int GetGCPCount(); 170 virtual const char *GetGCPProjection(); 171 virtual const GDAL_GCP *GetGCPs(); 172 virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList, 173 const char *pszGCPProjection ); 174 175 virtual CPLErr AddBand( GDALDataType eType, 176 char **papszOptions=NULL ); 177 178 virtual char **GetFileList(); 179 180 virtual CPLErr IRasterIO( GDALRWFlag eRWFlag, 181 int nXOff, int nYOff, int nXSize, int nYSize, 182 void * pData, int nBufXSize, int nBufYSize, 183 GDALDataType eBufType, 184 int nBandCount, int *panBandMap, 185 GSpacing nPixelSpace, GSpacing nLineSpace, 186 GSpacing nBandSpace, 187 GDALRasterIOExtraArg* psExtraArg); 188 189 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath); 190 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 191 192 /* Used by PDF driver for example */ 193 GDALDataset* GetSingleSimpleSource(); 194 195 void UnsetPreservedRelativeFilenames(); 196 197 static int Identify( GDALOpenInfo * ); 198 static GDALDataset *Open( GDALOpenInfo * ); 199 static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly ); 200 static GDALDataset *Create( const char * pszName, 201 int nXSize, int nYSize, int nBands, 202 GDALDataType eType, char ** papszOptions ); 203 static CPLErr Delete( const char * pszFilename ); 204 }; 205 206 /************************************************************************/ 207 /* VRTWarpedDataset */ 208 /************************************************************************/ 209 210 class GDALWarpOperation; 211 class VRTWarpedRasterBand; 212 213 class CPL_DLL VRTWarpedDataset : public VRTDataset 214 { 215 int nBlockXSize; 216 int nBlockYSize; 217 GDALWarpOperation *poWarper; 218 219 int nOverviewCount; 220 VRTWarpedDataset **papoOverviews; 221 int nSrcOvrLevel; 222 223 void CreateImplicitOverviews(); 224 225 friend class VRTWarpedRasterBand; 226 227 protected: 228 virtual int CloseDependentDatasets(); 229 230 public: 231 VRTWarpedDataset( int nXSize, int nYSize ); 232 ~VRTWarpedDataset(); 233 234 CPLErr Initialize( /* GDALWarpOptions */ void * ); 235 236 virtual CPLErr IBuildOverviews( const char *, int, int *, 237 int, int *, GDALProgressFunc, void * ); 238 239 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue, 240 const char *pszDomain = "" ); 241 242 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 243 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 244 245 virtual CPLErr AddBand( GDALDataType eType, 246 char **papszOptions=NULL ); 247 248 virtual char **GetFileList(); 249 250 CPLErr ProcessBlock( int iBlockX, int iBlockY ); 251 252 void GetBlockSize( int *, int * ); 253 }; 254 255 /************************************************************************/ 256 /* VRTRasterBand */ 257 /* */ 258 /* Provides support for all the various kinds of metadata but */ 259 /* no raster access. That is handled by derived classes. */ 260 /************************************************************************/ 261 262 class CPL_DLL VRTRasterBand : public GDALRasterBand 263 { 264 protected: 265 int bIsMaskBand; 266 267 int bNoDataValueSet; 268 int bHideNoDataValue; // If set to true, will not report the existance of nodata 269 double dfNoDataValue; 270 271 GDALColorTable *poColorTable; 272 273 GDALColorInterp eColorInterp; 274 275 char *pszUnitType; 276 char **papszCategoryNames; 277 278 double dfOffset; 279 double dfScale; 280 281 CPLXMLNode *psSavedHistograms; 282 283 void Initialize( int nXSize, int nYSize ); 284 285 std::vector<VRTOverviewInfo> apoOverviews; 286 287 VRTRasterBand *poMaskBand; 288 289 public: 290 291 VRTRasterBand(); 292 virtual ~VRTRasterBand(); 293 294 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 295 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ); 296 297 virtual CPLErr SetNoDataValue( double ); 298 virtual double GetNoDataValue( int *pbSuccess = NULL ); 299 300 virtual CPLErr SetColorTable( GDALColorTable * ); 301 virtual GDALColorTable *GetColorTable(); 302 303 virtual CPLErr SetColorInterpretation( GDALColorInterp ); 304 virtual GDALColorInterp GetColorInterpretation(); 305 306 virtual const char *GetUnitType(); 307 CPLErr SetUnitType( const char * ); 308 309 virtual char **GetCategoryNames(); 310 virtual CPLErr SetCategoryNames( char ** ); 311 312 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" ); 313 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue, 314 const char *pszDomain = "" ); 315 316 virtual double GetOffset( int *pbSuccess = NULL ); 317 CPLErr SetOffset( double ); 318 virtual double GetScale( int *pbSuccess = NULL ); 319 CPLErr SetScale( double ); 320 321 virtual int GetOverviewCount(); 322 virtual GDALRasterBand *GetOverview(int); 323 324 virtual CPLErr GetHistogram( double dfMin, double dfMax, 325 int nBuckets, GUIntBig * panHistogram, 326 int bIncludeOutOfRange, int bApproxOK, 327 GDALProgressFunc, void *pProgressData ); 328 329 virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax, 330 int *pnBuckets, GUIntBig ** ppanHistogram, 331 int bForce, 332 GDALProgressFunc, void *pProgressData); 333 334 virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax, 335 int nBuckets, GUIntBig *panHistogram ); 336 337 CPLErr CopyCommonInfoFrom( GDALRasterBand * ); 338 339 virtual void GetFileList(char*** ppapszFileList, int *pnSize, 340 int *pnMaxSize, CPLHashSet* hSetFiles); 341 342 virtual void SetDescription( const char * ); 343 344 virtual GDALRasterBand *GetMaskBand(); 345 virtual int GetMaskFlags(); 346 347 virtual CPLErr CreateMaskBand( int nFlags ); 348 349 void SetMaskBand(VRTRasterBand* poMaskBand); 350 351 void SetIsMaskBand(); 352 353 CPLErr UnsetNoDataValue(); 354 355 virtual int CloseDependentDatasets(); 356 IsSourcedRasterBand()357 virtual int IsSourcedRasterBand() { return FALSE; } 358 }; 359 360 /************************************************************************/ 361 /* VRTSourcedRasterBand */ 362 /************************************************************************/ 363 364 class VRTSimpleSource; 365 366 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand 367 { 368 private: 369 int nRecursionCounter; 370 CPLString osLastLocationInfo; 371 char **papszSourceList; 372 373 void Initialize( int nXSize, int nYSize ); 374 375 int CanUseSourcesMinMaxImplementations(); 376 377 public: 378 int nSources; 379 VRTSource **papoSources; 380 int bEqualAreas; 381 382 VRTSourcedRasterBand( GDALDataset *poDS, int nBand ); 383 VRTSourcedRasterBand( GDALDataType eType, 384 int nXSize, int nYSize ); 385 VRTSourcedRasterBand( GDALDataset *poDS, int nBand, 386 GDALDataType eType, 387 int nXSize, int nYSize ); 388 virtual ~VRTSourcedRasterBand(); 389 390 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int, 391 void *, int, int, GDALDataType, 392 GSpacing nPixelSpace, GSpacing nLineSpace, 393 GDALRasterIOExtraArg* psExtraArg); 394 395 virtual char **GetMetadataDomainList(); 396 virtual const char *GetMetadataItem( const char * pszName, 397 const char * pszDomain = "" ); 398 virtual char **GetMetadata( const char * pszDomain = "" ); 399 virtual CPLErr SetMetadata( char ** papszMetadata, 400 const char * pszDomain = "" ); 401 virtual CPLErr SetMetadataItem( const char * pszName, 402 const char * pszValue, 403 const char * pszDomain = "" ); 404 405 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 406 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ); 407 408 virtual double GetMinimum( int *pbSuccess = NULL ); 409 virtual double GetMaximum(int *pbSuccess = NULL ); 410 virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax ); 411 virtual CPLErr ComputeStatistics( int bApproxOK, 412 double *pdfMin, double *pdfMax, 413 double *pdfMean, double *pdfStdDev, 414 GDALProgressFunc pfnProgress, void *pProgressData ); 415 virtual CPLErr GetHistogram( double dfMin, double dfMax, 416 int nBuckets, GUIntBig * panHistogram, 417 int bIncludeOutOfRange, int bApproxOK, 418 GDALProgressFunc pfnProgress, void *pProgressData ); 419 420 CPLErr AddSource( VRTSource * ); 421 CPLErr AddSimpleSource( GDALRasterBand *poSrcBand, 422 int nSrcXOff=-1, int nSrcYOff=-1, 423 int nSrcXSize=-1, int nSrcYSize=-1, 424 int nDstXOff=-1, int nDstYOff=-1, 425 int nDstXSize=-1, int nDstYSize=-1, 426 const char *pszResampling = "near", 427 double dfNoDataValue = VRT_NODATA_UNSET); 428 CPLErr AddComplexSource( GDALRasterBand *poSrcBand, 429 int nSrcXOff=-1, int nSrcYOff=-1, 430 int nSrcXSize=-1, int nSrcYSize=-1, 431 int nDstXOff=-1, int nDstYOff=-1, 432 int nDstXSize=-1, int nDstYSize=-1, 433 double dfScaleOff=0.0, 434 double dfScaleRatio=1.0, 435 double dfNoDataValue = VRT_NODATA_UNSET, 436 int nColorTableComponent = 0); 437 438 CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand, 439 int nSrcXOff=-1, int nSrcYOff=-1, 440 int nSrcXSize=-1, int nSrcYSize=-1, 441 int nDstXOff=-1, int nDstYOff=-1, 442 int nDstXSize=-1, int nDstYSize=-1 ); 443 444 CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData, 445 double dfNoDataValue = VRT_NODATA_UNSET ); 446 447 void ConfigureSource(VRTSimpleSource *poSimpleSource, 448 GDALRasterBand *poSrcBand, 449 int bAddAsMaskBand, 450 int nSrcXOff, int nSrcYOff, 451 int nSrcXSize, int nSrcYSize, 452 int nDstXOff, int nDstYOff, 453 int nDstXSize, int nDstYSize); 454 455 virtual CPLErr IReadBlock( int, int, void * ); 456 457 virtual void GetFileList(char*** ppapszFileList, int *pnSize, 458 int *pnMaxSize, CPLHashSet* hSetFiles); 459 460 virtual int CloseDependentDatasets(); 461 IsSourcedRasterBand()462 virtual int IsSourcedRasterBand() { return TRUE; } 463 }; 464 465 /************************************************************************/ 466 /* VRTWarpedRasterBand */ 467 /************************************************************************/ 468 469 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand 470 { 471 public: 472 VRTWarpedRasterBand( GDALDataset *poDS, int nBand, 473 GDALDataType eType = GDT_Unknown ); 474 virtual ~VRTWarpedRasterBand(); 475 476 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 477 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ); 478 479 virtual CPLErr IReadBlock( int, int, void * ); 480 virtual CPLErr IWriteBlock( int, int, void * ); 481 482 virtual int GetOverviewCount(); 483 virtual GDALRasterBand *GetOverview(int); 484 }; 485 486 /************************************************************************/ 487 /* VRTDerivedRasterBand */ 488 /************************************************************************/ 489 490 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand 491 { 492 493 public: 494 char *pszFuncName; 495 GDALDataType eSourceTransferType; 496 497 VRTDerivedRasterBand(GDALDataset *poDS, int nBand); 498 VRTDerivedRasterBand(GDALDataset *poDS, int nBand, 499 GDALDataType eType, int nXSize, int nYSize); 500 virtual ~VRTDerivedRasterBand(); 501 502 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int, 503 void *, int, int, GDALDataType, 504 GSpacing nPixelSpace, GSpacing nLineSpace, 505 GDALRasterIOExtraArg* psExtraArg ); 506 507 static CPLErr AddPixelFunction 508 (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc); 509 static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName); 510 511 void SetPixelFunctionName(const char *pszFuncName); 512 void SetSourceTransferType(GDALDataType eDataType); 513 514 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 515 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ); 516 517 }; 518 519 /************************************************************************/ 520 /* VRTRawRasterBand */ 521 /************************************************************************/ 522 523 class RawRasterBand; 524 525 class CPL_DLL VRTRawRasterBand : public VRTRasterBand 526 { 527 RawRasterBand *poRawRaster; 528 529 char *pszSourceFilename; 530 int bRelativeToVRT; 531 532 public: 533 VRTRawRasterBand( GDALDataset *poDS, int nBand, 534 GDALDataType eType = GDT_Unknown ); 535 virtual ~VRTRawRasterBand(); 536 537 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 538 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ); 539 540 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int, 541 void *, int, int, GDALDataType, 542 GSpacing nPixelSpace, GSpacing nLineSpace, 543 GDALRasterIOExtraArg* psExtraArg ); 544 545 virtual CPLErr IReadBlock( int, int, void * ); 546 virtual CPLErr IWriteBlock( int, int, void * ); 547 548 CPLErr SetRawLink( const char *pszFilename, 549 const char *pszVRTPath, 550 int bRelativeToVRT, 551 vsi_l_offset nImageOffset, 552 int nPixelOffset, int nLineOffset, 553 const char *pszByteOrder ); 554 555 void ClearRawLink(); 556 557 virtual void GetFileList(char*** ppapszFileList, int *pnSize, 558 int *pnMaxSize, CPLHashSet* hSetFiles); 559 }; 560 561 /************************************************************************/ 562 /* VRTDriver */ 563 /************************************************************************/ 564 565 class VRTDriver : public GDALDriver 566 { 567 void *pDeserializerData; 568 569 public: 570 VRTDriver(); 571 ~VRTDriver(); 572 573 char **papszSourceParsers; 574 575 virtual char **GetMetadataDomainList(); 576 virtual char **GetMetadata( const char * pszDomain = "" ); 577 virtual CPLErr SetMetadata( char ** papszMetadata, 578 const char * pszDomain = "" ); 579 580 VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath ); 581 void AddSourceParser( const char *pszElementName, 582 VRTSourceParser pfnParser ); 583 }; 584 585 /************************************************************************/ 586 /* VRTSimpleSource */ 587 /************************************************************************/ 588 589 class CPL_DLL VRTSimpleSource : public VRTSource 590 { 591 protected: 592 GDALRasterBand *poRasterBand; 593 594 /* when poRasterBand is a mask band, poMaskBandMainBand is the band */ 595 /* from which the mask band is taken */ 596 GDALRasterBand *poMaskBandMainBand; 597 598 int nSrcXOff; 599 int nSrcYOff; 600 int nSrcXSize; 601 int nSrcYSize; 602 603 int nDstXOff; 604 int nDstYOff; 605 int nDstXSize; 606 int nDstYSize; 607 608 int bNoDataSet; 609 double dfNoDataValue; 610 CPLString osResampling; 611 612 int bRelativeToVRTOri; 613 CPLString osSourceFileNameOri; 614 615 public: 616 VRTSimpleSource(); 617 virtual ~VRTSimpleSource(); 618 619 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ); 620 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 621 622 void SetSrcBand( GDALRasterBand * ); 623 void SetSrcMaskBand( GDALRasterBand * ); 624 void SetSrcWindow( int, int, int, int ); 625 void SetDstWindow( int, int, int, int ); 626 void SetNoDataValue( double dfNoDataValue ); GetResampling()627 const CPLString& GetResampling() const { return osResampling; } 628 void SetResampling( const char* pszResampling ); 629 630 int GetSrcDstWindow( int, int, int, int, int, int, 631 double *pdfReqXOff, double *pdfReqYOff, 632 double *pdfReqXSize, double *pdfReqYSize, 633 int *, int *, int *, int *, 634 int *, int *, int *, int * ); 635 636 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 637 void *pData, int nBufXSize, int nBufYSize, 638 GDALDataType eBufType, 639 GSpacing nPixelSpace, GSpacing nLineSpace, 640 GDALRasterIOExtraArg* psExtraArg ); 641 642 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ); 643 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ); 644 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ); 645 virtual CPLErr ComputeStatistics( int nXSize, int nYSize, 646 int bApproxOK, 647 double *pdfMin, double *pdfMax, 648 double *pdfMean, double *pdfStdDev, 649 GDALProgressFunc pfnProgress, void *pProgressData ); 650 virtual CPLErr GetHistogram( int nXSize, int nYSize, 651 double dfMin, double dfMax, 652 int nBuckets, GUIntBig * panHistogram, 653 int bIncludeOutOfRange, int bApproxOK, 654 GDALProgressFunc pfnProgress, void *pProgressData ); 655 656 void DstToSrc( double dfX, double dfY, 657 double &dfXOut, double &dfYOut ); 658 void SrcToDst( double dfX, double dfY, 659 double &dfXOut, double &dfYOut ); 660 661 virtual void GetFileList(char*** ppapszFileList, int *pnSize, 662 int *pnMaxSize, CPLHashSet* hSetFiles); 663 IsSimpleSource()664 virtual int IsSimpleSource() { return TRUE; } GetType()665 virtual const char* GetType() { return "SimpleSource"; } 666 667 GDALRasterBand* GetBand(); 668 int IsSameExceptBandNumber(VRTSimpleSource* poOtherSource); 669 CPLErr DatasetRasterIO( 670 int nXOff, int nYOff, int nXSize, int nYSize, 671 void * pData, int nBufXSize, int nBufYSize, 672 GDALDataType eBufType, 673 int nBandCount, int *panBandMap, 674 GSpacing nPixelSpace, GSpacing nLineSpace, 675 GSpacing nBandSpace, 676 GDALRasterIOExtraArg* psExtraArg); 677 678 void UnsetPreservedRelativeFilenames(); 679 }; 680 681 /************************************************************************/ 682 /* VRTAveragedSource */ 683 /************************************************************************/ 684 685 class VRTAveragedSource : public VRTSimpleSource 686 { 687 public: 688 VRTAveragedSource(); 689 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 690 void *pData, int nBufXSize, int nBufYSize, 691 GDALDataType eBufType, 692 GSpacing nPixelSpace, GSpacing nLineSpace, 693 GDALRasterIOExtraArg* psExtraArg ); 694 695 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ); 696 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ); 697 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ); 698 virtual CPLErr ComputeStatistics( int nXSize, int nYSize, 699 int bApproxOK, 700 double *pdfMin, double *pdfMax, 701 double *pdfMean, double *pdfStdDev, 702 GDALProgressFunc pfnProgress, void *pProgressData ); 703 virtual CPLErr GetHistogram( int nXSize, int nYSize, 704 double dfMin, double dfMax, 705 int nBuckets, GUIntBig * panHistogram, 706 int bIncludeOutOfRange, int bApproxOK, 707 GDALProgressFunc pfnProgress, void *pProgressData ); 708 709 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); GetType()710 virtual const char* GetType() { return "AveragedSource"; } 711 }; 712 713 /************************************************************************/ 714 /* VRTComplexSource */ 715 /************************************************************************/ 716 717 typedef enum 718 { 719 VRT_SCALING_NONE, 720 VRT_SCALING_LINEAR, 721 VRT_SCALING_EXPONENTIAL, 722 } VRTComplexSourceScaling; 723 724 class CPL_DLL VRTComplexSource : public VRTSimpleSource 725 { 726 protected: 727 VRTComplexSourceScaling eScalingType; 728 double dfScaleOff; /* for linear scaling */ 729 double dfScaleRatio; /* for linear scaling */ 730 731 /* For non-linear scaling with a power function. */ 732 int bSrcMinMaxDefined; 733 double dfSrcMin; 734 double dfSrcMax; 735 double dfDstMin; 736 double dfDstMax; 737 double dfExponent; 738 739 int nColorTableComponent; 740 741 CPLErr RasterIOInternal( int nReqXOff, int nReqYOff, 742 int nReqXSize, int nReqYSize, 743 void *pData, int nOutXSize, int nOutYSize, 744 GDALDataType eBufType, 745 GSpacing nPixelSpace, GSpacing nLineSpace, 746 GDALRasterIOExtraArg* psExtraArg ); 747 748 public: 749 VRTComplexSource(); 750 virtual ~VRTComplexSource(); 751 752 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 753 void *pData, int nBufXSize, int nBufYSize, 754 GDALDataType eBufType, 755 GSpacing nPixelSpace, GSpacing nLineSpace, 756 GDALRasterIOExtraArg* psExtraArg ); 757 758 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ); 759 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ); 760 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ); 761 virtual CPLErr ComputeStatistics( int nXSize, int nYSize, 762 int bApproxOK, 763 double *pdfMin, double *pdfMax, 764 double *pdfMean, double *pdfStdDev, 765 GDALProgressFunc pfnProgress, void *pProgressData ); 766 virtual CPLErr GetHistogram( int nXSize, int nYSize, 767 double dfMin, double dfMax, 768 int nBuckets, GUIntBig * panHistogram, 769 int bIncludeOutOfRange, int bApproxOK, 770 GDALProgressFunc pfnProgress, void *pProgressData ); 771 772 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 773 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); GetType()774 virtual const char* GetType() { return "ComplexSource"; } 775 776 double LookupValue( double dfInput ); 777 778 void SetLinearScaling(double dfOffset, double dfScale); 779 void SetPowerScaling(double dfExponent, 780 double dfSrcMin, 781 double dfSrcMax, 782 double dfDstMin, 783 double dfDstMax); 784 void SetColorTableComponent(int nComponent); 785 786 double *padfLUTInputs; 787 double *padfLUTOutputs; 788 int nLUTItemCount; 789 790 }; 791 792 /************************************************************************/ 793 /* VRTFilteredSource */ 794 /************************************************************************/ 795 796 class VRTFilteredSource : public VRTComplexSource 797 { 798 private: 799 int IsTypeSupported( GDALDataType eType ); 800 801 protected: 802 int nSupportedTypesCount; 803 GDALDataType aeSupportedTypes[20]; 804 805 int nExtraEdgePixels; 806 807 public: 808 VRTFilteredSource(); 809 virtual ~VRTFilteredSource(); 810 811 void SetExtraEdgePixels( int ); 812 void SetFilteringDataTypesSupported( int, GDALDataType * ); 813 814 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType, 815 GByte *pabySrcData, GByte *pabyDstData ) = 0; 816 817 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 818 void *pData, int nBufXSize, int nBufYSize, 819 GDALDataType eBufType, 820 GSpacing nPixelSpace, GSpacing nLineSpace, 821 GDALRasterIOExtraArg* psExtraArg ); 822 }; 823 824 /************************************************************************/ 825 /* VRTKernelFilteredSource */ 826 /************************************************************************/ 827 828 class VRTKernelFilteredSource : public VRTFilteredSource 829 { 830 protected: 831 int nKernelSize; 832 833 double *padfKernelCoefs; 834 835 int bNormalized; 836 837 public: 838 VRTKernelFilteredSource(); 839 virtual ~VRTKernelFilteredSource(); 840 841 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ); 842 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 843 844 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType, 845 GByte *pabySrcData, GByte *pabyDstData ); 846 847 CPLErr SetKernel( int nKernelSize, double *padfCoefs ); 848 void SetNormalized( int ); 849 }; 850 851 /************************************************************************/ 852 /* VRTAverageFilteredSource */ 853 /************************************************************************/ 854 855 class VRTAverageFilteredSource : public VRTKernelFilteredSource 856 { 857 public: 858 VRTAverageFilteredSource( int nKernelSize ); 859 virtual ~VRTAverageFilteredSource(); 860 861 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ); 862 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 863 }; 864 865 /************************************************************************/ 866 /* VRTFuncSource */ 867 /************************************************************************/ 868 class VRTFuncSource : public VRTSource 869 { 870 public: 871 VRTFuncSource(); 872 virtual ~VRTFuncSource(); 873 XMLInit(CPLXMLNode *,const char *)874 virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; } 875 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ); 876 877 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 878 void *pData, int nBufXSize, int nBufYSize, 879 GDALDataType eBufType, 880 GSpacing nPixelSpace, GSpacing nLineSpace, 881 GDALRasterIOExtraArg* psExtraArg ); 882 883 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ); 884 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ); 885 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ); 886 virtual CPLErr ComputeStatistics( int nXSize, int nYSize, 887 int bApproxOK, 888 double *pdfMin, double *pdfMax, 889 double *pdfMean, double *pdfStdDev, 890 GDALProgressFunc pfnProgress, void *pProgressData ); 891 virtual CPLErr GetHistogram( int nXSize, int nYSize, 892 double dfMin, double dfMax, 893 int nBuckets, GUIntBig * panHistogram, 894 int bIncludeOutOfRange, int bApproxOK, 895 GDALProgressFunc pfnProgress, void *pProgressData ); 896 897 VRTImageReadFunc pfnReadFunc; 898 void *pCBData; 899 GDALDataType eType; 900 901 float fNoDataValue; 902 }; 903 904 #endif /* ndef VIRTUALDATASET_H_INCLUDED */ 905