vrtdataset.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. #ifndef VIRTUALDATASET_H_INCLUDED
  31. #define VIRTUALDATASET_H_INCLUDED
  32. #include "gdal_priv.h"
  33. #include "gdal_pam.h"
  34. #include "gdal_vrt.h"
  35. #include "cpl_hash_set.h"
  36. int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
  37. CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
  38. #if 0
  39. int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
  40. int nPointCount,
  41. double *padfX, double *padfY, double *padfZ,
  42. int *panSuccess );
  43. void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
  44. #endif
  45. /************************************************************************/
  46. /* VRTOverviewInfo() */
  47. /************************************************************************/
  48. class VRTOverviewInfo
  49. {
  50. public:
  51. CPLString osFilename;
  52. int nBand;
  53. GDALRasterBand *poBand;
  54. int bTriedToOpen;
  55. VRTOverviewInfo() : poBand(NULL), bTriedToOpen(FALSE) {}
  56. ~VRTOverviewInfo() {
  57. if( poBand == NULL )
  58. /* do nothing */;
  59. else if( poBand->GetDataset()->GetShared() )
  60. GDALClose( (GDALDatasetH) poBand->GetDataset() );
  61. else
  62. poBand->GetDataset()->Dereference();
  63. }
  64. };
  65. /************************************************************************/
  66. /* VRTSource */
  67. /************************************************************************/
  68. class CPL_DLL VRTSource
  69. {
  70. public:
  71. virtual ~VRTSource();
  72. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  73. void *pData, int nBufXSize, int nBufYSize,
  74. GDALDataType eBufType,
  75. GSpacing nPixelSpace, GSpacing nLineSpace,
  76. GDALRasterIOExtraArg* psExtraArg ) = 0;
  77. virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
  78. virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
  79. virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0;
  80. virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
  81. int bApproxOK,
  82. double *pdfMin, double *pdfMax,
  83. double *pdfMean, double *pdfStdDev,
  84. GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
  85. virtual CPLErr GetHistogram( int nXSize, int nYSize,
  86. double dfMin, double dfMax,
  87. int nBuckets, GUIntBig * panHistogram,
  88. int bIncludeOutOfRange, int bApproxOK,
  89. GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
  90. virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
  91. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
  92. virtual void GetFileList(char*** ppapszFileList, int *pnSize,
  93. int *pnMaxSize, CPLHashSet* hSetFiles);
  94. virtual int IsSimpleSource() { return FALSE; }
  95. };
  96. typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
  97. VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
  98. VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
  99. /************************************************************************/
  100. /* VRTDataset */
  101. /************************************************************************/
  102. class VRTRasterBand;
  103. class CPL_DLL VRTDataset : public GDALDataset
  104. {
  105. friend class VRTRasterBand;
  106. char *pszProjection;
  107. int bGeoTransformSet;
  108. double adfGeoTransform[6];
  109. int nGCPCount;
  110. GDAL_GCP *pasGCPList;
  111. char *pszGCPProjection;
  112. int bNeedsFlush;
  113. int bWritable;
  114. char *pszVRTPath;
  115. VRTRasterBand *poMaskBand;
  116. int bCompatibleForDatasetIO;
  117. int CheckCompatibleForDatasetIO();
  118. protected:
  119. virtual int CloseDependentDatasets();
  120. public:
  121. VRTDataset(int nXSize, int nYSize);
  122. ~VRTDataset();
  123. void SetNeedsFlush() { bNeedsFlush = TRUE; }
  124. virtual void FlushCache();
  125. void SetWritable(int bWritable) { this->bWritable = bWritable; }
  126. virtual CPLErr CreateMaskBand( int nFlags );
  127. void SetMaskBand(VRTRasterBand* poMaskBand);
  128. virtual const char *GetProjectionRef(void);
  129. virtual CPLErr SetProjection( const char * );
  130. virtual CPLErr GetGeoTransform( double * );
  131. virtual CPLErr SetGeoTransform( double * );
  132. virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
  133. virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
  134. const char *pszDomain = "" );
  135. virtual int GetGCPCount();
  136. virtual const char *GetGCPProjection();
  137. virtual const GDAL_GCP *GetGCPs();
  138. virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
  139. const char *pszGCPProjection );
  140. virtual CPLErr AddBand( GDALDataType eType,
  141. char **papszOptions=NULL );
  142. virtual char **GetFileList();
  143. virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
  144. int nXOff, int nYOff, int nXSize, int nYSize,
  145. void * pData, int nBufXSize, int nBufYSize,
  146. GDALDataType eBufType,
  147. int nBandCount, int *panBandMap,
  148. GSpacing nPixelSpace, GSpacing nLineSpace,
  149. GSpacing nBandSpace,
  150. GDALRasterIOExtraArg* psExtraArg);
  151. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
  152. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  153. /* Used by PDF driver for example */
  154. GDALDataset* GetSingleSimpleSource();
  155. void UnsetPreservedRelativeFilenames();
  156. static int Identify( GDALOpenInfo * );
  157. static GDALDataset *Open( GDALOpenInfo * );
  158. static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
  159. static GDALDataset *Create( const char * pszName,
  160. int nXSize, int nYSize, int nBands,
  161. GDALDataType eType, char ** papszOptions );
  162. static CPLErr Delete( const char * pszFilename );
  163. };
  164. /************************************************************************/
  165. /* VRTWarpedDataset */
  166. /************************************************************************/
  167. class GDALWarpOperation;
  168. class VRTWarpedRasterBand;
  169. class CPL_DLL VRTWarpedDataset : public VRTDataset
  170. {
  171. int nBlockXSize;
  172. int nBlockYSize;
  173. GDALWarpOperation *poWarper;
  174. int nOverviewCount;
  175. VRTWarpedDataset **papoOverviews;
  176. int nSrcOvrLevel;
  177. void CreateImplicitOverviews();
  178. friend class VRTWarpedRasterBand;
  179. protected:
  180. virtual int CloseDependentDatasets();
  181. public:
  182. VRTWarpedDataset( int nXSize, int nYSize );
  183. ~VRTWarpedDataset();
  184. CPLErr Initialize( /* GDALWarpOptions */ void * );
  185. virtual CPLErr IBuildOverviews( const char *, int, int *,
  186. int, int *, GDALProgressFunc, void * );
  187. virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
  188. const char *pszDomain = "" );
  189. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  190. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  191. virtual CPLErr AddBand( GDALDataType eType,
  192. char **papszOptions=NULL );
  193. virtual char **GetFileList();
  194. CPLErr ProcessBlock( int iBlockX, int iBlockY );
  195. void GetBlockSize( int *, int * );
  196. };
  197. /************************************************************************/
  198. /* VRTRasterBand */
  199. /* */
  200. /* Provides support for all the various kinds of metadata but */
  201. /* no raster access. That is handled by derived classes. */
  202. /************************************************************************/
  203. class CPL_DLL VRTRasterBand : public GDALRasterBand
  204. {
  205. protected:
  206. int bIsMaskBand;
  207. int bNoDataValueSet;
  208. int bHideNoDataValue; // If set to true, will not report the existance of nodata
  209. double dfNoDataValue;
  210. GDALColorTable *poColorTable;
  211. GDALColorInterp eColorInterp;
  212. char *pszUnitType;
  213. char **papszCategoryNames;
  214. double dfOffset;
  215. double dfScale;
  216. CPLXMLNode *psSavedHistograms;
  217. void Initialize( int nXSize, int nYSize );
  218. std::vector<VRTOverviewInfo> apoOverviews;
  219. VRTRasterBand *poMaskBand;
  220. public:
  221. VRTRasterBand();
  222. virtual ~VRTRasterBand();
  223. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  224. virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
  225. virtual CPLErr SetNoDataValue( double );
  226. virtual double GetNoDataValue( int *pbSuccess = NULL );
  227. virtual CPLErr SetColorTable( GDALColorTable * );
  228. virtual GDALColorTable *GetColorTable();
  229. virtual CPLErr SetColorInterpretation( GDALColorInterp );
  230. virtual GDALColorInterp GetColorInterpretation();
  231. virtual const char *GetUnitType();
  232. CPLErr SetUnitType( const char * );
  233. virtual char **GetCategoryNames();
  234. virtual CPLErr SetCategoryNames( char ** );
  235. virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
  236. virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
  237. const char *pszDomain = "" );
  238. virtual double GetOffset( int *pbSuccess = NULL );
  239. CPLErr SetOffset( double );
  240. virtual double GetScale( int *pbSuccess = NULL );
  241. CPLErr SetScale( double );
  242. virtual int GetOverviewCount();
  243. virtual GDALRasterBand *GetOverview(int);
  244. virtual CPLErr GetHistogram( double dfMin, double dfMax,
  245. int nBuckets, GUIntBig * panHistogram,
  246. int bIncludeOutOfRange, int bApproxOK,
  247. GDALProgressFunc, void *pProgressData );
  248. virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
  249. int *pnBuckets, GUIntBig ** ppanHistogram,
  250. int bForce,
  251. GDALProgressFunc, void *pProgressData);
  252. virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
  253. int nBuckets, GUIntBig *panHistogram );
  254. CPLErr CopyCommonInfoFrom( GDALRasterBand * );
  255. virtual void GetFileList(char*** ppapszFileList, int *pnSize,
  256. int *pnMaxSize, CPLHashSet* hSetFiles);
  257. virtual void SetDescription( const char * );
  258. virtual GDALRasterBand *GetMaskBand();
  259. virtual int GetMaskFlags();
  260. virtual CPLErr CreateMaskBand( int nFlags );
  261. void SetMaskBand(VRTRasterBand* poMaskBand);
  262. void SetIsMaskBand();
  263. CPLErr UnsetNoDataValue();
  264. virtual int CloseDependentDatasets();
  265. virtual int IsSourcedRasterBand() { return FALSE; }
  266. };
  267. /************************************************************************/
  268. /* VRTSourcedRasterBand */
  269. /************************************************************************/
  270. class VRTSimpleSource;
  271. class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
  272. {
  273. private:
  274. int nRecursionCounter;
  275. CPLString osLastLocationInfo;
  276. char **papszSourceList;
  277. void Initialize( int nXSize, int nYSize );
  278. int CanUseSourcesMinMaxImplementations();
  279. public:
  280. int nSources;
  281. VRTSource **papoSources;
  282. int bEqualAreas;
  283. VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
  284. VRTSourcedRasterBand( GDALDataType eType,
  285. int nXSize, int nYSize );
  286. VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
  287. GDALDataType eType,
  288. int nXSize, int nYSize );
  289. virtual ~VRTSourcedRasterBand();
  290. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  291. void *, int, int, GDALDataType,
  292. GSpacing nPixelSpace, GSpacing nLineSpace,
  293. GDALRasterIOExtraArg* psExtraArg);
  294. virtual char **GetMetadataDomainList();
  295. virtual const char *GetMetadataItem( const char * pszName,
  296. const char * pszDomain = "" );
  297. virtual char **GetMetadata( const char * pszDomain = "" );
  298. virtual CPLErr SetMetadata( char ** papszMetadata,
  299. const char * pszDomain = "" );
  300. virtual CPLErr SetMetadataItem( const char * pszName,
  301. const char * pszValue,
  302. const char * pszDomain = "" );
  303. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  304. virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
  305. virtual double GetMinimum( int *pbSuccess = NULL );
  306. virtual double GetMaximum(int *pbSuccess = NULL );
  307. virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax );
  308. virtual CPLErr ComputeStatistics( int bApproxOK,
  309. double *pdfMin, double *pdfMax,
  310. double *pdfMean, double *pdfStdDev,
  311. GDALProgressFunc pfnProgress, void *pProgressData );
  312. virtual CPLErr GetHistogram( double dfMin, double dfMax,
  313. int nBuckets, GUIntBig * panHistogram,
  314. int bIncludeOutOfRange, int bApproxOK,
  315. GDALProgressFunc pfnProgress, void *pProgressData );
  316. CPLErr AddSource( VRTSource * );
  317. CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
  318. int nSrcXOff=-1, int nSrcYOff=-1,
  319. int nSrcXSize=-1, int nSrcYSize=-1,
  320. int nDstXOff=-1, int nDstYOff=-1,
  321. int nDstXSize=-1, int nDstYSize=-1,
  322. const char *pszResampling = "near",
  323. double dfNoDataValue = VRT_NODATA_UNSET);
  324. CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
  325. int nSrcXOff=-1, int nSrcYOff=-1,
  326. int nSrcXSize=-1, int nSrcYSize=-1,
  327. int nDstXOff=-1, int nDstYOff=-1,
  328. int nDstXSize=-1, int nDstYSize=-1,
  329. double dfScaleOff=0.0,
  330. double dfScaleRatio=1.0,
  331. double dfNoDataValue = VRT_NODATA_UNSET,
  332. int nColorTableComponent = 0);
  333. CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
  334. int nSrcXOff=-1, int nSrcYOff=-1,
  335. int nSrcXSize=-1, int nSrcYSize=-1,
  336. int nDstXOff=-1, int nDstYOff=-1,
  337. int nDstXSize=-1, int nDstYSize=-1 );
  338. CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
  339. double dfNoDataValue = VRT_NODATA_UNSET );
  340. void ConfigureSource(VRTSimpleSource *poSimpleSource,
  341. GDALRasterBand *poSrcBand,
  342. int bAddAsMaskBand,
  343. int nSrcXOff, int nSrcYOff,
  344. int nSrcXSize, int nSrcYSize,
  345. int nDstXOff, int nDstYOff,
  346. int nDstXSize, int nDstYSize);
  347. virtual CPLErr IReadBlock( int, int, void * );
  348. virtual void GetFileList(char*** ppapszFileList, int *pnSize,
  349. int *pnMaxSize, CPLHashSet* hSetFiles);
  350. virtual int CloseDependentDatasets();
  351. virtual int IsSourcedRasterBand() { return TRUE; }
  352. };
  353. /************************************************************************/
  354. /* VRTWarpedRasterBand */
  355. /************************************************************************/
  356. class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
  357. {
  358. public:
  359. VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
  360. GDALDataType eType = GDT_Unknown );
  361. virtual ~VRTWarpedRasterBand();
  362. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  363. virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
  364. virtual CPLErr IReadBlock( int, int, void * );
  365. virtual CPLErr IWriteBlock( int, int, void * );
  366. virtual int GetOverviewCount();
  367. virtual GDALRasterBand *GetOverview(int);
  368. };
  369. /************************************************************************/
  370. /* VRTDerivedRasterBand */
  371. /************************************************************************/
  372. class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
  373. {
  374. public:
  375. char *pszFuncName;
  376. GDALDataType eSourceTransferType;
  377. VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
  378. VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
  379. GDALDataType eType, int nXSize, int nYSize);
  380. virtual ~VRTDerivedRasterBand();
  381. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  382. void *, int, int, GDALDataType,
  383. GSpacing nPixelSpace, GSpacing nLineSpace,
  384. GDALRasterIOExtraArg* psExtraArg );
  385. static CPLErr AddPixelFunction
  386. (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
  387. static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
  388. void SetPixelFunctionName(const char *pszFuncName);
  389. void SetSourceTransferType(GDALDataType eDataType);
  390. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  391. virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
  392. };
  393. /************************************************************************/
  394. /* VRTRawRasterBand */
  395. /************************************************************************/
  396. class RawRasterBand;
  397. class CPL_DLL VRTRawRasterBand : public VRTRasterBand
  398. {
  399. RawRasterBand *poRawRaster;
  400. char *pszSourceFilename;
  401. int bRelativeToVRT;
  402. public:
  403. VRTRawRasterBand( GDALDataset *poDS, int nBand,
  404. GDALDataType eType = GDT_Unknown );
  405. virtual ~VRTRawRasterBand();
  406. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  407. virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
  408. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  409. void *, int, int, GDALDataType,
  410. GSpacing nPixelSpace, GSpacing nLineSpace,
  411. GDALRasterIOExtraArg* psExtraArg );
  412. virtual CPLErr IReadBlock( int, int, void * );
  413. virtual CPLErr IWriteBlock( int, int, void * );
  414. CPLErr SetRawLink( const char *pszFilename,
  415. const char *pszVRTPath,
  416. int bRelativeToVRT,
  417. vsi_l_offset nImageOffset,
  418. int nPixelOffset, int nLineOffset,
  419. const char *pszByteOrder );
  420. void ClearRawLink();
  421. virtual void GetFileList(char*** ppapszFileList, int *pnSize,
  422. int *pnMaxSize, CPLHashSet* hSetFiles);
  423. };
  424. /************************************************************************/
  425. /* VRTDriver */
  426. /************************************************************************/
  427. class VRTDriver : public GDALDriver
  428. {
  429. void *pDeserializerData;
  430. public:
  431. VRTDriver();
  432. ~VRTDriver();
  433. char **papszSourceParsers;
  434. virtual char **GetMetadataDomainList();
  435. virtual char **GetMetadata( const char * pszDomain = "" );
  436. virtual CPLErr SetMetadata( char ** papszMetadata,
  437. const char * pszDomain = "" );
  438. VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
  439. void AddSourceParser( const char *pszElementName,
  440. VRTSourceParser pfnParser );
  441. };
  442. /************************************************************************/
  443. /* VRTSimpleSource */
  444. /************************************************************************/
  445. class CPL_DLL VRTSimpleSource : public VRTSource
  446. {
  447. protected:
  448. GDALRasterBand *poRasterBand;
  449. /* when poRasterBand is a mask band, poMaskBandMainBand is the band */
  450. /* from which the mask band is taken */
  451. GDALRasterBand *poMaskBandMainBand;
  452. int nSrcXOff;
  453. int nSrcYOff;
  454. int nSrcXSize;
  455. int nSrcYSize;
  456. int nDstXOff;
  457. int nDstYOff;
  458. int nDstXSize;
  459. int nDstYSize;
  460. int bNoDataSet;
  461. double dfNoDataValue;
  462. CPLString osResampling;
  463. int bRelativeToVRTOri;
  464. CPLString osSourceFileNameOri;
  465. public:
  466. VRTSimpleSource();
  467. virtual ~VRTSimpleSource();
  468. virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
  469. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  470. void SetSrcBand( GDALRasterBand * );
  471. void SetSrcMaskBand( GDALRasterBand * );
  472. void SetSrcWindow( int, int, int, int );
  473. void SetDstWindow( int, int, int, int );
  474. void SetNoDataValue( double dfNoDataValue );
  475. const CPLString& GetResampling() const { return osResampling; }
  476. void SetResampling( const char* pszResampling );
  477. int GetSrcDstWindow( int, int, int, int, int, int,
  478. double *pdfReqXOff, double *pdfReqYOff,
  479. double *pdfReqXSize, double *pdfReqYSize,
  480. int *, int *, int *, int *,
  481. int *, int *, int *, int * );
  482. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  483. void *pData, int nBufXSize, int nBufYSize,
  484. GDALDataType eBufType,
  485. GSpacing nPixelSpace, GSpacing nLineSpace,
  486. GDALRasterIOExtraArg* psExtraArg );
  487. virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
  488. virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
  489. virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
  490. virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
  491. int bApproxOK,
  492. double *pdfMin, double *pdfMax,
  493. double *pdfMean, double *pdfStdDev,
  494. GDALProgressFunc pfnProgress, void *pProgressData );
  495. virtual CPLErr GetHistogram( int nXSize, int nYSize,
  496. double dfMin, double dfMax,
  497. int nBuckets, GUIntBig * panHistogram,
  498. int bIncludeOutOfRange, int bApproxOK,
  499. GDALProgressFunc pfnProgress, void *pProgressData );
  500. void DstToSrc( double dfX, double dfY,
  501. double &dfXOut, double &dfYOut );
  502. void SrcToDst( double dfX, double dfY,
  503. double &dfXOut, double &dfYOut );
  504. virtual void GetFileList(char*** ppapszFileList, int *pnSize,
  505. int *pnMaxSize, CPLHashSet* hSetFiles);
  506. virtual int IsSimpleSource() { return TRUE; }
  507. virtual const char* GetType() { return "SimpleSource"; }
  508. GDALRasterBand* GetBand();
  509. int IsSameExceptBandNumber(VRTSimpleSource* poOtherSource);
  510. CPLErr DatasetRasterIO(
  511. int nXOff, int nYOff, int nXSize, int nYSize,
  512. void * pData, int nBufXSize, int nBufYSize,
  513. GDALDataType eBufType,
  514. int nBandCount, int *panBandMap,
  515. GSpacing nPixelSpace, GSpacing nLineSpace,
  516. GSpacing nBandSpace,
  517. GDALRasterIOExtraArg* psExtraArg);
  518. void UnsetPreservedRelativeFilenames();
  519. };
  520. /************************************************************************/
  521. /* VRTAveragedSource */
  522. /************************************************************************/
  523. class VRTAveragedSource : public VRTSimpleSource
  524. {
  525. public:
  526. VRTAveragedSource();
  527. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  528. void *pData, int nBufXSize, int nBufYSize,
  529. GDALDataType eBufType,
  530. GSpacing nPixelSpace, GSpacing nLineSpace,
  531. GDALRasterIOExtraArg* psExtraArg );
  532. virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
  533. virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
  534. virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
  535. virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
  536. int bApproxOK,
  537. double *pdfMin, double *pdfMax,
  538. double *pdfMean, double *pdfStdDev,
  539. GDALProgressFunc pfnProgress, void *pProgressData );
  540. virtual CPLErr GetHistogram( int nXSize, int nYSize,
  541. double dfMin, double dfMax,
  542. int nBuckets, GUIntBig * panHistogram,
  543. int bIncludeOutOfRange, int bApproxOK,
  544. GDALProgressFunc pfnProgress, void *pProgressData );
  545. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  546. virtual const char* GetType() { return "AveragedSource"; }
  547. };
  548. /************************************************************************/
  549. /* VRTComplexSource */
  550. /************************************************************************/
  551. typedef enum
  552. {
  553. VRT_SCALING_NONE,
  554. VRT_SCALING_LINEAR,
  555. VRT_SCALING_EXPONENTIAL,
  556. } VRTComplexSourceScaling;
  557. class CPL_DLL VRTComplexSource : public VRTSimpleSource
  558. {
  559. protected:
  560. VRTComplexSourceScaling eScalingType;
  561. double dfScaleOff; /* for linear scaling */
  562. double dfScaleRatio; /* for linear scaling */
  563. /* For non-linear scaling with a power function. */
  564. int bSrcMinMaxDefined;
  565. double dfSrcMin;
  566. double dfSrcMax;
  567. double dfDstMin;
  568. double dfDstMax;
  569. double dfExponent;
  570. int nColorTableComponent;
  571. CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
  572. int nReqXSize, int nReqYSize,
  573. void *pData, int nOutXSize, int nOutYSize,
  574. GDALDataType eBufType,
  575. GSpacing nPixelSpace, GSpacing nLineSpace,
  576. GDALRasterIOExtraArg* psExtraArg );
  577. public:
  578. VRTComplexSource();
  579. virtual ~VRTComplexSource();
  580. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  581. void *pData, int nBufXSize, int nBufYSize,
  582. GDALDataType eBufType,
  583. GSpacing nPixelSpace, GSpacing nLineSpace,
  584. GDALRasterIOExtraArg* psExtraArg );
  585. virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
  586. virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
  587. virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
  588. virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
  589. int bApproxOK,
  590. double *pdfMin, double *pdfMax,
  591. double *pdfMean, double *pdfStdDev,
  592. GDALProgressFunc pfnProgress, void *pProgressData );
  593. virtual CPLErr GetHistogram( int nXSize, int nYSize,
  594. double dfMin, double dfMax,
  595. int nBuckets, GUIntBig * panHistogram,
  596. int bIncludeOutOfRange, int bApproxOK,
  597. GDALProgressFunc pfnProgress, void *pProgressData );
  598. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  599. virtual CPLErr XMLInit( CPLXMLNode *, const char * );
  600. virtual const char* GetType() { return "ComplexSource"; }
  601. double LookupValue( double dfInput );
  602. void SetLinearScaling(double dfOffset, double dfScale);
  603. void SetPowerScaling(double dfExponent,
  604. double dfSrcMin,
  605. double dfSrcMax,
  606. double dfDstMin,
  607. double dfDstMax);
  608. void SetColorTableComponent(int nComponent);
  609. double *padfLUTInputs;
  610. double *padfLUTOutputs;
  611. int nLUTItemCount;
  612. };
  613. /************************************************************************/
  614. /* VRTFilteredSource */
  615. /************************************************************************/
  616. class VRTFilteredSource : public VRTComplexSource
  617. {
  618. private:
  619. int IsTypeSupported( GDALDataType eType );
  620. protected:
  621. int nSupportedTypesCount;
  622. GDALDataType aeSupportedTypes[20];
  623. int nExtraEdgePixels;
  624. public:
  625. VRTFilteredSource();
  626. virtual ~VRTFilteredSource();
  627. void SetExtraEdgePixels( int );
  628. void SetFilteringDataTypesSupported( int, GDALDataType * );
  629. virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
  630. GByte *pabySrcData, GByte *pabyDstData ) = 0;
  631. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  632. void *pData, int nBufXSize, int nBufYSize,
  633. GDALDataType eBufType,
  634. GSpacing nPixelSpace, GSpacing nLineSpace,
  635. GDALRasterIOExtraArg* psExtraArg );
  636. };
  637. /************************************************************************/
  638. /* VRTKernelFilteredSource */
  639. /************************************************************************/
  640. class VRTKernelFilteredSource : public VRTFilteredSource
  641. {
  642. protected:
  643. int nKernelSize;
  644. double *padfKernelCoefs;
  645. int bNormalized;
  646. public:
  647. VRTKernelFilteredSource();
  648. virtual ~VRTKernelFilteredSource();
  649. virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
  650. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  651. virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
  652. GByte *pabySrcData, GByte *pabyDstData );
  653. CPLErr SetKernel( int nKernelSize, double *padfCoefs );
  654. void SetNormalized( int );
  655. };
  656. /************************************************************************/
  657. /* VRTAverageFilteredSource */
  658. /************************************************************************/
  659. class VRTAverageFilteredSource : public VRTKernelFilteredSource
  660. {
  661. public:
  662. VRTAverageFilteredSource( int nKernelSize );
  663. virtual ~VRTAverageFilteredSource();
  664. virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
  665. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  666. };
  667. /************************************************************************/
  668. /* VRTFuncSource */
  669. /************************************************************************/
  670. class VRTFuncSource : public VRTSource
  671. {
  672. public:
  673. VRTFuncSource();
  674. virtual ~VRTFuncSource();
  675. virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
  676. virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
  677. virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
  678. void *pData, int nBufXSize, int nBufYSize,
  679. GDALDataType eBufType,
  680. GSpacing nPixelSpace, GSpacing nLineSpace,
  681. GDALRasterIOExtraArg* psExtraArg );
  682. virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
  683. virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
  684. virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
  685. virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
  686. int bApproxOK,
  687. double *pdfMin, double *pdfMax,
  688. double *pdfMean, double *pdfStdDev,
  689. GDALProgressFunc pfnProgress, void *pProgressData );
  690. virtual CPLErr GetHistogram( int nXSize, int nYSize,
  691. double dfMin, double dfMax,
  692. int nBuckets, GUIntBig * panHistogram,
  693. int bIncludeOutOfRange, int bApproxOK,
  694. GDALProgressFunc pfnProgress, void *pProgressData );
  695. VRTImageReadFunc pfnReadFunc;
  696. void *pCBData;
  697. GDALDataType eType;
  698. float fNoDataValue;
  699. };
  700. #endif /* ndef VIRTUALDATASET_H_INCLUDED */