forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoraster_priv.h
480 lines (390 loc) · 14.6 KB
/
georaster_priv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/******************************************************************************
*
* Name: georaster_priv.h
* Project: Oracle Spatial GeoRaster Driver
* Purpose: Define C++/Private declarations
* Author: Ivan Lucena [ivan.lucena at oracle.com]
*
******************************************************************************
* Copyright (c) 2008, Ivan Lucena
*
* SPDX-License-Identifier: MIT
*****************************************************************************/
#ifndef GEORASTER_PRIV_H_INCLUDED
#define GEORASTER_PRIV_H_INCLUDED
#include "gdal.h"
#include "gdal_priv.h"
#include "gdal_alg.h"
#include "gdal_rat.h"
#include "ogr_spatialref.h"
#include "cpl_minixml.h"
#include "cpl_list.h"
// ---------------------------------------------------------------------------
// DEFLATE compression support
// ---------------------------------------------------------------------------
#include <zlib.h>
// ---------------------------------------------------------------------------
// JPEG compression support
// ---------------------------------------------------------------------------
#ifdef JPEG_SUPPORTED
CPL_C_START
#include <jpeglib.h>
CPL_C_END
#endif
// ---------------------------------------------------------------------------
// JPEG2000 support - Install the Virtual File System handler to OCI LOB
// ---------------------------------------------------------------------------
CPL_C_START
void CPL_DLL VSIInstallOCILobHandler(void);
CPL_C_END
// ---------------------------------------------------------------------------
// System constants
// ---------------------------------------------------------------------------
// VAT maximum string len
#define MAXLEN_VATSTR 128
// Geographic system without EPSG parameters
#define UNKNOWN_CRS 999999
#define NO_CRS 0
#define DEFAULT_CRS NO_CRS
// Bitmap Mask for the whole dataset start with -99999
#define DEFAULT_BMP_MASK -99999
// Default block size
#define DEFAULT_BLOCK_ROWS 512
#define DEFAULT_BLOCK_COLUMNS 512
#define DEFAULT_JP2_TILE_ROWS 512
#define DEFAULT_JP2_TILE_COLUMNS 512
// Default Model Coordinate Location (internal pixel geo-reference)
#define MCL_CENTER 0
#define MCL_UPPERLEFT 1
#define MCL_DEFAULT MCL_CENTER
// MAX double string representation
#define MAX_DOUBLE_STR_REP 20
// Pyramid levels details
struct hLevelDetails
{
int nColumnBlockSize;
int nRowBlockSize;
int nTotalColumnBlocks;
int nTotalRowBlocks;
unsigned long nBlockCount;
unsigned long nBlockBytes;
unsigned long nGDALBlockBytes;
unsigned long nOffset;
};
// ---------------------------------------------------------------------------
// Support for multi-values NoData support
// ---------------------------------------------------------------------------
struct hNoDataItem
{
int nBand;
double dfLower;
double dfUpper;
};
// ---------------------------------------------------------------------------
// GeoRaster wrapper class definitions
// ---------------------------------------------------------------------------
#include "oci_wrapper.h"
class GeoRasterDataset;
class GeoRasterRasterBand;
class GeoRasterWrapper;
// ---------------------------------------------------------------------------
// GeoRasterDataset, extends GDALDataset to support GeoRaster Datasets
// ---------------------------------------------------------------------------
class GeoRasterDataset final : public GDALDataset
{
friend class GeoRasterRasterBand;
public:
GeoRasterDataset();
~GeoRasterDataset() override;
private:
GeoRasterWrapper *poGeoRaster;
bool bGeoTransform;
bool bForcedSRID;
mutable OGRSpatialReference m_oSRS{};
char **papszSubdatasets;
double adfGeoTransform[6];
GeoRasterRasterBand *poMaskBand;
bool bApplyNoDataArray;
void JP2_Open(GDALAccess eAccess);
void JP2_CreateCopy(GDALDataset *poJP2DS, char **papszOptions,
int *pnResolutions, GDALProgressFunc pfnProgress,
void *pProgressData);
boolean JP2_CopyDirect(const char *pszJP2Filename, int *pnResolutions,
GDALProgressFunc pfnProgress, void *pProgressData);
boolean JPEG_CopyDirect(const char *pszJPGFilename,
GDALProgressFunc pfnProgress, void *pProgressData);
public:
GDALDataset *poJP2Dataset;
void SetSubdatasets(GeoRasterWrapper *poGRW);
static int Identify(GDALOpenInfo *poOpenInfo);
static GDALDataset *Open(GDALOpenInfo *poOpenInfo);
static CPLErr Delete(const char *pszFilename);
static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
int nBands, GDALDataType eType,
char **papszOptions);
static GDALDataset *CreateCopy(const char *pszFilename,
GDALDataset *poSrcDS, int bStrict,
char **papszOptions,
GDALProgressFunc pfnProgress,
void *pProgressData);
CPLErr GetGeoTransform(double *padfTransform) override;
CPLErr SetGeoTransform(double *padfTransform) override;
const OGRSpatialReference *GetSpatialRef() const override;
CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
char **GetMetadataDomainList() override;
char **GetMetadata(const char *pszDomain) override;
CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
int nYSize, void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType, int nBandCount,
BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
GSpacing nLineSpace, GSpacing nBandSpace,
GDALRasterIOExtraArg *psExtraArg) override;
int GetGCPCount() override;
const OGRSpatialReference *GetGCPSpatialRef() const override;
const GDAL_GCP *GetGCPs() override;
CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
const OGRSpatialReference *poSRS) override;
CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
const int *panOverviewList, int nListBandsover,
const int *panBandList, GDALProgressFunc pfnProgress,
void *pProgresoversData,
CSLConstList papszOptions) override;
CPLErr CreateMaskBand(int nFlags) override;
// cppcheck-suppress functionStatic
OGRErr StartTransaction(int /* bForce */ = FALSE) override
{
return CE_None;
}
OGRErr CommitTransaction() override
{
return CE_None;
}
OGRErr RollbackTransaction() override
{
return CE_None;
}
char **GetFileList() override;
void AssignGeoRaster(GeoRasterWrapper *poGRW);
};
// ---------------------------------------------------------------------------
// GeoRasterRasterBand, extends GDALRasterBand to support GeoRaster Band
// ---------------------------------------------------------------------------
class GeoRasterRasterBand final : public GDALRasterBand
{
friend class GeoRasterDataset;
public:
GeoRasterRasterBand(GeoRasterDataset *poGDS, int nBand, int nLevel,
GDALDataset *poJP2Dataset = nullptr);
~GeoRasterRasterBand() override;
private:
GeoRasterWrapper *poGeoRaster;
GDALColorTable *poColorTable;
GDALRasterAttributeTable *poDefaultRAT;
GDALDataset *poJP2Dataset;
double dfMin;
double dfMax;
double dfMean;
double dfMedian;
double dfMode;
double dfStdDev;
bool bValidStats;
double dfNoData;
char *pszVATName;
int nOverviewLevel;
GeoRasterRasterBand **papoOverviews;
int nOverviewCount;
hNoDataItem *pahNoDataArray;
int nNoDataArraySz;
bool bHasNoDataArray;
void ApplyNoDataArray(void *pBuffer) const;
public:
double GetNoDataValue(int *pbSuccess = nullptr) override;
CPLErr SetNoDataValue(double dfNoDataValue) override;
double GetMinimum(int *pbSuccess = nullptr) override;
double GetMaximum(int *pbSuccess = nullptr) override;
GDALColorTable *GetColorTable() override;
CPLErr SetColorTable(GDALColorTable *poInColorTable) override;
GDALColorInterp GetColorInterpretation() override;
CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;
CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;
CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
double dfStdDev) override;
CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
double *pdfMax, double *pdfMean,
double *pdfStdDev) override;
GDALRasterAttributeTable *GetDefaultRAT() override;
CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT) override;
int GetOverviewCount() override;
GDALRasterBand *GetOverview(int) override;
CPLErr CreateMaskBand(int nFlags) override;
GDALRasterBand *GetMaskBand() override;
int GetMaskFlags() override;
bool IsMaskBand() const override
{
return nOverviewLevel == DEFAULT_BMP_MASK;
}
};
// ---------------------------------------------------------------------------
// GeoRasterWrapper, an interface for Oracle Spatial SDO_GEORASTER objects
// ---------------------------------------------------------------------------
class GeoRasterWrapper
{
public:
GeoRasterWrapper();
virtual ~GeoRasterWrapper();
private:
OCILobLocator **pahLocator;
unsigned long nBlockCount;
unsigned long nBlockBytes;
unsigned long nGDALBlockBytes;
GByte *pabyBlockBuf;
GByte *pabyCompressBuf;
OWStatement *poBlockStmt;
int nCurrentLevel;
long nLevelOffset;
long nCacheBlockId;
bool bFlushBlock;
unsigned long nFlushBlockSize;
bool bWriteOnly;
hLevelDetails *pahLevels;
int nCellSizeBits;
int nGDALCellBytes;
bool bUpdate;
bool bInitializeIO;
bool bFlushMetadata;
void InitializeLayersNode();
bool InitializeIO();
void InitializeLevel(int nLevel);
void LoadNoDataValues();
void UnpackNBits(GByte *pabyData);
void PackNBits(GByte *pabyData) const;
#ifdef JPEG_SUPPORTED
unsigned long CompressJpeg();
void UncompressJpeg(unsigned long nBufferSize);
struct jpeg_decompress_struct sDInfo;
struct jpeg_compress_struct sCInfo;
struct jpeg_error_mgr sJErr;
#endif
unsigned long CompressDeflate();
bool UncompressDeflate(unsigned long nBufferSize);
void GetSpatialReference();
public:
int nGCPCount;
GDAL_GCP *pasGCPList;
bool bFlushGCP;
void FlushGCP();
bool FlushMetadata();
static char **ParseIdentificator(const char *pszStringID);
static GeoRasterWrapper *Open(const char *pszStringID, bool bUpdate);
bool Create(char *pszDescription, char *pszInsert, bool bUpdate);
bool Delete();
void GetRasterInfo();
bool GetStatistics(int nBand, char *pszMin, char *pszMax, char *pszMean,
char *pszMedian, char *pszMode, char *pszStdDev,
char *pszSampling);
bool SetStatistics(int nBand, const char *pszMin, const char *pszMax,
const char *pszMean, const char *pszMedian,
const char *pszMode, const char *pszStdDev,
const char *pszSampling);
bool HasColorMap(int nBand);
void GetColorMap(int nBand, GDALColorTable *poCT);
void SetColorMap(int nBand, GDALColorTable *poCT);
void SetGeoReference(long long nSRIDIn);
bool GetDataBlock(int nBand, int nLevel, int nXOffset, int nYOffset,
void *pData);
bool SetDataBlock(int nBand, int nLevel, int nXOffset, int nYOffset,
void *pData);
long GetBlockNumber(int nB, int nX, int nY) const
{
return nLevelOffset +
(long)((ceil((double)((nB - 1) / nBandBlockSize)) *
nTotalColumnBlocks * nTotalRowBlocks) +
(nY * nTotalColumnBlocks) + nX);
}
bool FlushBlock(long nCacheBlock);
bool GetNoData(int nLayer, double *pdfNoDataValue);
bool SetNoData(int nLayer, const char *pszValue);
CPLXMLNode *GetMetadata()
{
return phMetadata;
}
bool SetVAT(int nBand, const char *pszName);
char *GetVAT(int nBand);
bool GeneratePyramid(int nLevels, const char *pszResampling,
bool bInternal = false);
bool GenerateStatistics(int nSamplingFactor, double *pdfSamplingWindow,
bool bHistogram, const char *pszLayerNumbers,
bool bUseBin, double *pdfBinFunction, bool bNodata);
void DeletePyramid();
void PrepareToOverwrite();
bool InitializeMask(int nLevel, int nBlockColumns, int nBlockRows,
int nColumnBlocks, int nRowBlocks, int nBandBlocks);
void SetWriteOnly(bool value)
{
bWriteOnly = value;
}
void SetRPC();
void SetMaxLevel(int nMaxLevel);
void GetRPC();
void GetGCP();
void SetGCP(int nGCPCountIn, const GDAL_GCP *pasGCPListIn);
void QueryWKText();
public:
OWConnection *poConnection;
CPLString sTable;
CPLString sSchema;
CPLString sOwner;
CPLString sColumn;
CPLString sDataTable;
long long nRasterId;
CPLString sWhere;
CPLString sValueAttributeTab;
long long nSRID;
long long nExtentSRID;
bool bGenSpatialExtent;
bool bCreateObjectTable;
CPLXMLNode *phMetadata;
CPLString sCellDepth;
bool bGenPyramid;
CPLString sPyramidResampling;
int nPyramidLevels;
CPLString sCompressionType;
int nCompressQuality;
CPLString sWKText;
CPLString sAuthority;
CPLList *psNoDataList;
int nRasterColumns;
int nRasterRows;
int nRasterBands;
CPLString sInterleaving;
bool bIsReferenced;
bool bBlocking;
bool bAutoBlocking;
double dfXCoefficient[3];
double dfYCoefficient[3];
int nColumnBlockSize;
int nRowBlockSize;
int nBandBlockSize;
int nTotalColumnBlocks;
int nTotalRowBlocks;
int nTotalBandBlocks;
int iDefaultRedBand;
int iDefaultGreenBand;
int iDefaultBlueBand;
int nPyramidMaxLevel;
bool bHasBitmapMask;
bool bUniqueFound;
bool bGenStats;
int nGenStatsSamplingFactor;
bool bGenStatsUseSamplingWindow;
double dfGenStatsSamplingWindow[4];
bool bGenStatsHistogram;
CPLString sGenStatsLayerNumbers;
bool bGenStatsUseBin;
double dfGenStatsBinFunction[5];
bool bGenStatsNodata;
int eModelCoordLocation;
unsigned int anULTCoordinate[3];
GDALRPCInfoV2 *phRPC;
};
#endif /* ifndef GEORASTER_PRIV_H_INCLUDED */