gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
18KB

  1. /******************************************************************************
  2. * $Id: gdal_proxy.h 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $
  3. *
  4. * Project: GDAL Core
  5. * Purpose: GDAL Core C++/Private declarations
  6. * Author: Even Rouault <even dot rouault at mines dash paris dot org>
  7. *
  8. ******************************************************************************
  9. * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included
  19. * in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  22. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS IN THE SOFTWARE.
  28. ****************************************************************************/
  29. #ifndef GDAL_PROXY_H_INCLUDED
  30. #define GDAL_PROXY_H_INCLUDED
  31. #ifndef DOXYGEN_SKIP
  32. #include "gdal.h"
  33. #ifdef __cplusplus
  34. #include "gdal_priv.h"
  35. #include "cpl_hash_set.h"
  36. /* ******************************************************************** */
  37. /* GDALProxyDataset */
  38. /* ******************************************************************** */
  39. class CPL_DLL GDALProxyDataset : public GDALDataset
  40. {
  41. protected:
  42. GDALProxyDataset() {}
  43. virtual GDALDataset *RefUnderlyingDataset() const = 0;
  44. virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset) const;
  45. CPLErr IBuildOverviews( const char *, int, int *,
  46. int, int *, GDALProgressFunc, void * ) override;
  47. CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  48. void *, int, int, GDALDataType,
  49. int, int *, GSpacing, GSpacing, GSpacing,
  50. GDALRasterIOExtraArg* psExtraArg ) override;
  51. public:
  52. char **GetMetadataDomainList() override;
  53. char **GetMetadata( const char * pszDomain ) override;
  54. CPLErr SetMetadata( char ** papszMetadata,
  55. const char * pszDomain ) override;
  56. const char *GetMetadataItem( const char * pszName,
  57. const char * pszDomain ) override;
  58. CPLErr SetMetadataItem( const char * pszName,
  59. const char * pszValue,
  60. const char * pszDomain ) override;
  61. void FlushCache() override;
  62. const OGRSpatialReference* GetSpatialRef() const override;
  63. CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
  64. CPLErr GetGeoTransform( double * ) override;
  65. CPLErr SetGeoTransform( double * ) override;
  66. void *GetInternalHandle( const char * ) override;
  67. GDALDriver *GetDriver() override;
  68. char **GetFileList() override;
  69. int GetGCPCount() override;
  70. const OGRSpatialReference* GetGCPSpatialRef() const override;
  71. const GDAL_GCP *GetGCPs() override;
  72. CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
  73. const OGRSpatialReference * poGCP_SRS ) override;
  74. CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
  75. int nBufXSize, int nBufYSize,
  76. GDALDataType eDT,
  77. int nBandCount, int *panBandList,
  78. char **papszOptions ) override;
  79. CPLErr CreateMaskBand( int nFlags ) override;
  80. protected:
  81. const char *_GetProjectionRef(void) override;
  82. CPLErr _SetProjection( const char * ) override;
  83. const char *_GetGCPProjection() override;
  84. CPLErr _SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
  85. const char *pszGCPProjection ) override;
  86. private:
  87. CPL_DISALLOW_COPY_ASSIGN(GDALProxyDataset)
  88. };
  89. /* ******************************************************************** */
  90. /* GDALProxyRasterBand */
  91. /* ******************************************************************** */
  92. class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
  93. {
  94. protected:
  95. GDALProxyRasterBand() {}
  96. virtual GDALRasterBand* RefUnderlyingRasterBand() = 0;
  97. virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
  98. CPLErr IReadBlock( int, int, void * ) override;
  99. CPLErr IWriteBlock( int, int, void * ) override;
  100. CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  101. void *, int, int, GDALDataType,
  102. GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg ) override;
  103. public:
  104. char **GetMetadataDomainList() override;
  105. char **GetMetadata( const char * pszDomain ) override;
  106. CPLErr SetMetadata( char ** papszMetadata,
  107. const char * pszDomain ) override;
  108. const char *GetMetadataItem( const char * pszName,
  109. const char * pszDomain ) override;
  110. CPLErr SetMetadataItem( const char * pszName,
  111. const char * pszValue,
  112. const char * pszDomain ) override;
  113. CPLErr FlushCache() override;
  114. char **GetCategoryNames() override;
  115. double GetNoDataValue( int *pbSuccess = nullptr ) override;
  116. double GetMinimum( int *pbSuccess = nullptr ) override;
  117. double GetMaximum(int *pbSuccess = nullptr ) override;
  118. double GetOffset( int *pbSuccess = nullptr ) override;
  119. double GetScale( int *pbSuccess = nullptr ) override;
  120. const char *GetUnitType() override;
  121. GDALColorInterp GetColorInterpretation() override;
  122. GDALColorTable *GetColorTable() override;
  123. CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0) override;
  124. CPLErr SetCategoryNames( char ** ) override;
  125. CPLErr SetNoDataValue( double ) override;
  126. CPLErr DeleteNoDataValue() override;
  127. CPLErr SetColorTable( GDALColorTable * ) override;
  128. CPLErr SetColorInterpretation( GDALColorInterp ) override;
  129. CPLErr SetOffset( double ) override;
  130. CPLErr SetScale( double ) override;
  131. CPLErr SetUnitType( const char * ) override;
  132. CPLErr GetStatistics( int bApproxOK, int bForce,
  133. double *pdfMin, double *pdfMax,
  134. double *pdfMean, double *padfStdDev ) override;
  135. CPLErr ComputeStatistics( int bApproxOK,
  136. double *pdfMin, double *pdfMax,
  137. double *pdfMean, double *pdfStdDev,
  138. GDALProgressFunc, void *pProgressData ) override;
  139. CPLErr SetStatistics( double dfMin, double dfMax,
  140. double dfMean, double dfStdDev ) override;
  141. CPLErr ComputeRasterMinMax( int, double* ) override;
  142. int HasArbitraryOverviews() override;
  143. int GetOverviewCount() override;
  144. GDALRasterBand *GetOverview( int ) override;
  145. GDALRasterBand *GetRasterSampleOverview( GUIntBig ) override;
  146. CPLErr BuildOverviews( const char *, int, int *,
  147. GDALProgressFunc, void * ) override;
  148. CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
  149. int nBufXSize, int nBufYSize,
  150. GDALDataType eDT, char **papszOptions ) override;
  151. CPLErr GetHistogram( double dfMin, double dfMax,
  152. int nBuckets, GUIntBig * panHistogram,
  153. int bIncludeOutOfRange, int bApproxOK,
  154. GDALProgressFunc, void *pProgressData ) override;
  155. CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
  156. int *pnBuckets, GUIntBig ** ppanHistogram,
  157. int bForce,
  158. GDALProgressFunc, void *pProgressData) override;
  159. CPLErr SetDefaultHistogram( double dfMin, double dfMax,
  160. int nBuckets, GUIntBig *panHistogram ) override;
  161. GDALRasterAttributeTable *GetDefaultRAT() override;
  162. CPLErr SetDefaultRAT( const GDALRasterAttributeTable * ) override;
  163. GDALRasterBand *GetMaskBand() override;
  164. int GetMaskFlags() override;
  165. CPLErr CreateMaskBand( int nFlags ) override;
  166. CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
  167. int *pnPixelSpace,
  168. GIntBig *pnLineSpace,
  169. char **papszOptions ) override;
  170. private:
  171. CPL_DISALLOW_COPY_ASSIGN(GDALProxyRasterBand)
  172. };
  173. /* ******************************************************************** */
  174. /* GDALProxyPoolDataset */
  175. /* ******************************************************************** */
  176. typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
  177. class GDALProxyPoolRasterBand;
  178. class CPL_DLL GDALProxyPoolDataset : public GDALProxyDataset
  179. {
  180. private:
  181. GIntBig responsiblePID = -1;
  182. mutable char *pszProjectionRef = nullptr;
  183. mutable OGRSpatialReference* m_poSRS = nullptr;
  184. mutable OGRSpatialReference* m_poGCPSRS = nullptr;
  185. double adfGeoTransform[6]{0,1,0,0,0,1};
  186. bool bHasSrcProjection = false;
  187. bool m_bHasSrcSRS = false;
  188. bool bHasSrcGeoTransform = false;
  189. char *pszGCPProjection = nullptr;
  190. int nGCPCount = 0;
  191. GDAL_GCP *pasGCPList = nullptr;
  192. CPLHashSet *metadataSet = nullptr;
  193. CPLHashSet *metadataItemSet = nullptr;
  194. mutable GDALProxyPoolCacheEntry* cacheEntry = nullptr;
  195. char *m_pszOwner = nullptr;
  196. GDALDataset *RefUnderlyingDataset(bool bForceOpen) const;
  197. protected:
  198. GDALDataset *RefUnderlyingDataset() const override;
  199. void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset) const override;
  200. friend class GDALProxyPoolRasterBand;
  201. public:
  202. GDALProxyPoolDataset( const char* pszSourceDatasetDescription,
  203. int nRasterXSize, int nRasterYSize,
  204. GDALAccess eAccess = GA_ReadOnly,
  205. int bShared = FALSE,
  206. const char * pszProjectionRef = nullptr,
  207. double * padfGeoTransform = nullptr,
  208. const char* pszOwner = nullptr );
  209. ~GDALProxyPoolDataset() override;
  210. void SetOpenOptions( char** papszOpenOptions );
  211. void AddSrcBandDescription( GDALDataType eDataType, int nBlockXSize,
  212. int nBlockYSize );
  213. // Used by VRT SimpleSource to add a single GDALProxyPoolRasterBand while
  214. // keeping all other bands initialized to a nullptr. This is under the assumption,
  215. // VRT SimpleSource will not have to access any other bands than the one added.
  216. void AddSrcBand(int nBand, GDALDataType eDataType, int nBlockXSize,
  217. int nBlockYSize );
  218. void FlushCache() override;
  219. const OGRSpatialReference* GetSpatialRef() const override;
  220. CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
  221. const char *_GetProjectionRef() override;
  222. CPLErr _SetProjection( const char * ) override;
  223. CPLErr GetGeoTransform( double * ) override;
  224. CPLErr SetGeoTransform( double * ) override;
  225. // Special behaviour for the following methods : they return a pointer
  226. // data type, that must be cached by the proxy, so it doesn't become invalid
  227. // when the underlying object get closed.
  228. char **GetMetadata( const char * pszDomain ) override;
  229. const char *GetMetadataItem( const char * pszName,
  230. const char * pszDomain ) override;
  231. void *GetInternalHandle( const char * pszRequest ) override;
  232. const char *_GetGCPProjection() override;
  233. const OGRSpatialReference* GetGCPSpatialRef() const override;
  234. const GDAL_GCP *GetGCPs() override;
  235. private:
  236. CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolDataset)
  237. };
  238. /* ******************************************************************** */
  239. /* GDALProxyPoolRasterBand */
  240. /* ******************************************************************** */
  241. class GDALProxyPoolOverviewRasterBand;
  242. class GDALProxyPoolMaskBand;
  243. class CPL_DLL GDALProxyPoolRasterBand : public GDALProxyRasterBand
  244. {
  245. private:
  246. CPLHashSet *metadataSet = nullptr;
  247. CPLHashSet *metadataItemSet = nullptr;
  248. char *pszUnitType = nullptr;
  249. char **papszCategoryNames = nullptr;
  250. GDALColorTable *poColorTable = nullptr;
  251. int nSizeProxyOverviewRasterBand = 0;
  252. GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand = nullptr;
  253. GDALProxyPoolMaskBand *poProxyMaskBand = nullptr;
  254. GDALRasterBand* RefUnderlyingRasterBand( bool bForceOpen );
  255. protected:
  256. GDALRasterBand* RefUnderlyingRasterBand() override;
  257. void UnrefUnderlyingRasterBand( GDALRasterBand* poUnderlyingRasterBand )
  258. override;
  259. friend class GDALProxyPoolOverviewRasterBand;
  260. friend class GDALProxyPoolMaskBand;
  261. public:
  262. GDALProxyPoolRasterBand( GDALProxyPoolDataset* poDS, int nBand,
  263. GDALDataType eDataType,
  264. int nBlockXSize, int nBlockYSize );
  265. GDALProxyPoolRasterBand( GDALProxyPoolDataset* poDS,
  266. GDALRasterBand* poUnderlyingRasterBand );
  267. ~GDALProxyPoolRasterBand() override;
  268. void AddSrcMaskBandDescription( GDALDataType eDataType, int nBlockXSize,
  269. int nBlockYSize );
  270. // Special behaviour for the following methods : they return a pointer
  271. // data type, that must be cached by the proxy, so it doesn't become invalid
  272. // when the underlying object get closed.
  273. char **GetMetadata( const char * pszDomain ) override;
  274. const char *GetMetadataItem( const char * pszName,
  275. const char * pszDomain ) override;
  276. char **GetCategoryNames() override;
  277. const char *GetUnitType() override;
  278. GDALColorTable *GetColorTable() override;
  279. GDALRasterBand *GetOverview( int ) override;
  280. GDALRasterBand *GetRasterSampleOverview( GUIntBig nDesiredSamples ) override; // TODO
  281. GDALRasterBand *GetMaskBand() override;
  282. CPLErr FlushCache() override;
  283. private:
  284. CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolRasterBand)
  285. };
  286. /* ******************************************************************** */
  287. /* GDALProxyPoolOverviewRasterBand */
  288. /* ******************************************************************** */
  289. class GDALProxyPoolOverviewRasterBand : public GDALProxyPoolRasterBand
  290. {
  291. private:
  292. GDALProxyPoolRasterBand *poMainBand = nullptr;
  293. int nOverviewBand = 0;
  294. GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
  295. int nRefCountUnderlyingMainRasterBand = 0;
  296. CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolOverviewRasterBand)
  297. protected:
  298. GDALRasterBand* RefUnderlyingRasterBand() override;
  299. void UnrefUnderlyingRasterBand( GDALRasterBand* poUnderlyingRasterBand )
  300. override;
  301. public:
  302. GDALProxyPoolOverviewRasterBand( GDALProxyPoolDataset* poDS,
  303. GDALRasterBand* poUnderlyingOverviewBand,
  304. GDALProxyPoolRasterBand* poMainBand,
  305. int nOverviewBand );
  306. ~GDALProxyPoolOverviewRasterBand() override;
  307. };
  308. /* ******************************************************************** */
  309. /* GDALProxyPoolMaskBand */
  310. /* ******************************************************************** */
  311. class GDALProxyPoolMaskBand : public GDALProxyPoolRasterBand
  312. {
  313. private:
  314. GDALProxyPoolRasterBand *poMainBand = nullptr;
  315. GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
  316. int nRefCountUnderlyingMainRasterBand = 0;
  317. CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolMaskBand)
  318. protected:
  319. GDALRasterBand* RefUnderlyingRasterBand() override;
  320. void UnrefUnderlyingRasterBand( GDALRasterBand* poUnderlyingRasterBand )
  321. override;
  322. public:
  323. GDALProxyPoolMaskBand( GDALProxyPoolDataset* poDS,
  324. GDALRasterBand* poUnderlyingMaskBand,
  325. GDALProxyPoolRasterBand* poMainBand );
  326. GDALProxyPoolMaskBand( GDALProxyPoolDataset* poDS,
  327. GDALProxyPoolRasterBand* poMainBand,
  328. GDALDataType eDataType,
  329. int nBlockXSize, int nBlockYSize );
  330. ~GDALProxyPoolMaskBand() override;
  331. };
  332. #endif
  333. /* ******************************************************************** */
  334. /* C types and methods declarations */
  335. /* ******************************************************************** */
  336. CPL_C_START
  337. typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
  338. GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(const char* pszSourceDatasetDescription,
  339. int nRasterXSize, int nRasterYSize,
  340. GDALAccess eAccess, int bShared,
  341. const char * pszProjectionRef,
  342. double * padfGeoTransform);
  343. void CPL_DLL GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
  344. void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription( GDALProxyPoolDatasetH hProxyPoolDataset,
  345. GDALDataType eDataType,
  346. int nBlockXSize, int nBlockYSize);
  347. CPL_C_END
  348. #endif /* #ifndef DOXYGEN_SKIP */
  349. #endif /* GDAL_PROXY_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1