gdal_proxy.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /******************************************************************************
  2. * $Id: gdal_proxy.h 28899 2015-04-14 09:27:00Z 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. #include "gdal.h"
  32. #ifdef __cplusplus
  33. #include "gdal_priv.h"
  34. #include "cpl_hash_set.h"
  35. /* ******************************************************************** */
  36. /* GDALProxyDataset */
  37. /* ******************************************************************** */
  38. class CPL_DLL GDALProxyDataset : public GDALDataset
  39. {
  40. protected:
  41. virtual GDALDataset *RefUnderlyingDataset() = 0;
  42. virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
  43. virtual CPLErr IBuildOverviews( const char *, int, int *,
  44. int, int *, GDALProgressFunc, void * );
  45. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  46. void *, int, int, GDALDataType,
  47. int, int *, GSpacing, GSpacing, GSpacing,
  48. GDALRasterIOExtraArg* psExtraArg );
  49. public:
  50. virtual char **GetMetadataDomainList();
  51. virtual char **GetMetadata( const char * pszDomain );
  52. virtual CPLErr SetMetadata( char ** papszMetadata,
  53. const char * pszDomain );
  54. virtual const char *GetMetadataItem( const char * pszName,
  55. const char * pszDomain );
  56. virtual CPLErr SetMetadataItem( const char * pszName,
  57. const char * pszValue,
  58. const char * pszDomain );
  59. virtual void FlushCache(void);
  60. virtual const char *GetProjectionRef(void);
  61. virtual CPLErr SetProjection( const char * );
  62. virtual CPLErr GetGeoTransform( double * );
  63. virtual CPLErr SetGeoTransform( double * );
  64. virtual void *GetInternalHandle( const char * );
  65. virtual GDALDriver *GetDriver(void);
  66. virtual char **GetFileList(void);
  67. virtual int GetGCPCount();
  68. virtual const char *GetGCPProjection();
  69. virtual const GDAL_GCP *GetGCPs();
  70. virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
  71. const char *pszGCPProjection );
  72. virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
  73. int nBufXSize, int nBufYSize,
  74. GDALDataType eDT,
  75. int nBandCount, int *panBandList,
  76. char **papszOptions );
  77. virtual CPLErr CreateMaskBand( int nFlags );
  78. };
  79. /* ******************************************************************** */
  80. /* GDALProxyRasterBand */
  81. /* ******************************************************************** */
  82. class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
  83. {
  84. protected:
  85. virtual GDALRasterBand* RefUnderlyingRasterBand() = 0;
  86. virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
  87. virtual CPLErr IReadBlock( int, int, void * );
  88. virtual CPLErr IWriteBlock( int, int, void * );
  89. virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
  90. void *, int, int, GDALDataType,
  91. GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
  92. public:
  93. virtual char **GetMetadataDomainList();
  94. virtual char **GetMetadata( const char * pszDomain );
  95. virtual CPLErr SetMetadata( char ** papszMetadata,
  96. const char * pszDomain );
  97. virtual const char *GetMetadataItem( const char * pszName,
  98. const char * pszDomain );
  99. virtual CPLErr SetMetadataItem( const char * pszName,
  100. const char * pszValue,
  101. const char * pszDomain );
  102. virtual CPLErr FlushCache();
  103. virtual char **GetCategoryNames();
  104. virtual double GetNoDataValue( int *pbSuccess = NULL );
  105. virtual double GetMinimum( int *pbSuccess = NULL );
  106. virtual double GetMaximum(int *pbSuccess = NULL );
  107. virtual double GetOffset( int *pbSuccess = NULL );
  108. virtual double GetScale( int *pbSuccess = NULL );
  109. virtual const char *GetUnitType();
  110. virtual GDALColorInterp GetColorInterpretation();
  111. virtual GDALColorTable *GetColorTable();
  112. virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
  113. virtual CPLErr SetCategoryNames( char ** );
  114. virtual CPLErr SetNoDataValue( double );
  115. virtual CPLErr SetColorTable( GDALColorTable * );
  116. virtual CPLErr SetColorInterpretation( GDALColorInterp );
  117. virtual CPLErr SetOffset( double );
  118. virtual CPLErr SetScale( double );
  119. virtual CPLErr SetUnitType( const char * );
  120. virtual CPLErr GetStatistics( int bApproxOK, int bForce,
  121. double *pdfMin, double *pdfMax,
  122. double *pdfMean, double *padfStdDev );
  123. virtual CPLErr ComputeStatistics( int bApproxOK,
  124. double *pdfMin, double *pdfMax,
  125. double *pdfMean, double *pdfStdDev,
  126. GDALProgressFunc, void *pProgressData );
  127. virtual CPLErr SetStatistics( double dfMin, double dfMax,
  128. double dfMean, double dfStdDev );
  129. virtual CPLErr ComputeRasterMinMax( int, double* );
  130. virtual int HasArbitraryOverviews();
  131. virtual int GetOverviewCount();
  132. virtual GDALRasterBand *GetOverview(int);
  133. virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig );
  134. virtual CPLErr BuildOverviews( const char *, int, int *,
  135. GDALProgressFunc, void * );
  136. virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
  137. int nBufXSize, int nBufYSize,
  138. GDALDataType eDT, char **papszOptions );
  139. virtual CPLErr GetHistogram( double dfMin, double dfMax,
  140. int nBuckets, GUIntBig * panHistogram,
  141. int bIncludeOutOfRange, int bApproxOK,
  142. GDALProgressFunc, void *pProgressData );
  143. virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
  144. int *pnBuckets, GUIntBig ** ppanHistogram,
  145. int bForce,
  146. GDALProgressFunc, void *pProgressData);
  147. virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
  148. int nBuckets, GUIntBig *panHistogram );
  149. virtual GDALRasterAttributeTable *GetDefaultRAT();
  150. virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
  151. virtual GDALRasterBand *GetMaskBand();
  152. virtual int GetMaskFlags();
  153. virtual CPLErr CreateMaskBand( int nFlags );
  154. virtual CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
  155. int *pnPixelSpace,
  156. GIntBig *pnLineSpace,
  157. char **papszOptions );
  158. };
  159. /* ******************************************************************** */
  160. /* GDALProxyPoolDataset */
  161. /* ******************************************************************** */
  162. typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
  163. class GDALProxyPoolRasterBand;
  164. class CPL_DLL GDALProxyPoolDataset : public GDALProxyDataset
  165. {
  166. private:
  167. GIntBig responsiblePID;
  168. char *pszProjectionRef;
  169. double adfGeoTransform[6];
  170. int bHasSrcProjection;
  171. int bHasSrcGeoTransform;
  172. char *pszGCPProjection;
  173. int nGCPCount;
  174. GDAL_GCP *pasGCPList;
  175. CPLHashSet *metadataSet;
  176. CPLHashSet *metadataItemSet;
  177. GDALProxyPoolCacheEntry* cacheEntry;
  178. protected:
  179. virtual GDALDataset *RefUnderlyingDataset();
  180. virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
  181. friend class GDALProxyPoolRasterBand;
  182. public:
  183. GDALProxyPoolDataset(const char* pszSourceDatasetDescription,
  184. int nRasterXSize, int nRasterYSize,
  185. GDALAccess eAccess = GA_ReadOnly,
  186. int bShared = FALSE,
  187. const char * pszProjectionRef = NULL,
  188. double * padfGeoTransform = NULL);
  189. ~GDALProxyPoolDataset();
  190. void SetOpenOptions(char** papszOpenOptions);
  191. void AddSrcBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
  192. virtual const char *GetProjectionRef(void);
  193. virtual CPLErr SetProjection( const char * );
  194. virtual CPLErr GetGeoTransform( double * );
  195. virtual CPLErr SetGeoTransform( double * );
  196. /* Special behaviour for the following methods : they return a pointer */
  197. /* data type, that must be cached by the proxy, so it doesn't become invalid */
  198. /* when the underlying object get closed */
  199. virtual char **GetMetadata( const char * pszDomain );
  200. virtual const char *GetMetadataItem( const char * pszName,
  201. const char * pszDomain );
  202. virtual void *GetInternalHandle( const char * pszRequest );
  203. virtual const char *GetGCPProjection();
  204. virtual const GDAL_GCP *GetGCPs();
  205. };
  206. /* ******************************************************************** */
  207. /* GDALProxyPoolRasterBand */
  208. /* ******************************************************************** */
  209. class GDALProxyPoolOverviewRasterBand;
  210. class GDALProxyPoolMaskBand;
  211. class CPL_DLL GDALProxyPoolRasterBand : public GDALProxyRasterBand
  212. {
  213. private:
  214. CPLHashSet *metadataSet;
  215. CPLHashSet *metadataItemSet;
  216. char *pszUnitType;
  217. char **papszCategoryNames;
  218. GDALColorTable *poColorTable;
  219. int nSizeProxyOverviewRasterBand;
  220. GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand;
  221. GDALProxyPoolMaskBand *poProxyMaskBand;
  222. void Init();
  223. protected:
  224. virtual GDALRasterBand* RefUnderlyingRasterBand();
  225. virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
  226. friend class GDALProxyPoolOverviewRasterBand;
  227. friend class GDALProxyPoolMaskBand;
  228. public:
  229. GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS, int nBand,
  230. GDALDataType eDataType,
  231. int nBlockXSize, int nBlockYSize);
  232. GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS,
  233. GDALRasterBand* poUnderlyingRasterBand);
  234. ~GDALProxyPoolRasterBand();
  235. void AddSrcMaskBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
  236. /* Special behaviour for the following methods : they return a pointer */
  237. /* data type, that must be cached by the proxy, so it doesn't become invalid */
  238. /* when the underlying object get closed */
  239. virtual char **GetMetadata( const char * pszDomain );
  240. virtual const char *GetMetadataItem( const char * pszName,
  241. const char * pszDomain );
  242. virtual char **GetCategoryNames();
  243. virtual const char *GetUnitType();
  244. virtual GDALColorTable *GetColorTable();
  245. virtual GDALRasterBand *GetOverview(int);
  246. virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig nDesiredSamples); // TODO
  247. virtual GDALRasterBand *GetMaskBand();
  248. };
  249. /* ******************************************************************** */
  250. /* GDALProxyPoolOverviewRasterBand */
  251. /* ******************************************************************** */
  252. class GDALProxyPoolOverviewRasterBand : public GDALProxyPoolRasterBand
  253. {
  254. private:
  255. GDALProxyPoolRasterBand *poMainBand;
  256. int nOverviewBand;
  257. GDALRasterBand *poUnderlyingMainRasterBand;
  258. int nRefCountUnderlyingMainRasterBand;
  259. protected:
  260. virtual GDALRasterBand* RefUnderlyingRasterBand();
  261. virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
  262. public:
  263. GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset* poDS,
  264. GDALRasterBand* poUnderlyingOverviewBand,
  265. GDALProxyPoolRasterBand* poMainBand,
  266. int nOverviewBand);
  267. ~GDALProxyPoolOverviewRasterBand();
  268. };
  269. /* ******************************************************************** */
  270. /* GDALProxyPoolMaskBand */
  271. /* ******************************************************************** */
  272. class GDALProxyPoolMaskBand : public GDALProxyPoolRasterBand
  273. {
  274. private:
  275. GDALProxyPoolRasterBand *poMainBand;
  276. GDALRasterBand *poUnderlyingMainRasterBand;
  277. int nRefCountUnderlyingMainRasterBand;
  278. protected:
  279. virtual GDALRasterBand* RefUnderlyingRasterBand();
  280. virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
  281. public:
  282. GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
  283. GDALRasterBand* poUnderlyingMaskBand,
  284. GDALProxyPoolRasterBand* poMainBand);
  285. GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
  286. GDALProxyPoolRasterBand* poMainBand,
  287. GDALDataType eDataType,
  288. int nBlockXSize, int nBlockYSize);
  289. ~GDALProxyPoolMaskBand();
  290. };
  291. #endif
  292. /* ******************************************************************** */
  293. /* C types and methods declarations */
  294. /* ******************************************************************** */
  295. CPL_C_START
  296. typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
  297. GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(const char* pszSourceDatasetDescription,
  298. int nRasterXSize, int nRasterYSize,
  299. GDALAccess eAccess, int bShared,
  300. const char * pszProjectionRef,
  301. double * padfGeoTransform);
  302. void CPL_DLL GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
  303. void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription( GDALProxyPoolDatasetH hProxyPoolDataset,
  304. GDALDataType eDataType,
  305. int nBlockXSize, int nBlockYSize);
  306. CPL_C_END
  307. #endif /* GDAL_PROXY_H_INCLUDED */