GDAL
gdal_proxy.h
1/******************************************************************************
2 * $Id$
3 *
4 * Project: GDAL Core
5 * Purpose: GDAL Core C++/Private declarations
6 * Author: Even Rouault <even dot rouault at spatialys.com>
7 *
8 ******************************************************************************
9 * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
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
30#ifndef GDAL_PROXY_H_INCLUDED
31#define GDAL_PROXY_H_INCLUDED
32
33#ifndef DOXYGEN_SKIP
34
35#include "gdal.h"
36
37#ifdef __cplusplus
38
39#include "gdal_priv.h"
40#include "cpl_hash_set.h"
41
42/* ******************************************************************** */
43/* GDALProxyDataset */
44/* ******************************************************************** */
45
46class CPL_DLL GDALProxyDataset : public GDALDataset
47{
48 protected:
49 GDALProxyDataset()
50 {
51 }
52
53 virtual GDALDataset *RefUnderlyingDataset() const = 0;
54 virtual void UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const;
55
56 CPLErr IBuildOverviews(const char *, int, const int *, int, const int *,
57 GDALProgressFunc, void *,
58 CSLConstList papszOptions) override;
59 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
61 GDALRasterIOExtraArg *psExtraArg) override;
62
63 public:
64 char **GetMetadataDomainList() override;
65 char **GetMetadata(const char *pszDomain) override;
66 CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
67 const char *GetMetadataItem(const char *pszName,
68 const char *pszDomain) override;
69 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
70 const char *pszDomain) override;
71
72 void FlushCache(bool bAtClosing) override;
73
74 const OGRSpatialReference *GetSpatialRef() const override;
75 CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
76
77 CPLErr GetGeoTransform(double *) override;
78 CPLErr SetGeoTransform(double *) override;
79
80 void *GetInternalHandle(const char *) override;
81 GDALDriver *GetDriver() override;
82 char **GetFileList() override;
83
84 int GetGCPCount() override;
85 const OGRSpatialReference *GetGCPSpatialRef() const override;
86 const GDAL_GCP *GetGCPs() override;
87 CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
88 const OGRSpatialReference *poGCP_SRS) override;
89
90 CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
91 int nBufXSize, int nBufYSize, GDALDataType eDT,
92 int nBandCount, int *panBandList,
93 char **papszOptions) override;
94
95 CPLErr CreateMaskBand(int nFlags) override;
96
97 private:
98 CPL_DISALLOW_COPY_ASSIGN(GDALProxyDataset)
99};
100
101/* ******************************************************************** */
102/* GDALProxyRasterBand */
103/* ******************************************************************** */
104
105class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
106{
107 protected:
108 GDALProxyRasterBand()
109 {
110 }
111
112 virtual GDALRasterBand *RefUnderlyingRasterBand() const = 0;
113 virtual void
114 UnrefUnderlyingRasterBand(GDALRasterBand *poUnderlyingRasterBand) const;
115
116 CPLErr IReadBlock(int, int, void *) override;
117 CPLErr IWriteBlock(int, int, void *) override;
118 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
120 GDALRasterIOExtraArg *psExtraArg) override;
121
122 public:
123 char **GetMetadataDomainList() override;
124 char **GetMetadata(const char *pszDomain) override;
125 CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
126 const char *GetMetadataItem(const char *pszName,
127 const char *pszDomain) override;
128 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
129 const char *pszDomain) override;
130 CPLErr FlushCache(bool bAtClosing) override;
131 char **GetCategoryNames() override;
132 double GetNoDataValue(int *pbSuccess = nullptr) override;
133 double GetMinimum(int *pbSuccess = nullptr) override;
134 double GetMaximum(int *pbSuccess = nullptr) override;
135 double GetOffset(int *pbSuccess = nullptr) override;
136 double GetScale(int *pbSuccess = nullptr) override;
137 const char *GetUnitType() override;
138 GDALColorInterp GetColorInterpretation() override;
139 GDALColorTable *GetColorTable() override;
140 CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0) override;
141
142 CPLErr SetCategoryNames(char **) override;
143 CPLErr SetNoDataValue(double) override;
144 CPLErr DeleteNoDataValue() override;
145 CPLErr SetColorTable(GDALColorTable *) override;
146 CPLErr SetColorInterpretation(GDALColorInterp) override;
147 CPLErr SetOffset(double) override;
148 CPLErr SetScale(double) override;
149 CPLErr SetUnitType(const char *) override;
150
151 CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
152 double *pdfMax, double *pdfMean,
153 double *padfStdDev) override;
154 CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
155 double *pdfMean, double *pdfStdDev,
156 GDALProgressFunc, void *pProgressData) override;
157 CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
158 double dfStdDev) override;
159 CPLErr ComputeRasterMinMax(int, double *) override;
160
161 int HasArbitraryOverviews() override;
162 int GetOverviewCount() override;
163 GDALRasterBand *GetOverview(int) override;
164 GDALRasterBand *GetRasterSampleOverview(GUIntBig) override;
165 CPLErr BuildOverviews(const char *, int, const int *, GDALProgressFunc,
166 void *, CSLConstList papszOptions) override;
167
168 CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
169 int nBufXSize, int nBufYSize, GDALDataType eDT,
170 char **papszOptions) override;
171
172 CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
173 GUIntBig *panHistogram, int bIncludeOutOfRange,
174 int bApproxOK, GDALProgressFunc,
175 void *pProgressData) override;
176
177 CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
178 GUIntBig **ppanHistogram, int bForce,
179 GDALProgressFunc, void *pProgressData) override;
180 CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
181 GUIntBig *panHistogram) override;
182
183 GDALRasterAttributeTable *GetDefaultRAT() override;
184 CPLErr SetDefaultRAT(const GDALRasterAttributeTable *) override;
185
186 GDALRasterBand *GetMaskBand() override;
187 int GetMaskFlags() override;
188 CPLErr CreateMaskBand(int nFlags) override;
189 bool IsMaskBand() const override;
190 GDALMaskValueRange GetMaskValueRange() const override;
191
192 CPLVirtualMem *GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
193 GIntBig *pnLineSpace,
194 char **papszOptions) override;
195
196 private:
197 CPL_DISALLOW_COPY_ASSIGN(GDALProxyRasterBand)
198};
199
200/* ******************************************************************** */
201/* GDALProxyPoolDataset */
202/* ******************************************************************** */
203
204typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
205class GDALProxyPoolRasterBand;
206
207class CPL_DLL GDALProxyPoolDataset : public GDALProxyDataset
208{
209 private:
210 GIntBig responsiblePID = -1;
211
212 mutable char *pszProjectionRef = nullptr;
213 mutable OGRSpatialReference *m_poSRS = nullptr;
214 mutable OGRSpatialReference *m_poGCPSRS = nullptr;
215 double adfGeoTransform[6]{0, 1, 0, 0, 0, 1};
216 bool m_bHasSrcSRS = false;
217 bool bHasSrcGeoTransform = false;
218 char *pszGCPProjection = nullptr;
219 int nGCPCount = 0;
220 GDAL_GCP *pasGCPList = nullptr;
221 CPLHashSet *metadataSet = nullptr;
222 CPLHashSet *metadataItemSet = nullptr;
223
224 mutable GDALProxyPoolCacheEntry *cacheEntry = nullptr;
225 char *m_pszOwner = nullptr;
226
227 GDALDataset *RefUnderlyingDataset(bool bForceOpen) const;
228
229 GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
230 GDALAccess eAccess, int bShared, const char *pszOwner);
231
232 protected:
233 GDALDataset *RefUnderlyingDataset() const override;
234 void
235 UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const override;
236
237 friend class GDALProxyPoolRasterBand;
238
239 public:
240 GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
241 int nRasterXSize, int nRasterYSize,
242 GDALAccess eAccess = GA_ReadOnly, int bShared = FALSE,
243 const char *pszProjectionRef = nullptr,
244 double *padfGeoTransform = nullptr,
245 const char *pszOwner = nullptr);
246
247 static GDALProxyPoolDataset *Create(const char *pszSourceDatasetDescription,
248 CSLConstList papszOpenOptions = nullptr,
249 GDALAccess eAccess = GA_ReadOnly,
250 int bShared = FALSE,
251 const char *pszOwner = nullptr);
252
253 ~GDALProxyPoolDataset() override;
254
255 void SetOpenOptions(CSLConstList papszOpenOptions);
256
257 // If size (nBlockXSize&nBlockYSize) parameters is zero
258 // they will be loaded when RefUnderlyingRasterBand function is called.
259 // But in this case we cannot use them in other non-virtual methods before
260 // RefUnderlyingRasterBand fist call.
261 void AddSrcBandDescription(GDALDataType eDataType, int nBlockXSize,
262 int nBlockYSize);
263
264 // Used by VRT SimpleSource to add a single GDALProxyPoolRasterBand while
265 // keeping all other bands initialized to a nullptr. This is under the
266 // assumption, VRT SimpleSource will not have to access any other bands than
267 // the one added.
268 void AddSrcBand(int nBand, GDALDataType eDataType, int nBlockXSize,
269 int nBlockYSize);
270 void FlushCache(bool bAtClosing) override;
271
272 const OGRSpatialReference *GetSpatialRef() const override;
273 CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
274
275 CPLErr GetGeoTransform(double *) override;
276 CPLErr SetGeoTransform(double *) override;
277
278 // Special behavior for the following methods : they return a pointer
279 // data type, that must be cached by the proxy, so it doesn't become invalid
280 // when the underlying object get closed.
281 char **GetMetadata(const char *pszDomain) override;
282 const char *GetMetadataItem(const char *pszName,
283 const char *pszDomain) override;
284
285 void *GetInternalHandle(const char *pszRequest) override;
286
287 const OGRSpatialReference *GetGCPSpatialRef() const override;
288 const GDAL_GCP *GetGCPs() override;
289
290 private:
291 CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolDataset)
292};
293
294/* ******************************************************************** */
295/* GDALProxyPoolRasterBand */
296/* ******************************************************************** */
297
298class GDALProxyPoolOverviewRasterBand;
299class GDALProxyPoolMaskBand;
300
301class CPL_DLL GDALProxyPoolRasterBand : public GDALProxyRasterBand
302{
303 private:
304 CPLHashSet *metadataSet = nullptr;
305 CPLHashSet *metadataItemSet = nullptr;
306 char *pszUnitType = nullptr;
307 char **papszCategoryNames = nullptr;
308 GDALColorTable *poColorTable = nullptr;
309
310 int nSizeProxyOverviewRasterBand = 0;
311 GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand = nullptr;
312 GDALProxyPoolMaskBand *poProxyMaskBand = nullptr;
313
314 GDALRasterBand *RefUnderlyingRasterBand(bool bForceOpen) const;
315
316 protected:
317 GDALRasterBand *RefUnderlyingRasterBand() const override;
318 void UnrefUnderlyingRasterBand(
319 GDALRasterBand *poUnderlyingRasterBand) const override;
320
321 friend class GDALProxyPoolOverviewRasterBand;
322 friend class GDALProxyPoolMaskBand;
323
324 public:
325 GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS, int nBand,
326 GDALDataType eDataType, int nBlockXSize,
327 int nBlockYSize);
328 GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS,
329 GDALRasterBand *poUnderlyingRasterBand);
330 ~GDALProxyPoolRasterBand() override;
331
332 void AddSrcMaskBandDescription(GDALDataType eDataType, int nBlockXSize,
333 int nBlockYSize);
334
335 void AddSrcMaskBandDescriptionFromUnderlying();
336
337 // Special behavior for the following methods : they return a pointer
338 // data type, that must be cached by the proxy, so it doesn't become invalid
339 // when the underlying object get closed.
340 char **GetMetadata(const char *pszDomain) override;
341 const char *GetMetadataItem(const char *pszName,
342 const char *pszDomain) override;
343 char **GetCategoryNames() override;
344 const char *GetUnitType() override;
345 GDALColorTable *GetColorTable() override;
346 GDALRasterBand *GetOverview(int) override;
348 GetRasterSampleOverview(GUIntBig nDesiredSamples) override; // TODO
349 GDALRasterBand *GetMaskBand() override;
350
351 CPLErr FlushCache(bool bAtClosing) override;
352
353 private:
354 CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolRasterBand)
355};
356
357/* ******************************************************************** */
358/* GDALProxyPoolOverviewRasterBand */
359/* ******************************************************************** */
360
361class GDALProxyPoolOverviewRasterBand : public GDALProxyPoolRasterBand
362{
363 private:
364 GDALProxyPoolRasterBand *poMainBand = nullptr;
365 int nOverviewBand = 0;
366
367 mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
368 mutable int nRefCountUnderlyingMainRasterBand = 0;
369
370 CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolOverviewRasterBand)
371
372 protected:
373 GDALRasterBand *RefUnderlyingRasterBand() const override;
374 void UnrefUnderlyingRasterBand(
375 GDALRasterBand *poUnderlyingRasterBand) const override;
376
377 public:
378 GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset *poDS,
379 GDALRasterBand *poUnderlyingOverviewBand,
380 GDALProxyPoolRasterBand *poMainBand,
381 int nOverviewBand);
382 ~GDALProxyPoolOverviewRasterBand() override;
383};
384
385/* ******************************************************************** */
386/* GDALProxyPoolMaskBand */
387/* ******************************************************************** */
388
389class GDALProxyPoolMaskBand : public GDALProxyPoolRasterBand
390{
391 private:
392 GDALProxyPoolRasterBand *poMainBand = nullptr;
393
394 mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
395 mutable int nRefCountUnderlyingMainRasterBand = 0;
396
397 CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolMaskBand)
398
399 protected:
400 GDALRasterBand *RefUnderlyingRasterBand() const override;
401 void UnrefUnderlyingRasterBand(
402 GDALRasterBand *poUnderlyingRasterBand) const override;
403
404 public:
405 GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
406 GDALRasterBand *poUnderlyingMaskBand,
407 GDALProxyPoolRasterBand *poMainBand);
408 GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
409 GDALProxyPoolRasterBand *poMainBand,
410 GDALDataType eDataType, int nBlockXSize,
411 int nBlockYSize);
412 ~GDALProxyPoolMaskBand() override;
413
414 bool IsMaskBand() const override
415 {
416 return true;
417 }
418};
419
420#endif
421
422/* ******************************************************************** */
423/* C types and methods declarations */
424/* ******************************************************************** */
425
427
428typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
429
430GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(
431 const char *pszSourceDatasetDescription, int nRasterXSize, int nRasterYSize,
432 GDALAccess eAccess, int bShared, const char *pszProjectionRef,
433 double *padfGeoTransform);
434
435void CPL_DLL
436GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
437
438void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription(
439 GDALProxyPoolDatasetH hProxyPoolDataset, GDALDataType eDataType,
440 int nBlockXSize, int nBlockYSize);
441
443
444#endif /* #ifndef DOXYGEN_SKIP */
445
446#endif /* GDAL_PROXY_H_INCLUDED */
A color table / palette.
Definition gdal_priv.h:1093
A set of associated raster bands, usually from one file.
Definition gdal_priv.h:348
virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize, GDALDataType eDT, int nBandCount, int *panBandList, char **papszOptions)
Advise driver of upcoming read requests.
Definition gdaldataset.cpp:2729
char ** GetMetadataDomainList() override
Fetch list of metadata domains.
Definition gdaldataset.cpp:4236
virtual void * GetInternalHandle(const char *pszHandleName)
Fetch a format specific internally meaningful handle.
Definition gdaldataset.cpp:1203
virtual CPLErr CreateMaskBand(int nFlagsIn)
Adds a mask band to the dataset.
Definition gdaldataset.cpp:3041
virtual void FlushCache(bool bAtClosing=false)
Flush all write cached data to disk.
Definition gdaldataset.cpp:435
virtual int GetGCPCount()
Get number of GCPs.
Definition gdaldataset.cpp:1486
virtual CPLErr GetGeoTransform(double *padfTransform)
Fetch the affine transformation coefficients.
Definition gdaldataset.cpp:1105
virtual const OGRSpatialReference * GetGCPSpatialRef() const
Get output spatial reference system for GCPs.
Definition gdaldataset.cpp:1572
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
virtual CPLErr SetSpatialRef(const OGRSpatialReference *poSRS)
Set the spatial reference system for this dataset.
Definition gdaldataset.cpp:1026
virtual GDALDriver * GetDriver(void)
Fetch the driver to which this dataset relates.
Definition gdaldataset.cpp:1241
virtual CPLErr SetGeoTransform(double *padfTransform)
Set the affine transformation coefficients.
Definition gdaldataset.cpp:1159
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition gdaldataset.cpp:1736
virtual const OGRSpatialReference * GetSpatialRef() const
Fetch the spatial reference for this dataset.
Definition gdaldataset.cpp:921
CPLErr BuildOverviews(const char *, int, const int *, int, const int *, GDALProgressFunc, void *, CSLConstList papszOptions)
Build raster overview(s)
Definition gdaldataset.cpp:1839
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
void static void char ** GetMetadata(const char *pszDomain="") override
Fetch metadata.
Definition gdaldataset.cpp:4135
virtual const GDAL_GCP * GetGCPs()
Fetch GCPs.
Definition gdaldataset.cpp:1629
virtual char ** GetFileList(void)
Fetch files forming dataset.
Definition gdaldataset.cpp:2920
Format specific driver.
Definition gdal_priv.h:1641
virtual const char * GetMetadataItem(const char *pszName, const char *pszDomain="")
Fetch single metadata item.
Definition gdalmajorobject.cpp:341
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition gdal_rat.h:48
A single raster band (or channel).
Definition gdal_priv.h:1238
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:167
CPLErr
Error category.
Definition cpl_error.h:53
Hash set implementation.
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition cpl_hash_set.h:52
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:236
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:317
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:313
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1049
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1190
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:233
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:62
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:314
GDALAccess
Definition gdal.h:124
@ GA_ReadOnly
Definition gdal.h:125
GDALDataType
Definition gdal.h:64
GDALColorInterp
Definition gdal.h:226
GDALRWFlag
Definition gdal.h:131
C++ GDAL entry points.
GDALMaskValueRange
Range of values found in a mask band.
Definition gdal_priv.h:1209
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:175
Ground Control Point.
Definition gdal.h:959