Line data Source code
1 : /******************************************************************************
2 : *
3 : * Name: gdal_priv.h
4 : * Project: GDAL Core
5 : * Purpose: GDAL Core C++/Private declarations.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1998, Frank Warmerdam
10 : * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 : *
12 : * SPDX-License-Identifier: MIT
13 : ****************************************************************************/
14 :
15 : #ifndef GDAL_PRIV_H_INCLUDED
16 : #define GDAL_PRIV_H_INCLUDED
17 :
18 : /**
19 : * \file gdal_priv.h
20 : *
21 : * C++ GDAL entry points.
22 : */
23 :
24 : /* -------------------------------------------------------------------- */
25 : /* Predeclare various classes before pulling in gdal.h, the */
26 : /* public declarations. */
27 : /* -------------------------------------------------------------------- */
28 : class GDALMajorObject;
29 : class GDALDataset;
30 : class GDALRasterBand;
31 : class GDALDriver;
32 : class GDALRasterAttributeTable;
33 : class GDALProxyDataset;
34 : class GDALProxyRasterBand;
35 : class GDALAsyncReader;
36 : class GDALRelationship;
37 :
38 : /* -------------------------------------------------------------------- */
39 : /* Pull in the public declarations. This gets the C apis, and */
40 : /* also various constants. However, we will still get to */
41 : /* provide the real class definitions for the GDAL classes. */
42 : /* -------------------------------------------------------------------- */
43 :
44 : #include "gdal.h"
45 : #include "gdal_frmts.h"
46 : #include "gdalsubdatasetinfo.h"
47 : #include "cpl_vsi.h"
48 : #include "cpl_conv.h"
49 : #include "cpl_float.h"
50 : #include "cpl_string.h"
51 : #include "cpl_minixml.h"
52 : #include "cpl_multiproc.h"
53 : #include "cpl_atomic_ops.h"
54 :
55 : #include <stdarg.h>
56 :
57 : #include <cmath>
58 : #include <complex>
59 : #include <cstdint>
60 : #include <iterator>
61 : #include <limits>
62 : #include <map>
63 : #include <memory>
64 : #include <set>
65 : #if __cplusplus >= 202002L
66 : #include <span>
67 : #endif
68 : #include <vector>
69 :
70 : #include "ogr_core.h"
71 : #include "ogr_feature.h"
72 :
73 : //! @cond Doxygen_Suppress
74 : #define GMO_VALID 0x0001
75 : #define GMO_IGNORE_UNIMPLEMENTED 0x0002
76 : #define GMO_SUPPORT_MD 0x0004
77 : #define GMO_SUPPORT_MDMD 0x0008
78 : #define GMO_MD_DIRTY 0x0010
79 : #define GMO_PAM_CLASS 0x0020
80 :
81 : //! @endcond
82 :
83 : /************************************************************************/
84 : /* GDALMultiDomainMetadata */
85 : /************************************************************************/
86 :
87 : //! @cond Doxygen_Suppress
88 4826300 : class CPL_DLL GDALMultiDomainMetadata
89 : {
90 : private:
91 : CPLStringList aosDomainList{};
92 :
93 : struct Comparator
94 : {
95 31122500 : bool operator()(const char *a, const char *b) const
96 : {
97 31122500 : return STRCASECMP(a, b) < 0;
98 : }
99 : };
100 :
101 : std::map<const char *, CPLStringList, Comparator> oMetadata{};
102 :
103 : public:
104 : GDALMultiDomainMetadata();
105 : ~GDALMultiDomainMetadata();
106 :
107 : int XMLInit(const CPLXMLNode *psMetadata, int bMerge);
108 : CPLXMLNode *Serialize() const;
109 :
110 437068 : CSLConstList GetDomainList() const
111 : {
112 437068 : return aosDomainList.List();
113 : }
114 :
115 : char **GetMetadata(const char *pszDomain = "");
116 : CPLErr SetMetadata(CSLConstList papszMetadata, const char *pszDomain = "");
117 : const char *GetMetadataItem(const char *pszName,
118 : const char *pszDomain = "");
119 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
120 : const char *pszDomain = "");
121 :
122 : void Clear();
123 :
124 : inline void clear()
125 : {
126 : Clear();
127 : }
128 : };
129 :
130 : //! @endcond
131 :
132 : /* ******************************************************************** */
133 : /* GDALMajorObject */
134 : /* */
135 : /* Base class providing metadata, description and other */
136 : /* services shared by major objects. */
137 : /* ******************************************************************** */
138 :
139 : /** Object with metadata. */
140 : class CPL_DLL GDALMajorObject
141 : {
142 : protected:
143 : //! @cond Doxygen_Suppress
144 : int nFlags; // GMO_* flags.
145 : CPLString sDescription{};
146 : GDALMultiDomainMetadata oMDMD{};
147 :
148 : //! @endcond
149 :
150 : char **BuildMetadataDomainList(char **papszList, int bCheckNonEmpty,
151 : ...) CPL_NULL_TERMINATED;
152 :
153 : public:
154 : GDALMajorObject();
155 : virtual ~GDALMajorObject();
156 :
157 : int GetMOFlags() const;
158 : void SetMOFlags(int nFlagsIn);
159 :
160 : virtual const char *GetDescription() const;
161 : virtual void SetDescription(const char *);
162 :
163 : virtual char **GetMetadataDomainList();
164 :
165 : virtual char **GetMetadata(const char *pszDomain = "");
166 : virtual CPLErr SetMetadata(char **papszMetadata,
167 : const char *pszDomain = "");
168 : virtual const char *GetMetadataItem(const char *pszName,
169 : const char *pszDomain = "");
170 : virtual CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
171 : const char *pszDomain = "");
172 :
173 : /** Convert a GDALMajorObject* to a GDALMajorObjectH.
174 : * @since GDAL 2.3
175 : */
176 245 : static inline GDALMajorObjectH ToHandle(GDALMajorObject *poMajorObject)
177 : {
178 245 : return static_cast<GDALMajorObjectH>(poMajorObject);
179 : }
180 :
181 : /** Convert a GDALMajorObjectH to a GDALMajorObject*.
182 : * @since GDAL 2.3
183 : */
184 2058740 : static inline GDALMajorObject *FromHandle(GDALMajorObjectH hMajorObject)
185 : {
186 2058740 : return static_cast<GDALMajorObject *>(hMajorObject);
187 : }
188 : };
189 :
190 : /* ******************************************************************** */
191 : /* GDALDefaultOverviews */
192 : /* ******************************************************************** */
193 :
194 : //! @cond Doxygen_Suppress
195 : class GDALOpenInfo;
196 :
197 : class CPL_DLL GDALDefaultOverviews
198 : {
199 : friend class GDALDataset;
200 :
201 : GDALDataset *poDS;
202 : GDALDataset *poODS;
203 :
204 : CPLString osOvrFilename{};
205 :
206 : bool bOvrIsAux;
207 :
208 : bool bCheckedForMask;
209 : bool bOwnMaskDS;
210 : GDALDataset *poMaskDS;
211 :
212 : // For "overview datasets" we record base level info so we can
213 : // find our way back to get overview masks.
214 : GDALDataset *poBaseDS;
215 :
216 : // Stuff for deferred initialize/overviewscans.
217 : bool bCheckedForOverviews;
218 : void OverviewScan();
219 : char *pszInitName;
220 : bool bInitNameIsOVR;
221 : char **papszInitSiblingFiles;
222 :
223 : public:
224 : GDALDefaultOverviews();
225 : ~GDALDefaultOverviews();
226 :
227 : void Initialize(GDALDataset *poDSIn, const char *pszName = nullptr,
228 : CSLConstList papszSiblingFiles = nullptr,
229 : bool bNameIsOVR = false);
230 :
231 : void Initialize(GDALDataset *poDSIn, GDALOpenInfo *poOpenInfo,
232 : const char *pszName = nullptr,
233 : bool bTransferSiblingFilesIfLoaded = true);
234 :
235 : void TransferSiblingFiles(char **papszSiblingFiles);
236 :
237 : int IsInitialized();
238 :
239 : int CloseDependentDatasets();
240 :
241 : // Overview Related
242 :
243 : int GetOverviewCount(int nBand);
244 : GDALRasterBand *GetOverview(int nBand, int iOverview);
245 :
246 : CPLErr BuildOverviews(const char *pszBasename, const char *pszResampling,
247 : int nOverviews, const int *panOverviewList,
248 : int nBands, const int *panBandList,
249 : GDALProgressFunc pfnProgress, void *pProgressData,
250 : CSLConstList papszOptions);
251 :
252 : CPLErr BuildOverviewsSubDataset(const char *pszPhysicalFile,
253 : const char *pszResampling, int nOverviews,
254 : const int *panOverviewList, int nBands,
255 : const int *panBandList,
256 : GDALProgressFunc pfnProgress,
257 : void *pProgressData,
258 : CSLConstList papszOptions);
259 :
260 : CPLErr BuildOverviewsMask(const char *pszResampling, int nOverviews,
261 : const int *panOverviewList,
262 : GDALProgressFunc pfnProgress, void *pProgressData,
263 : CSLConstList papszOptions);
264 :
265 : CPLErr CleanOverviews();
266 :
267 : // Mask Related
268 :
269 : CPLErr CreateMaskBand(int nFlags, int nBand = -1);
270 : GDALRasterBand *GetMaskBand(int nBand);
271 : int GetMaskFlags(int nBand);
272 :
273 : int HaveMaskFile(char **papszSiblings = nullptr,
274 : const char *pszBasename = nullptr);
275 :
276 47683 : char **GetSiblingFiles()
277 : {
278 47683 : return papszInitSiblingFiles;
279 : }
280 :
281 : private:
282 : CPL_DISALLOW_COPY_ASSIGN(GDALDefaultOverviews)
283 : };
284 :
285 : //! @endcond
286 :
287 : /* ******************************************************************** */
288 : /* GDALOpenInfo */
289 : /* ******************************************************************** */
290 :
291 : /** Class for dataset open functions. */
292 : class CPL_DLL GDALOpenInfo
293 : {
294 : bool bHasGotSiblingFiles = false;
295 : char **papszSiblingFiles = nullptr;
296 : int nHeaderBytesTried = 0;
297 :
298 : public:
299 : GDALOpenInfo(const char *pszFile, int nOpenFlagsIn,
300 : const char *const *papszSiblingFiles = nullptr);
301 : ~GDALOpenInfo(void);
302 :
303 : /** Filename */
304 : char *pszFilename = nullptr;
305 :
306 : /** Result of CPLGetExtension(pszFilename); */
307 : std::string osExtension{};
308 :
309 : /** Open options */
310 : char **papszOpenOptions = nullptr;
311 :
312 : /** Access flag */
313 : GDALAccess eAccess = GA_ReadOnly;
314 : /** Open flags */
315 : int nOpenFlags = 0;
316 :
317 : /** Whether stat()'ing the file was successful */
318 : bool bStatOK = false;
319 : /** Whether the file is a directory */
320 : bool bIsDirectory = false;
321 :
322 : /** Pointer to the file */
323 : VSILFILE *fpL = nullptr;
324 :
325 : /** Number of bytes in pabyHeader */
326 : int nHeaderBytes = 0;
327 : /** Buffer with first bytes of the file */
328 : GByte *pabyHeader = nullptr;
329 :
330 : /** Allowed drivers (NULL for all) */
331 : const char *const *papszAllowedDrivers = nullptr;
332 :
333 : int TryToIngest(int nBytes);
334 : char **GetSiblingFiles();
335 : char **StealSiblingFiles();
336 : bool AreSiblingFilesLoaded() const;
337 :
338 : bool IsSingleAllowedDriver(const char *pszDriverName) const;
339 :
340 : /** Return whether the extension of the file is equal to pszExt, using
341 : * case-insensitive comparison.
342 : * @since 3.11 */
343 926521 : inline bool IsExtensionEqualToCI(const char *pszExt) const
344 : {
345 926521 : return EQUAL(osExtension.c_str(), pszExt);
346 : }
347 :
348 : private:
349 : CPL_DISALLOW_COPY_ASSIGN(GDALOpenInfo)
350 : };
351 :
352 : /* ******************************************************************** */
353 : /* gdal::GCP */
354 : /* ******************************************************************** */
355 :
356 : namespace gdal
357 : {
358 : /** C++ wrapper over the C GDAL_GCP structure.
359 : *
360 : * It has the same binary layout, and thus a gdal::GCP pointer can be cast as a
361 : * GDAL_GCP pointer.
362 : *
363 : * @since 3.9
364 : */
365 : class CPL_DLL GCP
366 : {
367 : public:
368 : explicit GCP(const char *pszId = "", const char *pszInfo = "",
369 : double dfPixel = 0, double dfLine = 0, double dfX = 0,
370 : double dfY = 0, double dfZ = 0);
371 : ~GCP();
372 : GCP(const GCP &);
373 : explicit GCP(const GDAL_GCP &other);
374 : GCP &operator=(const GCP &);
375 : GCP(GCP &&);
376 : GCP &operator=(GCP &&);
377 :
378 : /** Returns the "id" member. */
379 21930 : inline const char *Id() const
380 : {
381 21930 : return gcp.pszId;
382 : }
383 :
384 : void SetId(const char *pszId);
385 :
386 : /** Returns the "info" member. */
387 43842 : inline const char *Info() const
388 : {
389 43842 : return gcp.pszInfo;
390 : }
391 :
392 : void SetInfo(const char *pszInfo);
393 :
394 : /** Returns the "pixel" member. */
395 21949 : inline double Pixel() const
396 : {
397 21949 : return gcp.dfGCPPixel;
398 : }
399 :
400 : /** Returns a reference to the "pixel" member. */
401 24709 : inline double &Pixel()
402 : {
403 24709 : return gcp.dfGCPPixel;
404 : }
405 :
406 : /** Returns the "line" member. */
407 21949 : inline double Line() const
408 : {
409 21949 : return gcp.dfGCPLine;
410 : }
411 :
412 : /** Returns a reference to the "line" member. */
413 24709 : inline double &Line()
414 : {
415 24709 : return gcp.dfGCPLine;
416 : }
417 :
418 : /** Returns the "X" member. */
419 21949 : inline double X() const
420 : {
421 21949 : return gcp.dfGCPX;
422 : }
423 :
424 : /** Returns a reference to the "X" member. */
425 24635 : inline double &X()
426 : {
427 24635 : return gcp.dfGCPX;
428 : }
429 :
430 : /** Returns the "Y" member. */
431 21949 : inline double Y() const
432 : {
433 21949 : return gcp.dfGCPY;
434 : }
435 :
436 : /** Returns a reference to the "Y" member. */
437 24635 : inline double &Y()
438 : {
439 24635 : return gcp.dfGCPY;
440 : }
441 :
442 : /** Returns the "Z" member. */
443 43777 : inline double Z() const
444 : {
445 43777 : return gcp.dfGCPZ;
446 : }
447 :
448 : /** Returns a reference to the "Z" member. */
449 24535 : inline double &Z()
450 : {
451 24535 : return gcp.dfGCPZ;
452 : }
453 :
454 : /** Casts as a C GDAL_GCP pointer */
455 415 : inline const GDAL_GCP *c_ptr() const
456 : {
457 415 : return &gcp;
458 : }
459 :
460 : static const GDAL_GCP *c_ptr(const std::vector<GCP> &asGCPs);
461 :
462 : static std::vector<GCP> fromC(const GDAL_GCP *pasGCPList, int nGCPCount);
463 :
464 : private:
465 : GDAL_GCP gcp;
466 : };
467 :
468 : } /* namespace gdal */
469 :
470 : /* ******************************************************************** */
471 : /* GDALDataset */
472 : /* ******************************************************************** */
473 :
474 : class OGRLayer;
475 : class OGRGeometry;
476 : class OGRSpatialReference;
477 : class OGRStyleTable;
478 : class swq_select;
479 : class swq_select_parse_options;
480 : class GDALGroup;
481 :
482 : //! @cond Doxygen_Suppress
483 : typedef struct GDALSQLParseInfo GDALSQLParseInfo;
484 : //! @endcond
485 :
486 : //! @cond Doxygen_Suppress
487 : #ifdef GDAL_COMPILATION
488 : #define OPTIONAL_OUTSIDE_GDAL(val)
489 : #else
490 : #define OPTIONAL_OUTSIDE_GDAL(val) = val
491 : #endif
492 : //! @endcond
493 :
494 : //! @cond Doxygen_Suppress
495 : // This macro can be defined to check that GDALDataset::IRasterIO()
496 : // implementations do not alter the passed panBandList. It is not defined
497 : // by default (and should not!), hence int* is used.
498 : #if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
499 : #define BANDMAP_TYPE const int *
500 : #else
501 : #define BANDMAP_TYPE int *
502 : #endif
503 : //! @endcond
504 :
505 : /** A set of associated raster bands, usually from one file. */
506 : class CPL_DLL GDALDataset : public GDALMajorObject
507 : {
508 : friend GDALDatasetH CPL_STDCALL
509 : GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags,
510 : const char *const *papszAllowedDrivers,
511 : const char *const *papszOpenOptions,
512 : const char *const *papszSiblingFiles);
513 : friend CPLErr CPL_STDCALL GDALClose(GDALDatasetH hDS);
514 :
515 : friend class GDALDriver;
516 : friend class GDALDefaultOverviews;
517 : friend class GDALProxyDataset;
518 : friend class GDALDriverManager;
519 :
520 : CPL_INTERNAL void AddToDatasetOpenList();
521 :
522 : CPL_INTERNAL void UnregisterFromSharedDataset();
523 :
524 : CPL_INTERNAL static void ReportErrorV(const char *pszDSName,
525 : CPLErr eErrClass, CPLErrorNum err_no,
526 : const char *fmt, va_list args);
527 :
528 : protected:
529 : //! @cond Doxygen_Suppress
530 : GDALDriver *poDriver = nullptr;
531 : GDALAccess eAccess = GA_ReadOnly;
532 :
533 : // Stored raster information.
534 : int nRasterXSize = 512;
535 : int nRasterYSize = 512;
536 : int nBands = 0;
537 : GDALRasterBand **papoBands = nullptr;
538 :
539 : static constexpr int OPEN_FLAGS_CLOSED = -1;
540 : int nOpenFlags =
541 : 0; // set to OPEN_FLAGS_CLOSED after Close() has been called
542 :
543 : int nRefCount = 1;
544 : bool bForceCachedIO = false;
545 : bool bShared = false;
546 : bool bIsInternal = true;
547 : bool bSuppressOnClose = false;
548 :
549 : mutable std::map<std::string, std::unique_ptr<OGRFieldDomain>>
550 : m_oMapFieldDomains{};
551 :
552 : GDALDataset(void);
553 : explicit GDALDataset(int bForceCachedIO);
554 :
555 : void RasterInitialize(int, int);
556 : void SetBand(int nNewBand, GDALRasterBand *poBand);
557 : void SetBand(int nNewBand, std::unique_ptr<GDALRasterBand> poBand);
558 :
559 : GDALDefaultOverviews oOvManager{};
560 :
561 : virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
562 : const int *panOverviewList, int nListBands,
563 : const int *panBandList,
564 : GDALProgressFunc pfnProgress,
565 : void *pProgressData,
566 : CSLConstList papszOptions);
567 :
568 : virtual CPLErr
569 : IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
570 : void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
571 : int nBandCount, BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
572 : GSpacing nLineSpace, GSpacing nBandSpace,
573 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
574 :
575 : /* This method should only be be overloaded by GDALProxyDataset */
576 : virtual CPLErr
577 : BlockBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
578 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
579 : GDALDataType eBufType, int nBandCount,
580 : const int *panBandMap, GSpacing nPixelSpace,
581 : GSpacing nLineSpace, GSpacing nBandSpace,
582 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
583 : CPLErr BlockBasedFlushCache(bool bAtClosing);
584 :
585 : CPLErr
586 : BandBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
587 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
588 : GDALDataType eBufType, int nBandCount,
589 : const int *panBandMap, GSpacing nPixelSpace,
590 : GSpacing nLineSpace, GSpacing nBandSpace,
591 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
592 :
593 : CPLErr
594 : RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
595 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
596 : GDALDataType eBufType, int nBandCount,
597 : const int *panBandMap, GSpacing nPixelSpace,
598 : GSpacing nLineSpace, GSpacing nBandSpace,
599 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
600 :
601 : CPLErr ValidateRasterIOOrAdviseReadParameters(
602 : const char *pszCallingFunc, int *pbStopProcessingOnCENone, int nXOff,
603 : int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize,
604 : int nBandCount, const int *panBandMap);
605 :
606 : CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
607 : int nXSize, int nYSize, void *pData,
608 : int nBufXSize, int nBufYSize,
609 : GDALDataType eBufType, int nBandCount,
610 : const int *panBandMap, GSpacing nPixelSpace,
611 : GSpacing nLineSpace, GSpacing nBandSpace,
612 : GDALRasterIOExtraArg *psExtraArg, int *pbTried);
613 :
614 : void ShareLockWithParentDataset(GDALDataset *poParentDataset);
615 :
616 : bool m_bCanBeReopened = false;
617 :
618 : virtual bool CanBeCloned(int nScopeFlags, bool bCanShareState) const;
619 :
620 : friend class GDALThreadSafeDataset;
621 : friend class MEMDataset;
622 : virtual std::unique_ptr<GDALDataset> Clone(int nScopeFlags,
623 : bool bCanShareState) const;
624 :
625 : //! @endcond
626 :
627 : void CleanupPostFileClosing();
628 :
629 : virtual int CloseDependentDatasets();
630 : //! @cond Doxygen_Suppress
631 : int ValidateLayerCreationOptions(const char *const *papszLCO);
632 :
633 : char **papszOpenOptions = nullptr;
634 :
635 : friend class GDALRasterBand;
636 :
637 : // The below methods related to read write mutex are fragile logic, and
638 : // should not be used by out-of-tree code if possible.
639 : int EnterReadWrite(GDALRWFlag eRWFlag);
640 : void LeaveReadWrite();
641 : void InitRWLock();
642 :
643 : void TemporarilyDropReadWriteLock();
644 : void ReacquireReadWriteLock();
645 :
646 : void DisableReadWriteMutex();
647 :
648 : int AcquireMutex();
649 : void ReleaseMutex();
650 :
651 : bool IsAllBands(int nBandCount, const int *panBandList) const;
652 : //! @endcond
653 :
654 : public:
655 : ~GDALDataset() override;
656 :
657 : virtual CPLErr Close();
658 :
659 : int GetRasterXSize() const;
660 : int GetRasterYSize() const;
661 : int GetRasterCount() const;
662 : GDALRasterBand *GetRasterBand(int);
663 : const GDALRasterBand *GetRasterBand(int) const;
664 :
665 : /**
666 : * @brief SetQueryLoggerFunc
667 : * @param pfnQueryLoggerFuncIn query logger function callback
668 : * @param poQueryLoggerArgIn arguments passed to the query logger function
669 : * @return true on success
670 : */
671 : virtual bool SetQueryLoggerFunc(GDALQueryLoggerFunc pfnQueryLoggerFuncIn,
672 : void *poQueryLoggerArgIn);
673 :
674 : /** Class returned by GetBands() that act as a container for raster bands.
675 : */
676 : class CPL_DLL Bands
677 : {
678 : private:
679 : friend class GDALDataset;
680 : GDALDataset *m_poSelf;
681 :
682 7 : CPL_INTERNAL explicit Bands(GDALDataset *poSelf) : m_poSelf(poSelf)
683 : {
684 7 : }
685 :
686 6 : class CPL_DLL Iterator
687 : {
688 : struct Private;
689 : std::unique_ptr<Private> m_poPrivate;
690 :
691 : public:
692 : Iterator(GDALDataset *poDS, bool bStart);
693 : Iterator(const Iterator &oOther); // declared but not defined.
694 : // Needed for gcc 5.4 at least
695 : Iterator(Iterator &&oOther) noexcept; // declared but not defined.
696 : // Needed for gcc 5.4 at least
697 : ~Iterator();
698 : GDALRasterBand *operator*();
699 : Iterator &operator++();
700 : bool operator!=(const Iterator &it) const;
701 : };
702 :
703 : public:
704 : const Iterator begin() const;
705 :
706 : const Iterator end() const;
707 :
708 : size_t size() const;
709 :
710 : GDALRasterBand *operator[](int iBand);
711 : GDALRasterBand *operator[](size_t iBand);
712 : };
713 :
714 : Bands GetBands();
715 :
716 : virtual CPLErr FlushCache(bool bAtClosing = false);
717 : virtual CPLErr DropCache();
718 :
719 : virtual GIntBig GetEstimatedRAMUsage();
720 :
721 : virtual const OGRSpatialReference *GetSpatialRef() const;
722 : virtual CPLErr SetSpatialRef(const OGRSpatialReference *poSRS);
723 :
724 : // Compatibility layer
725 : const char *GetProjectionRef(void) const;
726 : CPLErr SetProjection(const char *pszProjection);
727 :
728 : virtual CPLErr GetGeoTransform(double *padfTransform);
729 : virtual CPLErr SetGeoTransform(double *padfTransform);
730 :
731 : CPLErr GeolocationToPixelLine(
732 : double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
733 : double *pdfPixel, double *pdfLine,
734 : CSLConstList papszTransformerOptions = nullptr) const;
735 :
736 : virtual CPLErr AddBand(GDALDataType eType, char **papszOptions = nullptr);
737 :
738 : virtual void *GetInternalHandle(const char *pszHandleName);
739 : virtual GDALDriver *GetDriver(void);
740 : virtual char **GetFileList(void);
741 :
742 : virtual const char *GetDriverName();
743 :
744 : virtual const OGRSpatialReference *GetGCPSpatialRef() const;
745 : virtual int GetGCPCount();
746 : virtual const GDAL_GCP *GetGCPs();
747 : virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
748 : const OGRSpatialReference *poGCP_SRS);
749 :
750 : // Compatibility layer
751 : const char *GetGCPProjection();
752 : CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
753 : const char *pszGCPProjection);
754 :
755 : virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
756 : int nBufXSize, int nBufYSize, GDALDataType eDT,
757 : int nBandCount, int *panBandList,
758 : char **papszOptions);
759 :
760 : virtual CPLErr CreateMaskBand(int nFlagsIn);
761 :
762 : virtual GDALAsyncReader *
763 : BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf,
764 : int nBufXSize, int nBufYSize, GDALDataType eBufType,
765 : int nBandCount, int *panBandMap, int nPixelSpace,
766 : int nLineSpace, int nBandSpace, char **papszOptions);
767 : virtual void EndAsyncReader(GDALAsyncReader *poARIO);
768 :
769 : //! @cond Doxygen_Suppress
770 : struct RawBinaryLayout
771 : {
772 : enum class Interleaving
773 : {
774 : UNKNOWN,
775 : BIP,
776 : BIL,
777 : BSQ
778 : };
779 : std::string osRawFilename{};
780 : Interleaving eInterleaving = Interleaving::UNKNOWN;
781 : GDALDataType eDataType = GDT_Unknown;
782 : bool bLittleEndianOrder = false;
783 :
784 : vsi_l_offset nImageOffset = 0;
785 : GIntBig nPixelOffset = 0;
786 : GIntBig nLineOffset = 0;
787 : GIntBig nBandOffset = 0;
788 : };
789 :
790 : virtual bool GetRawBinaryLayout(RawBinaryLayout &);
791 : //! @endcond
792 :
793 : #ifndef DOXYGEN_SKIP
794 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
795 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
796 : GDALDataType eBufType, int nBandCount,
797 : const int *panBandMap, GSpacing nPixelSpace,
798 : GSpacing nLineSpace, GSpacing nBandSpace,
799 : GDALRasterIOExtraArg *psExtraArg
800 : OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
801 : #else
802 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
803 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
804 : GDALDataType eBufType, int nBandCount,
805 : const int *panBandMap, GSpacing nPixelSpace,
806 : GSpacing nLineSpace, GSpacing nBandSpace,
807 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
808 : #endif
809 :
810 : virtual CPLStringList GetCompressionFormats(int nXOff, int nYOff,
811 : int nXSize, int nYSize,
812 : int nBandCount,
813 : const int *panBandList);
814 : virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
815 : int nYOff, int nXSize, int nYSize,
816 : int nBands, const int *panBandList,
817 : void **ppBuffer, size_t *pnBufferSize,
818 : char **ppszDetailedFormat);
819 :
820 : int Reference();
821 : int Dereference();
822 : int ReleaseRef();
823 :
824 : /** Return access mode.
825 : * @return access mode.
826 : */
827 112693 : GDALAccess GetAccess() const
828 : {
829 112693 : return eAccess;
830 : }
831 :
832 : int GetShared() const;
833 : void MarkAsShared();
834 :
835 : void MarkSuppressOnClose();
836 : void UnMarkSuppressOnClose();
837 :
838 : /** Return MarkSuppressOnClose flag.
839 : * @return MarkSuppressOnClose flag.
840 : */
841 3584632 : bool IsMarkedSuppressOnClose() const
842 : {
843 3584632 : return bSuppressOnClose;
844 : }
845 :
846 : /** Return open options.
847 : * @return open options.
848 : */
849 10346 : char **GetOpenOptions()
850 : {
851 10346 : return papszOpenOptions;
852 : }
853 :
854 : bool IsThreadSafe(int nScopeFlags) const;
855 :
856 : #ifndef DOXYGEN_SKIP
857 : /** Return open options.
858 : * @return open options.
859 : */
860 7 : CSLConstList GetOpenOptions() const
861 : {
862 7 : return papszOpenOptions;
863 : }
864 : #endif
865 :
866 : static GDALDataset **GetOpenDatasets(int *pnDatasetCount);
867 :
868 : #ifndef DOXYGEN_SKIP
869 : CPLErr
870 : BuildOverviews(const char *pszResampling, int nOverviews,
871 : const int *panOverviewList, int nListBands,
872 : const int *panBandList, GDALProgressFunc pfnProgress,
873 : void *pProgressData,
874 : CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(nullptr));
875 : #else
876 : CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
877 : const int *panOverviewList, int nListBands,
878 : const int *panBandList, GDALProgressFunc pfnProgress,
879 : void *pProgressData, CSLConstList papszOptions);
880 : #endif
881 :
882 : #ifndef DOXYGEN_XML
883 : void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
884 : ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
885 :
886 : static void ReportError(const char *pszDSName, CPLErr eErrClass,
887 : CPLErrorNum err_no, const char *fmt, ...)
888 : CPL_PRINT_FUNC_FORMAT(4, 5);
889 : #endif
890 :
891 : char **GetMetadata(const char *pszDomain = "") override;
892 :
893 : // Only defined when Doxygen enabled
894 : #ifdef DOXYGEN_SKIP
895 : CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
896 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
897 : const char *pszDomain) override;
898 : #endif
899 :
900 : char **GetMetadataDomainList() override;
901 :
902 : virtual void ClearStatistics();
903 :
904 : /** Convert a GDALDataset* to a GDALDatasetH.
905 : * @since GDAL 2.3
906 : */
907 24999 : static inline GDALDatasetH ToHandle(GDALDataset *poDS)
908 : {
909 24999 : return static_cast<GDALDatasetH>(poDS);
910 : }
911 :
912 : /** Convert a GDALDatasetH to a GDALDataset*.
913 : * @since GDAL 2.3
914 : */
915 1359329 : static inline GDALDataset *FromHandle(GDALDatasetH hDS)
916 : {
917 1359329 : return static_cast<GDALDataset *>(hDS);
918 : }
919 :
920 : /** @see GDALOpenEx().
921 : * @since GDAL 2.3
922 : */
923 25334 : static GDALDataset *Open(const char *pszFilename,
924 : unsigned int nOpenFlags = 0,
925 : const char *const *papszAllowedDrivers = nullptr,
926 : const char *const *papszOpenOptions = nullptr,
927 : const char *const *papszSiblingFiles = nullptr)
928 : {
929 25334 : return FromHandle(GDALOpenEx(pszFilename, nOpenFlags,
930 : papszAllowedDrivers, papszOpenOptions,
931 25269 : papszSiblingFiles));
932 : }
933 :
934 : /** Object returned by GetFeatures() iterators */
935 : struct FeatureLayerPair
936 : {
937 : /** Unique pointer to a OGRFeature. */
938 : OGRFeatureUniquePtr feature{};
939 :
940 : /** Layer to which the feature belongs to. */
941 : OGRLayer *layer = nullptr;
942 : };
943 :
944 : //! @cond Doxygen_Suppress
945 : // SetEnableOverviews() only to be used by GDALOverviewDataset
946 : void SetEnableOverviews(bool bEnable);
947 :
948 : // Only to be used by driver's GetOverviewCount() method.
949 : bool AreOverviewsEnabled() const;
950 :
951 : static void ReportUpdateNotSupportedByDriver(const char *pszDriverName);
952 : //! @endcond
953 :
954 : private:
955 : class Private;
956 : Private *m_poPrivate;
957 :
958 : CPL_INTERNAL OGRLayer *BuildLayerFromSelectInfo(
959 : swq_select *psSelectInfo, OGRGeometry *poSpatialFilter,
960 : const char *pszDialect, swq_select_parse_options *poSelectParseOptions);
961 : CPLStringList oDerivedMetadataList{};
962 :
963 : public:
964 : virtual int GetLayerCount();
965 : virtual OGRLayer *GetLayer(int iLayer);
966 :
967 : virtual bool IsLayerPrivate(int iLayer) const;
968 :
969 : /** Class returned by GetLayers() that acts as a range of layers.
970 : * @since GDAL 2.3
971 : */
972 : class CPL_DLL Layers
973 : {
974 : private:
975 : friend class GDALDataset;
976 : GDALDataset *m_poSelf;
977 :
978 25 : CPL_INTERNAL explicit Layers(GDALDataset *poSelf) : m_poSelf(poSelf)
979 : {
980 25 : }
981 :
982 : public:
983 : /** Layer iterator.
984 : * @since GDAL 2.3
985 : */
986 58 : class CPL_DLL Iterator
987 : {
988 : struct Private;
989 : std::unique_ptr<Private> m_poPrivate;
990 :
991 : public:
992 : using value_type = OGRLayer *; /**< value_type */
993 : using reference = OGRLayer *; /**< reference */
994 : using difference_type = void; /**< difference_type */
995 : using pointer = void; /**< pointer */
996 : using iterator_category =
997 : std::input_iterator_tag; /**< iterator_category */
998 :
999 : Iterator(); /**< Default constructor */
1000 : Iterator(GDALDataset *poDS, bool bStart); /**< Constructor */
1001 : Iterator(const Iterator &oOther); /**< Copy constructor */
1002 : Iterator(Iterator &&oOther) noexcept; /**< Move constructor */
1003 : ~Iterator(); /**< Destructor */
1004 :
1005 : Iterator &
1006 : operator=(const Iterator &oOther); /**< Assignment operator */
1007 : Iterator &operator=(
1008 : Iterator &&oOther) noexcept; /**< Move assignment operator */
1009 :
1010 : OGRLayer *operator*() const; /**< Dereference operator */
1011 : Iterator &operator++(); /**< Pre-increment operator */
1012 : Iterator operator++(int); /**< Post-increment operator */
1013 : bool operator!=(const Iterator &it)
1014 : const; /**< Difference comparison operator */
1015 : };
1016 :
1017 : Iterator begin() const;
1018 : Iterator end() const;
1019 :
1020 : size_t size() const;
1021 :
1022 : OGRLayer *operator[](int iLayer);
1023 : OGRLayer *operator[](size_t iLayer);
1024 : OGRLayer *operator[](const char *pszLayername);
1025 : };
1026 :
1027 : Layers GetLayers();
1028 :
1029 : virtual OGRLayer *GetLayerByName(const char *);
1030 : virtual OGRErr DeleteLayer(int iLayer);
1031 :
1032 : virtual void ResetReading();
1033 : virtual OGRFeature *GetNextFeature(OGRLayer **ppoBelongingLayer,
1034 : double *pdfProgressPct,
1035 : GDALProgressFunc pfnProgress,
1036 : void *pProgressData);
1037 :
1038 : /** Class returned by GetFeatures() that act as a container for vector
1039 : * features. */
1040 : class CPL_DLL Features
1041 : {
1042 : private:
1043 : friend class GDALDataset;
1044 : GDALDataset *m_poSelf;
1045 :
1046 2 : CPL_INTERNAL explicit Features(GDALDataset *poSelf) : m_poSelf(poSelf)
1047 : {
1048 2 : }
1049 :
1050 4 : class CPL_DLL Iterator
1051 : {
1052 : struct Private;
1053 : std::unique_ptr<Private> m_poPrivate;
1054 :
1055 : public:
1056 : Iterator(GDALDataset *poDS, bool bStart);
1057 : Iterator(const Iterator &oOther); // declared but not defined.
1058 : // Needed for gcc 5.4 at least
1059 : Iterator(Iterator &&oOther) noexcept; // declared but not defined.
1060 : // Needed for gcc 5.4 at least
1061 : ~Iterator();
1062 : const FeatureLayerPair &operator*() const;
1063 : Iterator &operator++();
1064 : bool operator!=(const Iterator &it) const;
1065 : };
1066 :
1067 : public:
1068 : const Iterator begin() const;
1069 :
1070 : const Iterator end() const;
1071 : };
1072 :
1073 : Features GetFeatures();
1074 :
1075 : virtual int TestCapability(const char *);
1076 :
1077 : virtual std::vector<std::string>
1078 : GetFieldDomainNames(CSLConstList papszOptions = nullptr) const;
1079 :
1080 : virtual const OGRFieldDomain *GetFieldDomain(const std::string &name) const;
1081 :
1082 : virtual bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
1083 : std::string &failureReason);
1084 :
1085 : virtual bool DeleteFieldDomain(const std::string &name,
1086 : std::string &failureReason);
1087 :
1088 : virtual bool UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
1089 : std::string &failureReason);
1090 :
1091 : virtual std::vector<std::string>
1092 : GetRelationshipNames(CSLConstList papszOptions = nullptr) const;
1093 :
1094 : virtual const GDALRelationship *
1095 : GetRelationship(const std::string &name) const;
1096 :
1097 : virtual bool
1098 : AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
1099 : std::string &failureReason);
1100 :
1101 : virtual bool DeleteRelationship(const std::string &name,
1102 : std::string &failureReason);
1103 :
1104 : virtual bool
1105 : UpdateRelationship(std::unique_ptr<GDALRelationship> &&relationship,
1106 : std::string &failureReason);
1107 :
1108 : //! @cond Doxygen_Suppress
1109 : OGRLayer *CreateLayer(const char *pszName);
1110 :
1111 : OGRLayer *CreateLayer(const char *pszName, std::nullptr_t);
1112 : //! @endcond
1113 :
1114 : OGRLayer *CreateLayer(const char *pszName,
1115 : const OGRSpatialReference *poSpatialRef,
1116 : OGRwkbGeometryType eGType = wkbUnknown,
1117 : CSLConstList papszOptions = nullptr);
1118 :
1119 : OGRLayer *CreateLayer(const char *pszName,
1120 : const OGRGeomFieldDefn *poGeomFieldDefn,
1121 : CSLConstList papszOptions = nullptr);
1122 :
1123 : virtual OGRLayer *CopyLayer(OGRLayer *poSrcLayer, const char *pszNewName,
1124 : char **papszOptions = nullptr);
1125 :
1126 : virtual OGRStyleTable *GetStyleTable();
1127 : virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
1128 :
1129 : virtual void SetStyleTable(OGRStyleTable *poStyleTable);
1130 :
1131 : virtual OGRLayer *ExecuteSQL(const char *pszStatement,
1132 : OGRGeometry *poSpatialFilter,
1133 : const char *pszDialect);
1134 : virtual void ReleaseResultSet(OGRLayer *poResultsSet);
1135 : virtual OGRErr AbortSQL();
1136 :
1137 : int GetRefCount() const;
1138 : int GetSummaryRefCount() const;
1139 : OGRErr Release();
1140 :
1141 : virtual OGRErr StartTransaction(int bForce = FALSE);
1142 : virtual OGRErr CommitTransaction();
1143 : virtual OGRErr RollbackTransaction();
1144 :
1145 : virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
1146 :
1147 : //! @cond Doxygen_Suppress
1148 : static int IsGenericSQLDialect(const char *pszDialect);
1149 :
1150 : // Semi-public methods. Only to be used by in-tree drivers.
1151 : GDALSQLParseInfo *
1152 : BuildParseInfo(swq_select *psSelectInfo,
1153 : swq_select_parse_options *poSelectParseOptions);
1154 : static void DestroyParseInfo(GDALSQLParseInfo *psParseInfo);
1155 : OGRLayer *ExecuteSQL(const char *pszStatement, OGRGeometry *poSpatialFilter,
1156 : const char *pszDialect,
1157 : swq_select_parse_options *poSelectParseOptions);
1158 : //! @endcond
1159 :
1160 : protected:
1161 : virtual OGRLayer *ICreateLayer(const char *pszName,
1162 : const OGRGeomFieldDefn *poGeomFieldDefn,
1163 : CSLConstList papszOptions);
1164 :
1165 : //! @cond Doxygen_Suppress
1166 : OGRErr ProcessSQLCreateIndex(const char *);
1167 : OGRErr ProcessSQLDropIndex(const char *);
1168 : OGRErr ProcessSQLDropTable(const char *);
1169 : OGRErr ProcessSQLAlterTableAddColumn(const char *);
1170 : OGRErr ProcessSQLAlterTableDropColumn(const char *);
1171 : OGRErr ProcessSQLAlterTableAlterColumn(const char *);
1172 : OGRErr ProcessSQLAlterTableRenameColumn(const char *);
1173 :
1174 : OGRStyleTable *m_poStyleTable = nullptr;
1175 :
1176 : friend class GDALProxyPoolDataset;
1177 : //! @endcond
1178 :
1179 : private:
1180 : CPL_DISALLOW_COPY_ASSIGN(GDALDataset)
1181 : };
1182 :
1183 : //! @cond Doxygen_Suppress
1184 : struct CPL_DLL GDALDatasetUniquePtrDeleter
1185 : {
1186 74 : void operator()(GDALDataset *poDataset) const
1187 : {
1188 74 : GDALClose(poDataset);
1189 74 : }
1190 : };
1191 :
1192 : //! @endcond
1193 :
1194 : //! @cond Doxygen_Suppress
1195 : struct CPL_DLL GDALDatasetUniquePtrReleaser
1196 : {
1197 516 : void operator()(GDALDataset *poDataset) const
1198 : {
1199 516 : if (poDataset)
1200 513 : poDataset->Release();
1201 516 : }
1202 : };
1203 :
1204 : //! @endcond
1205 :
1206 : /** Unique pointer type for GDALDataset.
1207 : * Appropriate for use on datasets open in non-shared mode and onto which
1208 : * reference counter has not been manually modified.
1209 : * @since GDAL 2.3
1210 : */
1211 : using GDALDatasetUniquePtr =
1212 : std::unique_ptr<GDALDataset, GDALDatasetUniquePtrDeleter>;
1213 :
1214 : /* ******************************************************************** */
1215 : /* GDALRasterBlock */
1216 : /* ******************************************************************** */
1217 :
1218 : /** A single raster block in the block cache.
1219 : *
1220 : * And the global block manager that manages a least-recently-used list of
1221 : * blocks from various datasets/bands */
1222 : class CPL_DLL GDALRasterBlock
1223 : {
1224 : friend class GDALAbstractBandBlockCache;
1225 :
1226 : GDALDataType eType;
1227 :
1228 : bool bDirty;
1229 : volatile int nLockCount;
1230 :
1231 : int nXOff;
1232 : int nYOff;
1233 :
1234 : int nXSize;
1235 : int nYSize;
1236 :
1237 : void *pData;
1238 :
1239 : GDALRasterBand *poBand;
1240 :
1241 : GDALRasterBlock *poNext;
1242 : GDALRasterBlock *poPrevious;
1243 :
1244 : bool bMustDetach;
1245 :
1246 : CPL_INTERNAL void Detach_unlocked(void);
1247 : CPL_INTERNAL void Touch_unlocked(void);
1248 :
1249 : CPL_INTERNAL void RecycleFor(int nXOffIn, int nYOffIn);
1250 :
1251 : public:
1252 : GDALRasterBlock(GDALRasterBand *, int, int);
1253 : GDALRasterBlock(int nXOffIn, int nYOffIn); /* only for lookup purpose */
1254 : virtual ~GDALRasterBlock();
1255 :
1256 : CPLErr Internalize(void);
1257 : void Touch(void);
1258 : void MarkDirty(void);
1259 : void MarkClean(void);
1260 :
1261 : /** Increment the lock count */
1262 9874310 : int AddLock(void)
1263 : {
1264 9874310 : return CPLAtomicInc(&nLockCount);
1265 : }
1266 :
1267 : /** Decrement the lock count */
1268 9876181 : int DropLock(void)
1269 : {
1270 9876181 : return CPLAtomicDec(&nLockCount);
1271 : }
1272 :
1273 : void Detach();
1274 :
1275 : CPLErr Write();
1276 :
1277 : /** Return the data type
1278 : * @return data type
1279 : */
1280 19502 : GDALDataType GetDataType() const
1281 : {
1282 19502 : return eType;
1283 : }
1284 :
1285 : /** Return the x offset of the top-left corner of the block
1286 : * @return x offset
1287 : */
1288 12122400 : int GetXOff() const
1289 : {
1290 12122400 : return nXOff;
1291 : }
1292 :
1293 : /** Return the y offset of the top-left corner of the block
1294 : * @return y offset
1295 : */
1296 482960000 : int GetYOff() const
1297 : {
1298 482960000 : return nYOff;
1299 : }
1300 :
1301 : /** Return the width of the block
1302 : * @return width
1303 : */
1304 : int GetXSize() const
1305 : {
1306 : return nXSize;
1307 : }
1308 :
1309 : /** Return the height of the block
1310 : * @return height
1311 : */
1312 : int GetYSize() const
1313 : {
1314 : return nYSize;
1315 : }
1316 :
1317 : /** Return the dirty flag
1318 : * @return dirty flag
1319 : */
1320 3690880 : int GetDirty() const
1321 : {
1322 3690880 : return bDirty;
1323 : }
1324 :
1325 : /** Return the data buffer
1326 : * @return data buffer
1327 : */
1328 13045469 : void *GetDataRef(void)
1329 : {
1330 13045469 : return pData;
1331 : }
1332 :
1333 : /** Return the block size in bytes
1334 : * @return block size.
1335 : */
1336 6342730 : GPtrDiff_t GetBlockSize() const
1337 : {
1338 6342730 : return static_cast<GPtrDiff_t>(nXSize) * nYSize *
1339 6342730 : GDALGetDataTypeSizeBytes(eType);
1340 : }
1341 :
1342 : int TakeLock();
1343 : int DropLockForRemovalFromStorage();
1344 :
1345 : /// @brief Accessor to source GDALRasterBand object.
1346 : /// @return source raster band of the raster block.
1347 59234 : GDALRasterBand *GetBand()
1348 : {
1349 59234 : return poBand;
1350 : }
1351 :
1352 : static void FlushDirtyBlocks();
1353 : static int FlushCacheBlock(int bDirtyBlocksOnly = FALSE);
1354 : static void Verify();
1355 :
1356 : static void EnterDisableDirtyBlockFlush();
1357 : static void LeaveDisableDirtyBlockFlush();
1358 :
1359 : #ifdef notdef
1360 : static void CheckNonOrphanedBlocks(GDALRasterBand *poBand);
1361 : void DumpBlock();
1362 : static void DumpAll();
1363 : #endif
1364 :
1365 : /* Should only be called by GDALDestroyDriverManager() */
1366 : //! @cond Doxygen_Suppress
1367 : CPL_INTERNAL static void DestroyRBMutex();
1368 : //! @endcond
1369 :
1370 : private:
1371 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBlock)
1372 : };
1373 :
1374 : /* ******************************************************************** */
1375 : /* GDALColorTable */
1376 : /* ******************************************************************** */
1377 :
1378 : /** A color table / palette. */
1379 :
1380 2078 : class CPL_DLL GDALColorTable
1381 : {
1382 : GDALPaletteInterp eInterp;
1383 :
1384 : std::vector<GDALColorEntry> aoEntries{};
1385 :
1386 : public:
1387 : explicit GDALColorTable(GDALPaletteInterp = GPI_RGB);
1388 : ~GDALColorTable();
1389 :
1390 : GDALColorTable *Clone() const;
1391 : int IsSame(const GDALColorTable *poOtherCT) const;
1392 :
1393 : GDALPaletteInterp GetPaletteInterpretation() const;
1394 :
1395 : int GetColorEntryCount() const;
1396 : const GDALColorEntry *GetColorEntry(int i) const;
1397 : int GetColorEntryAsRGB(int i, GDALColorEntry *poEntry) const;
1398 : void SetColorEntry(int i, const GDALColorEntry *poEntry);
1399 : int CreateColorRamp(int nStartIndex, const GDALColorEntry *psStartColor,
1400 : int nEndIndex, const GDALColorEntry *psEndColor);
1401 : bool IsIdentity() const;
1402 :
1403 : /** Convert a GDALColorTable* to a GDALRasterBandH.
1404 : * @since GDAL 2.3
1405 : */
1406 1921 : static inline GDALColorTableH ToHandle(GDALColorTable *poCT)
1407 : {
1408 1921 : return static_cast<GDALColorTableH>(poCT);
1409 : }
1410 :
1411 : /** Convert a GDALColorTableH to a GDALColorTable*.
1412 : * @since GDAL 2.3
1413 : */
1414 14485 : static inline GDALColorTable *FromHandle(GDALColorTableH hCT)
1415 : {
1416 14485 : return static_cast<GDALColorTable *>(hCT);
1417 : }
1418 : };
1419 :
1420 : /* ******************************************************************** */
1421 : /* GDALAbstractBandBlockCache */
1422 : /* ******************************************************************** */
1423 :
1424 : //! @cond Doxygen_Suppress
1425 :
1426 : //! This manages how a raster band store its cached block.
1427 : // only used by GDALRasterBand implementation.
1428 :
1429 : class GDALAbstractBandBlockCache
1430 : {
1431 : // List of blocks that can be freed or recycled, and its lock
1432 : CPLLock *hSpinLock = nullptr;
1433 : GDALRasterBlock *psListBlocksToFree = nullptr;
1434 :
1435 : // Band keep alive counter, and its lock & condition
1436 : CPLCond *hCond = nullptr;
1437 : CPLMutex *hCondMutex = nullptr;
1438 : volatile int nKeepAliveCounter = 0;
1439 :
1440 : volatile int m_nDirtyBlocks = 0;
1441 :
1442 : CPL_DISALLOW_COPY_ASSIGN(GDALAbstractBandBlockCache)
1443 :
1444 : protected:
1445 : GDALRasterBand *poBand;
1446 :
1447 : int m_nInitialDirtyBlocksInFlushCache = 0;
1448 : int m_nLastTick = -1;
1449 : size_t m_nWriteDirtyBlocksDisabled = 0;
1450 :
1451 : void FreeDanglingBlocks();
1452 : void UnreferenceBlockBase();
1453 :
1454 : void StartDirtyBlockFlushingLog();
1455 : void UpdateDirtyBlockFlushingLog();
1456 : void EndDirtyBlockFlushingLog();
1457 :
1458 : public:
1459 : explicit GDALAbstractBandBlockCache(GDALRasterBand *poBand);
1460 : virtual ~GDALAbstractBandBlockCache();
1461 :
1462 : GDALRasterBlock *CreateBlock(int nXBlockOff, int nYBlockOff);
1463 : void AddBlockToFreeList(GDALRasterBlock *poBlock);
1464 : void IncDirtyBlocks(int nInc);
1465 : void WaitCompletionPendingTasks();
1466 :
1467 1 : void EnableDirtyBlockWriting()
1468 : {
1469 1 : --m_nWriteDirtyBlocksDisabled;
1470 1 : }
1471 :
1472 2487 : void DisableDirtyBlockWriting()
1473 : {
1474 2487 : ++m_nWriteDirtyBlocksDisabled;
1475 2487 : }
1476 :
1477 0 : bool HasDirtyBlocks() const
1478 : {
1479 0 : return m_nDirtyBlocks > 0;
1480 : }
1481 :
1482 : virtual bool Init() = 0;
1483 : virtual bool IsInitOK() = 0;
1484 : virtual CPLErr FlushCache() = 0;
1485 : virtual CPLErr AdoptBlock(GDALRasterBlock *poBlock) = 0;
1486 : virtual GDALRasterBlock *TryGetLockedBlockRef(int nXBlockOff,
1487 : int nYBlockYOff) = 0;
1488 : virtual CPLErr UnreferenceBlock(GDALRasterBlock *poBlock) = 0;
1489 : virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
1490 : int bWriteDirtyBlock) = 0;
1491 : };
1492 :
1493 : GDALAbstractBandBlockCache *
1494 : GDALArrayBandBlockCacheCreate(GDALRasterBand *poBand);
1495 : GDALAbstractBandBlockCache *
1496 : GDALHashSetBandBlockCacheCreate(GDALRasterBand *poBand);
1497 :
1498 : //! @endcond
1499 :
1500 : /* ******************************************************************** */
1501 : /* GDALRasterBand */
1502 : /* ******************************************************************** */
1503 :
1504 : class GDALMDArray;
1505 : class GDALDoublePointsCache;
1506 :
1507 : /** Range of values found in a mask band */
1508 : typedef enum
1509 : {
1510 : GMVR_UNKNOWN, /*! Unknown (can also be used for any values between 0 and 255
1511 : for a Byte band) */
1512 : GMVR_0_AND_1_ONLY, /*! Only 0 and 1 */
1513 : GMVR_0_AND_255_ONLY, /*! Only 0 and 255 */
1514 : } GDALMaskValueRange;
1515 :
1516 : /** Suggested/most efficient access pattern to blocks. */
1517 : typedef int GDALSuggestedBlockAccessPattern;
1518 :
1519 : /** Unknown, or no particular read order is suggested. */
1520 : constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
1521 :
1522 : /** Random access to blocks is efficient. */
1523 : constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
1524 :
1525 : /** Reading by strips from top to bottom is the most efficient. */
1526 : constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
1527 :
1528 : /** Reading by strips from bottom to top is the most efficient. */
1529 : constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
1530 :
1531 : /** Reading the largest chunk from the raster is the most efficient (can be
1532 : * combined with above values). */
1533 : constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
1534 :
1535 : /** A single raster band (or channel). */
1536 :
1537 : class CPL_DLL GDALRasterBand : public GDALMajorObject
1538 : {
1539 : private:
1540 : friend class GDALArrayBandBlockCache;
1541 : friend class GDALHashSetBandBlockCache;
1542 : friend class GDALRasterBlock;
1543 : friend class GDALDataset;
1544 :
1545 : CPLErr eFlushBlockErr = CE_None;
1546 : GDALAbstractBandBlockCache *poBandBlockCache = nullptr;
1547 :
1548 : CPL_INTERNAL void SetFlushBlockErr(CPLErr eErr);
1549 : CPL_INTERNAL CPLErr UnreferenceBlock(GDALRasterBlock *poBlock);
1550 : CPL_INTERNAL void IncDirtyBlocks(int nInc);
1551 :
1552 : protected:
1553 : //! @cond Doxygen_Suppress
1554 : GDALDataset *poDS = nullptr;
1555 : int nBand = 0; /* 1 based */
1556 :
1557 : int nRasterXSize = 0;
1558 : int nRasterYSize = 0;
1559 :
1560 : GDALDataType eDataType = GDT_Byte;
1561 : GDALAccess eAccess = GA_ReadOnly;
1562 :
1563 : /* stuff related to blocking, and raster cache */
1564 : int nBlockXSize = -1;
1565 : int nBlockYSize = -1;
1566 : int nBlocksPerRow = 0;
1567 : int nBlocksPerColumn = 0;
1568 :
1569 : int nBlockReads = 0;
1570 : int bForceCachedIO = 0;
1571 :
1572 : class GDALRasterBandOwnedOrNot
1573 : {
1574 : public:
1575 1201220 : GDALRasterBandOwnedOrNot()
1576 1201220 : {
1577 1200990 : }
1578 :
1579 : GDALRasterBandOwnedOrNot(GDALRasterBand *poBand, bool bOwned)
1580 : : m_poBandOwned(bOwned ? poBand : nullptr),
1581 : m_poBandRef(bOwned ? nullptr : poBand)
1582 : {
1583 : }
1584 :
1585 1201370 : void reset()
1586 : {
1587 1201370 : m_poBandOwned.reset();
1588 1201350 : m_poBandRef = nullptr;
1589 1201350 : }
1590 :
1591 28307 : void reset(GDALRasterBand *poBand, bool bOwned)
1592 : {
1593 28307 : m_poBandOwned.reset(bOwned ? poBand : nullptr);
1594 28306 : m_poBandRef = bOwned ? nullptr : poBand;
1595 28306 : }
1596 :
1597 66847 : void reset(std::unique_ptr<GDALRasterBand> poBand)
1598 : {
1599 66847 : m_poBandOwned = std::move(poBand);
1600 66847 : m_poBandRef = nullptr;
1601 66847 : }
1602 :
1603 2 : const GDALRasterBand *get() const
1604 : {
1605 2 : return static_cast<const GDALRasterBand *>(*this);
1606 : }
1607 :
1608 1363520 : GDALRasterBand *get()
1609 : {
1610 1363520 : return static_cast<GDALRasterBand *>(*this);
1611 : }
1612 :
1613 707453 : bool IsOwned() const
1614 : {
1615 707453 : return m_poBandOwned != nullptr;
1616 : }
1617 :
1618 2 : operator const GDALRasterBand *() const
1619 : {
1620 2 : return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
1621 : }
1622 :
1623 2897300 : operator GDALRasterBand *()
1624 : {
1625 2897300 : return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
1626 : }
1627 :
1628 : private:
1629 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBandOwnedOrNot)
1630 : std::unique_ptr<GDALRasterBand> m_poBandOwned{};
1631 : GDALRasterBand *m_poBandRef = nullptr;
1632 : };
1633 :
1634 : GDALRasterBandOwnedOrNot poMask{};
1635 : bool m_bEnablePixelTypeSignedByteWarning =
1636 : true; // Remove me in GDAL 4.0. See GetMetadataItem() implementation
1637 : int nMaskFlags = 0;
1638 :
1639 : void InvalidateMaskBand();
1640 :
1641 : friend class GDALProxyRasterBand;
1642 : friend class GDALDefaultOverviews;
1643 :
1644 : CPLErr
1645 : RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1646 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
1647 : GDALDataType eBufType, GSpacing nPixelSpace,
1648 : GSpacing nLineSpace,
1649 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
1650 :
1651 : int EnterReadWrite(GDALRWFlag eRWFlag);
1652 : void LeaveReadWrite();
1653 : void InitRWLock();
1654 : void SetValidPercent(GUIntBig nSampleCount, GUIntBig nValidCount);
1655 :
1656 : mutable GDALDoublePointsCache *m_poPointsCache = nullptr;
1657 :
1658 : //! @endcond
1659 :
1660 : protected:
1661 : virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData) = 0;
1662 : virtual CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pData);
1663 :
1664 : virtual CPLErr
1665 : IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
1666 : void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
1667 : GSpacing nPixelSpace, GSpacing nLineSpace,
1668 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
1669 :
1670 : virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize,
1671 : int nYSize, int nMaskFlagStop,
1672 : double *pdfDataPct);
1673 : //! @cond Doxygen_Suppress
1674 : CPLErr
1675 : OverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1676 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
1677 : GDALDataType eBufType, GSpacing nPixelSpace,
1678 : GSpacing nLineSpace,
1679 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
1680 :
1681 : CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
1682 : int nXSize, int nYSize, void *pData,
1683 : int nBufXSize, int nBufYSize,
1684 : GDALDataType eBufType, GSpacing nPixelSpace,
1685 : GSpacing nLineSpace,
1686 : GDALRasterIOExtraArg *psExtraArg, int *pbTried);
1687 :
1688 : int InitBlockInfo();
1689 :
1690 : void AddBlockToFreeList(GDALRasterBlock *);
1691 :
1692 2101540 : bool HasBlockCache() const
1693 : {
1694 2101540 : return poBandBlockCache != nullptr;
1695 : }
1696 :
1697 17 : bool HasDirtyBlocks() const
1698 : {
1699 17 : return poBandBlockCache && poBandBlockCache->HasDirtyBlocks();
1700 : }
1701 :
1702 : //! @endcond
1703 :
1704 : public:
1705 : GDALRasterBand();
1706 : explicit GDALRasterBand(int bForceCachedIO);
1707 :
1708 : ~GDALRasterBand() override;
1709 :
1710 : int GetXSize() const;
1711 : int GetYSize() const;
1712 : int GetBand() const;
1713 : GDALDataset *GetDataset() const;
1714 :
1715 : GDALDataType GetRasterDataType(void) const;
1716 : void GetBlockSize(int *pnXSize, int *pnYSize) const;
1717 : CPLErr GetActualBlockSize(int nXBlockOff, int nYBlockOff, int *pnXValid,
1718 : int *pnYValid) const;
1719 :
1720 : virtual GDALSuggestedBlockAccessPattern
1721 : GetSuggestedBlockAccessPattern() const;
1722 :
1723 : GDALAccess GetAccess();
1724 :
1725 : #ifndef DOXYGEN_SKIP
1726 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1727 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
1728 : GDALDataType eBufType, GSpacing nPixelSpace,
1729 : GSpacing nLineSpace,
1730 : GDALRasterIOExtraArg *psExtraArg
1731 : OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
1732 : #else
1733 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1734 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
1735 : GDALDataType eBufType, GSpacing nPixelSpace,
1736 : GSpacing nLineSpace,
1737 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
1738 : #endif
1739 :
1740 : template <class T>
1741 : CPLErr ReadRaster(T *pData, size_t nArrayEltCount = 0, double dfXOff = 0,
1742 : double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
1743 : size_t nBufXSize = 0, size_t nBufYSize = 0,
1744 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
1745 : GDALProgressFunc pfnProgress = nullptr,
1746 : void *pProgressData = nullptr) const;
1747 :
1748 : template <class T>
1749 : CPLErr ReadRaster(std::vector<T> &vData, double dfXOff = 0,
1750 : double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
1751 : size_t nBufXSize = 0, size_t nBufYSize = 0,
1752 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
1753 : GDALProgressFunc pfnProgress = nullptr,
1754 : void *pProgressData = nullptr) const;
1755 :
1756 : #if __cplusplus >= 202002L
1757 : //! @cond Doxygen_Suppress
1758 : template <class T>
1759 : inline CPLErr
1760 : ReadRaster(std::span<T> pData, double dfXOff = 0, double dfYOff = 0,
1761 : double dfXSize = 0, double dfYSize = 0, size_t nBufXSize = 0,
1762 : size_t nBufYSize = 0,
1763 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
1764 : GDALProgressFunc pfnProgress = nullptr,
1765 : void *pProgressData = nullptr) const
1766 : {
1767 : return ReadRaster(pData.data(), pData.size(), dfXOff, dfYOff, dfXSize,
1768 : dfYSize, nBufXSize, nBufYSize, eResampleAlg,
1769 : pfnProgress, pProgressData);
1770 : }
1771 :
1772 : //! @endcond
1773 : #endif
1774 :
1775 : CPLErr ReadBlock(int nXBlockOff, int nYBlockOff,
1776 : void *pImage) CPL_WARN_UNUSED_RESULT;
1777 :
1778 : CPLErr WriteBlock(int nXBlockOff, int nYBlockOff,
1779 : void *pImage) CPL_WARN_UNUSED_RESULT;
1780 :
1781 : // This method should only be overloaded by GDALProxyRasterBand
1782 : virtual GDALRasterBlock *
1783 : GetLockedBlockRef(int nXBlockOff, int nYBlockOff,
1784 : int bJustInitialize = FALSE) CPL_WARN_UNUSED_RESULT;
1785 :
1786 : // This method should only be overloaded by GDALProxyRasterBand
1787 : virtual GDALRasterBlock *
1788 : TryGetLockedBlockRef(int nXBlockOff,
1789 : int nYBlockYOff) CPL_WARN_UNUSED_RESULT;
1790 :
1791 : // This method should only be overloaded by GDALProxyRasterBand
1792 : virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
1793 : int bWriteDirtyBlock = TRUE);
1794 :
1795 : unsigned char *
1796 : GetIndexColorTranslationTo(/* const */ GDALRasterBand *poReferenceBand,
1797 : unsigned char *pTranslationTable = nullptr,
1798 : int *pApproximateMatching = nullptr);
1799 :
1800 : // New OpengIS CV_SampleDimension stuff.
1801 :
1802 : virtual CPLErr FlushCache(bool bAtClosing = false);
1803 : virtual CPLErr DropCache();
1804 : virtual char **GetCategoryNames();
1805 : virtual double GetNoDataValue(int *pbSuccess = nullptr);
1806 : virtual int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr);
1807 : virtual uint64_t GetNoDataValueAsUInt64(int *pbSuccess = nullptr);
1808 : virtual double GetMinimum(int *pbSuccess = nullptr);
1809 : virtual double GetMaximum(int *pbSuccess = nullptr);
1810 : virtual double GetOffset(int *pbSuccess = nullptr);
1811 : virtual double GetScale(int *pbSuccess = nullptr);
1812 : virtual const char *GetUnitType();
1813 : virtual GDALColorInterp GetColorInterpretation();
1814 : virtual GDALColorTable *GetColorTable();
1815 : virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
1816 :
1817 : virtual CPLErr SetCategoryNames(char **papszNames);
1818 : virtual CPLErr SetNoDataValue(double dfNoData);
1819 : virtual CPLErr SetNoDataValueAsInt64(int64_t nNoData);
1820 : virtual CPLErr SetNoDataValueAsUInt64(uint64_t nNoData);
1821 : virtual CPLErr DeleteNoDataValue();
1822 : virtual CPLErr SetColorTable(GDALColorTable *poCT);
1823 : virtual CPLErr SetColorInterpretation(GDALColorInterp eColorInterp);
1824 : virtual CPLErr SetOffset(double dfNewOffset);
1825 : virtual CPLErr SetScale(double dfNewScale);
1826 : virtual CPLErr SetUnitType(const char *pszNewValue);
1827 :
1828 : virtual CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
1829 : double *pdfMax, double *pdfMean,
1830 : double *padfStdDev);
1831 : virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
1832 : double *pdfMax, double *pdfMean,
1833 : double *pdfStdDev, GDALProgressFunc,
1834 : void *pProgressData);
1835 : virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
1836 : double dfStdDev);
1837 : virtual CPLErr ComputeRasterMinMax(int bApproxOK, double *adfMinMax);
1838 : virtual CPLErr ComputeRasterMinMaxLocation(double *pdfMin, double *pdfMax,
1839 : int *pnMinX, int *pnMinY,
1840 : int *pnMaxX, int *pnMaxY);
1841 :
1842 : // Only defined when Doxygen enabled
1843 : #ifdef DOXYGEN_SKIP
1844 : CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
1845 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
1846 : const char *pszDomain) override;
1847 : #endif
1848 : virtual const char *GetMetadataItem(const char *pszName,
1849 : const char *pszDomain = "") override;
1850 :
1851 : virtual int HasArbitraryOverviews();
1852 : virtual int GetOverviewCount();
1853 : virtual GDALRasterBand *GetOverview(int i);
1854 : virtual GDALRasterBand *GetRasterSampleOverview(GUIntBig);
1855 : virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
1856 : const int *panOverviewList,
1857 : GDALProgressFunc pfnProgress,
1858 : void *pProgressData,
1859 : CSLConstList papszOptions);
1860 :
1861 : virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
1862 : int nBufXSize, int nBufYSize,
1863 : GDALDataType eBufType, char **papszOptions);
1864 :
1865 : virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
1866 : GUIntBig *panHistogram, int bIncludeOutOfRange,
1867 : int bApproxOK, GDALProgressFunc,
1868 : void *pProgressData);
1869 :
1870 : virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax,
1871 : int *pnBuckets, GUIntBig **ppanHistogram,
1872 : int bForce, GDALProgressFunc,
1873 : void *pProgressData);
1874 : virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
1875 : GUIntBig *panHistogram);
1876 :
1877 : virtual GDALRasterAttributeTable *GetDefaultRAT();
1878 : virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT);
1879 :
1880 : virtual GDALRasterBand *GetMaskBand();
1881 : virtual int GetMaskFlags();
1882 : virtual CPLErr CreateMaskBand(int nFlagsIn);
1883 : virtual bool IsMaskBand() const;
1884 : virtual GDALMaskValueRange GetMaskValueRange() const;
1885 :
1886 : virtual CPLVirtualMem *
1887 : GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
1888 : GIntBig *pnLineSpace,
1889 : char **papszOptions) CPL_WARN_UNUSED_RESULT;
1890 :
1891 : int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
1892 : int nMaskFlagStop = 0,
1893 : double *pdfDataPct = nullptr);
1894 :
1895 : std::shared_ptr<GDALMDArray> AsMDArray() const;
1896 :
1897 : CPLErr InterpolateAtGeolocation(
1898 : double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
1899 : GDALRIOResampleAlg eInterpolation, double *pdfRealValue,
1900 : double *pdfImagValue = nullptr,
1901 : CSLConstList papszTransformerOptions = nullptr) const;
1902 :
1903 : virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
1904 : GDALRIOResampleAlg eInterpolation,
1905 : double *pdfRealValue,
1906 : double *pdfImagValue = nullptr) const;
1907 :
1908 : #ifndef DOXYGEN_XML
1909 : void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
1910 : ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
1911 : #endif
1912 :
1913 : /** Convert a GDALRasterBand* to a GDALRasterBandH.
1914 : * @since GDAL 2.3
1915 : */
1916 313889 : static inline GDALRasterBandH ToHandle(GDALRasterBand *poBand)
1917 : {
1918 313889 : return static_cast<GDALRasterBandH>(poBand);
1919 : }
1920 :
1921 : /** Convert a GDALRasterBandH to a GDALRasterBand*.
1922 : * @since GDAL 2.3
1923 : */
1924 5189288 : static inline GDALRasterBand *FromHandle(GDALRasterBandH hBand)
1925 : {
1926 5189288 : return static_cast<GDALRasterBand *>(hBand);
1927 : }
1928 :
1929 : //! @cond Doxygen_Suppress
1930 : // Remove me in GDAL 4.0. See GetMetadataItem() implementation
1931 : // Internal use in GDAL only !
1932 : virtual void EnablePixelTypeSignedByteWarning(bool b)
1933 : #ifndef GDAL_COMPILATION
1934 : CPL_WARN_DEPRECATED("Do not use that method outside of GDAL!")
1935 : #endif
1936 : ;
1937 :
1938 : //! @endcond
1939 :
1940 : private:
1941 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBand)
1942 : };
1943 :
1944 : //! @cond Doxygen_Suppress
1945 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
1946 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
1947 : T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
1948 : double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
1949 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
1950 : void *pProgressData) const;
1951 :
1952 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
1953 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
1954 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
1955 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
1956 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
1957 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
1958 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
1959 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
1960 : GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
1961 : GDAL_EXTERN_TEMPLATE_READ_RASTER(double)
1962 : // Not allowed by C++ standard
1963 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int16_t>)
1964 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int32_t>)
1965 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
1966 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
1967 :
1968 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
1969 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
1970 : std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
1971 : double dfYSize, size_t nBufXSize, size_t nBufYSize, \
1972 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
1973 : void *pProgressData) const;
1974 :
1975 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
1976 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
1977 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
1978 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
1979 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
1980 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
1981 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
1982 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
1983 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
1984 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(double)
1985 : // Not allowed by C++ standard
1986 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int16_t>)
1987 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int32_t>)
1988 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
1989 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
1990 :
1991 : //! @endcond
1992 :
1993 : //! @cond Doxygen_Suppress
1994 : /* ******************************************************************** */
1995 : /* GDALAllValidMaskBand */
1996 : /* ******************************************************************** */
1997 :
1998 184654 : class CPL_DLL GDALAllValidMaskBand : public GDALRasterBand
1999 : {
2000 : protected:
2001 : CPLErr IReadBlock(int, int, void *) override;
2002 :
2003 : CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
2004 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
2005 : GDALDataType eBufType, GSpacing nPixelSpace,
2006 : GSpacing nLineSpace,
2007 : GDALRasterIOExtraArg *psExtraArg) override;
2008 :
2009 : CPL_DISALLOW_COPY_ASSIGN(GDALAllValidMaskBand)
2010 :
2011 : public:
2012 : explicit GDALAllValidMaskBand(GDALRasterBand *);
2013 : ~GDALAllValidMaskBand() override;
2014 :
2015 : GDALRasterBand *GetMaskBand() override;
2016 : int GetMaskFlags() override;
2017 :
2018 1 : bool IsMaskBand() const override
2019 : {
2020 1 : return true;
2021 : }
2022 :
2023 0 : GDALMaskValueRange GetMaskValueRange() const override
2024 : {
2025 0 : return GMVR_0_AND_255_ONLY;
2026 : }
2027 :
2028 : CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
2029 : double *pdfMean, double *pdfStdDev,
2030 : GDALProgressFunc, void *pProgressData) override;
2031 : };
2032 :
2033 : /* ******************************************************************** */
2034 : /* GDALNoDataMaskBand */
2035 : /* ******************************************************************** */
2036 :
2037 1742 : class CPL_DLL GDALNoDataMaskBand : public GDALRasterBand
2038 : {
2039 : friend class GDALRasterBand;
2040 : double m_dfNoDataValue = 0;
2041 : int64_t m_nNoDataValueInt64 = 0;
2042 : uint64_t m_nNoDataValueUInt64 = 0;
2043 : GDALRasterBand *m_poParent = nullptr;
2044 :
2045 : CPL_DISALLOW_COPY_ASSIGN(GDALNoDataMaskBand)
2046 :
2047 : protected:
2048 : CPLErr IReadBlock(int, int, void *) override;
2049 : CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
2050 : GDALDataType, GSpacing, GSpacing,
2051 : GDALRasterIOExtraArg *psExtraArg) override;
2052 :
2053 : public:
2054 : explicit GDALNoDataMaskBand(GDALRasterBand *);
2055 : explicit GDALNoDataMaskBand(GDALRasterBand *, double dfNoDataValue);
2056 : ~GDALNoDataMaskBand() override;
2057 :
2058 1 : bool IsMaskBand() const override
2059 : {
2060 1 : return true;
2061 : }
2062 :
2063 0 : GDALMaskValueRange GetMaskValueRange() const override
2064 : {
2065 0 : return GMVR_0_AND_255_ONLY;
2066 : }
2067 :
2068 : static bool IsNoDataInRange(double dfNoDataValue, GDALDataType eDataType);
2069 : };
2070 :
2071 : /* ******************************************************************** */
2072 : /* GDALNoDataValuesMaskBand */
2073 : /* ******************************************************************** */
2074 :
2075 : class CPL_DLL GDALNoDataValuesMaskBand : public GDALRasterBand
2076 : {
2077 : double *padfNodataValues;
2078 :
2079 : CPL_DISALLOW_COPY_ASSIGN(GDALNoDataValuesMaskBand)
2080 :
2081 : protected:
2082 : CPLErr IReadBlock(int, int, void *) override;
2083 :
2084 : public:
2085 : explicit GDALNoDataValuesMaskBand(GDALDataset *);
2086 : ~GDALNoDataValuesMaskBand() override;
2087 :
2088 0 : bool IsMaskBand() const override
2089 : {
2090 0 : return true;
2091 : }
2092 :
2093 0 : GDALMaskValueRange GetMaskValueRange() const override
2094 : {
2095 0 : return GMVR_0_AND_255_ONLY;
2096 : }
2097 : };
2098 :
2099 : /* ******************************************************************** */
2100 : /* GDALRescaledAlphaBand */
2101 : /* ******************************************************************** */
2102 :
2103 : class GDALRescaledAlphaBand : public GDALRasterBand
2104 : {
2105 : GDALRasterBand *poParent;
2106 : void *pTemp;
2107 :
2108 : CPL_DISALLOW_COPY_ASSIGN(GDALRescaledAlphaBand)
2109 :
2110 : protected:
2111 : CPLErr IReadBlock(int, int, void *) override;
2112 : CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
2113 : GDALDataType, GSpacing, GSpacing,
2114 : GDALRasterIOExtraArg *psExtraArg) override;
2115 :
2116 : public:
2117 : explicit GDALRescaledAlphaBand(GDALRasterBand *);
2118 : ~GDALRescaledAlphaBand() override;
2119 :
2120 0 : bool IsMaskBand() const override
2121 : {
2122 0 : return true;
2123 : }
2124 : };
2125 :
2126 : //! @endcond
2127 :
2128 : /* ******************************************************************** */
2129 : /* GDALIdentifyEnum */
2130 : /* ******************************************************************** */
2131 :
2132 : /**
2133 : * Enumeration used by GDALDriver::pfnIdentify().
2134 : *
2135 : * @since GDAL 2.1
2136 : */
2137 : typedef enum
2138 : {
2139 : /** Identify could not determine if the file is recognized or not by the
2140 : probed driver. */
2141 : GDAL_IDENTIFY_UNKNOWN = -1,
2142 : /** Identify determined the file is not recognized by the probed driver. */
2143 : GDAL_IDENTIFY_FALSE = 0,
2144 : /** Identify determined the file is recognized by the probed driver. */
2145 : GDAL_IDENTIFY_TRUE = 1
2146 : } GDALIdentifyEnum;
2147 :
2148 : /* ******************************************************************** */
2149 : /* GDALDriver */
2150 : /* ******************************************************************** */
2151 :
2152 : /**
2153 : * \brief Format specific driver.
2154 : *
2155 : * An instance of this class is created for each supported format, and
2156 : * manages information about the format.
2157 : *
2158 : * This roughly corresponds to a file format, though some
2159 : * drivers may be gateways to many formats through a secondary
2160 : * multi-library.
2161 : */
2162 :
2163 330396 : class CPL_DLL GDALDriver : public GDALMajorObject
2164 : {
2165 : public:
2166 : GDALDriver();
2167 : ~GDALDriver() override;
2168 :
2169 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
2170 : const char *pszDomain = "") override;
2171 :
2172 : /* -------------------------------------------------------------------- */
2173 : /* Public C++ methods. */
2174 : /* -------------------------------------------------------------------- */
2175 : GDALDataset *Create(const char *pszName, int nXSize, int nYSize, int nBands,
2176 : GDALDataType eType,
2177 : CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
2178 :
2179 : GDALDataset *
2180 : CreateMultiDimensional(const char *pszName,
2181 : CSLConstList papszRootGroupOptions,
2182 : CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
2183 :
2184 : CPLErr Delete(const char *pszName);
2185 : CPLErr Rename(const char *pszNewName, const char *pszOldName);
2186 : CPLErr CopyFiles(const char *pszNewName, const char *pszOldName);
2187 :
2188 : GDALDataset *CreateCopy(const char *, GDALDataset *, int,
2189 : CSLConstList papszOptions,
2190 : GDALProgressFunc pfnProgress,
2191 : void *pProgressData) CPL_WARN_UNUSED_RESULT;
2192 :
2193 : bool CanVectorTranslateFrom(const char *pszDestName,
2194 : GDALDataset *poSourceDS,
2195 : CSLConstList papszVectorTranslateArguments,
2196 : char ***ppapszFailureReasons);
2197 :
2198 : /**
2199 : * \brief Returns TRUE if the given open option is supported by the driver.
2200 : * @param pszOpenOptionName name of the open option to be checked
2201 : * @return TRUE if the driver supports the open option
2202 : * @since GDAL 3.11
2203 : */
2204 : bool HasOpenOption(const char *pszOpenOptionName) const;
2205 :
2206 : GDALDataset *
2207 : VectorTranslateFrom(const char *pszDestName, GDALDataset *poSourceDS,
2208 : CSLConstList papszVectorTranslateArguments,
2209 : GDALProgressFunc pfnProgress,
2210 : void *pProgressData) CPL_WARN_UNUSED_RESULT;
2211 :
2212 : /* -------------------------------------------------------------------- */
2213 : /* The following are semiprivate, not intended to be accessed */
2214 : /* by anyone but the formats instantiating and populating the */
2215 : /* drivers. */
2216 : /* -------------------------------------------------------------------- */
2217 : //! @cond Doxygen_Suppress
2218 :
2219 : // Not aimed at being used outside of GDAL. Use GDALDataset::Open() instead
2220 : GDALDataset *Open(GDALOpenInfo *poOpenInfo, bool bSetOpenOptions);
2221 :
2222 : typedef GDALDataset *(*OpenCallback)(GDALOpenInfo *);
2223 :
2224 : OpenCallback pfnOpen = nullptr;
2225 :
2226 546113 : virtual OpenCallback GetOpenCallback()
2227 : {
2228 546113 : return pfnOpen;
2229 : }
2230 :
2231 : typedef GDALDataset *(*CreateCallback)(const char *pszName, int nXSize,
2232 : int nYSize, int nBands,
2233 : GDALDataType eType,
2234 : char **papszOptions);
2235 :
2236 : CreateCallback pfnCreate = nullptr;
2237 :
2238 20175 : virtual CreateCallback GetCreateCallback()
2239 : {
2240 20175 : return pfnCreate;
2241 : }
2242 :
2243 : GDALDataset *(*pfnCreateEx)(GDALDriver *, const char *pszName, int nXSize,
2244 : int nYSize, int nBands, GDALDataType eType,
2245 : char **papszOptions) = nullptr;
2246 :
2247 : typedef GDALDataset *(*CreateMultiDimensionalCallback)(
2248 : const char *pszName, CSLConstList papszRootGroupOptions,
2249 : CSLConstList papszOptions);
2250 :
2251 : CreateMultiDimensionalCallback pfnCreateMultiDimensional = nullptr;
2252 :
2253 467 : virtual CreateMultiDimensionalCallback GetCreateMultiDimensionalCallback()
2254 : {
2255 467 : return pfnCreateMultiDimensional;
2256 : }
2257 :
2258 : typedef CPLErr (*DeleteCallback)(const char *pszName);
2259 : DeleteCallback pfnDelete = nullptr;
2260 :
2261 5444 : virtual DeleteCallback GetDeleteCallback()
2262 : {
2263 5444 : return pfnDelete;
2264 : }
2265 :
2266 : typedef GDALDataset *(*CreateCopyCallback)(const char *, GDALDataset *, int,
2267 : char **,
2268 : GDALProgressFunc pfnProgress,
2269 : void *pProgressData);
2270 :
2271 : CreateCopyCallback pfnCreateCopy = nullptr;
2272 :
2273 10958 : virtual CreateCopyCallback GetCreateCopyCallback()
2274 : {
2275 10958 : return pfnCreateCopy;
2276 : }
2277 :
2278 : void *pDriverData = nullptr;
2279 :
2280 : void (*pfnUnloadDriver)(GDALDriver *) = nullptr;
2281 :
2282 : /** Identify() if the file is recognized or not by the driver.
2283 :
2284 : Return GDAL_IDENTIFY_TRUE (1) if the passed file is certainly recognized
2285 : by the driver. Return GDAL_IDENTIFY_FALSE (0) if the passed file is
2286 : certainly NOT recognized by the driver. Return GDAL_IDENTIFY_UNKNOWN (-1)
2287 : if the passed file may be or may not be recognized by the driver, and
2288 : that a potentially costly test must be done with pfnOpen.
2289 : */
2290 : int (*pfnIdentify)(GDALOpenInfo *) = nullptr;
2291 : int (*pfnIdentifyEx)(GDALDriver *, GDALOpenInfo *) = nullptr;
2292 :
2293 : typedef CPLErr (*RenameCallback)(const char *pszNewName,
2294 : const char *pszOldName);
2295 : RenameCallback pfnRename = nullptr;
2296 :
2297 174 : virtual RenameCallback GetRenameCallback()
2298 : {
2299 174 : return pfnRename;
2300 : }
2301 :
2302 : typedef CPLErr (*CopyFilesCallback)(const char *pszNewName,
2303 : const char *pszOldName);
2304 : CopyFilesCallback pfnCopyFiles = nullptr;
2305 :
2306 9 : virtual CopyFilesCallback GetCopyFilesCallback()
2307 : {
2308 9 : return pfnCopyFiles;
2309 : }
2310 :
2311 : // Used for legacy OGR drivers, and Python drivers
2312 : GDALDataset *(*pfnOpenWithDriverArg)(GDALDriver *,
2313 : GDALOpenInfo *) = nullptr;
2314 :
2315 : /* For legacy OGR drivers */
2316 : GDALDataset *(*pfnCreateVectorOnly)(GDALDriver *, const char *pszName,
2317 : char **papszOptions) = nullptr;
2318 : CPLErr (*pfnDeleteDataSource)(GDALDriver *, const char *pszName) = nullptr;
2319 :
2320 : /** Whether pfnVectorTranslateFrom() can be run given the source dataset
2321 : * and the non-positional arguments of GDALVectorTranslate() stored
2322 : * in papszVectorTranslateArguments.
2323 : */
2324 : bool (*pfnCanVectorTranslateFrom)(
2325 : const char *pszDestName, GDALDataset *poSourceDS,
2326 : CSLConstList papszVectorTranslateArguments,
2327 : char ***ppapszFailureReasons) = nullptr;
2328 :
2329 : /** Creates a copy from the specified source dataset, using the
2330 : * non-positional arguments of GDALVectorTranslate() stored
2331 : * in papszVectorTranslateArguments.
2332 : */
2333 : GDALDataset *(*pfnVectorTranslateFrom)(
2334 : const char *pszDestName, GDALDataset *poSourceDS,
2335 : CSLConstList papszVectorTranslateArguments,
2336 : GDALProgressFunc pfnProgress, void *pProgressData) = nullptr;
2337 :
2338 : /**
2339 : * Returns a (possibly null) pointer to the Subdataset informational function
2340 : * from the subdataset file name.
2341 : */
2342 : GDALSubdatasetInfo *(*pfnGetSubdatasetInfoFunc)(const char *pszFileName) =
2343 : nullptr;
2344 :
2345 : //! @endcond
2346 :
2347 : /* -------------------------------------------------------------------- */
2348 : /* Helper methods. */
2349 : /* -------------------------------------------------------------------- */
2350 : //! @cond Doxygen_Suppress
2351 : GDALDataset *DefaultCreateCopy(const char *, GDALDataset *, int,
2352 : CSLConstList papszOptions,
2353 : GDALProgressFunc pfnProgress,
2354 : void *pProgressData) CPL_WARN_UNUSED_RESULT;
2355 :
2356 : static CPLErr DefaultCreateCopyMultiDimensional(
2357 : GDALDataset *poSrcDS, GDALDataset *poDstDS, bool bStrict,
2358 : CSLConstList /*papszOptions*/, GDALProgressFunc pfnProgress,
2359 : void *pProgressData);
2360 :
2361 : static CPLErr DefaultCopyMasks(GDALDataset *poSrcDS, GDALDataset *poDstDS,
2362 : int bStrict);
2363 : static CPLErr DefaultCopyMasks(GDALDataset *poSrcDS, GDALDataset *poDstDS,
2364 : int bStrict, CSLConstList papszOptions,
2365 : GDALProgressFunc pfnProgress,
2366 : void *pProgressData);
2367 :
2368 : CPLErr QuietDeleteForCreateCopy(const char *pszFilename,
2369 : GDALDataset *poSrcDS);
2370 :
2371 : //! @endcond
2372 : static CPLErr QuietDelete(const char *pszName,
2373 : CSLConstList papszAllowedDrivers = nullptr);
2374 :
2375 : //! @cond Doxygen_Suppress
2376 : static CPLErr DefaultRename(const char *pszNewName, const char *pszOldName);
2377 : static CPLErr DefaultCopyFiles(const char *pszNewName,
2378 : const char *pszOldName);
2379 : static void DefaultCopyMetadata(GDALDataset *poSrcDS, GDALDataset *poDstDS,
2380 : CSLConstList papszOptions,
2381 : CSLConstList papszExcludedDomains);
2382 :
2383 : //! @endcond
2384 :
2385 : /** Convert a GDALDriver* to a GDALDriverH.
2386 : * @since GDAL 2.3
2387 : */
2388 47 : static inline GDALDriverH ToHandle(GDALDriver *poDriver)
2389 : {
2390 47 : return static_cast<GDALDriverH>(poDriver);
2391 : }
2392 :
2393 : /** Convert a GDALDriverH to a GDALDriver*.
2394 : * @since GDAL 2.3
2395 : */
2396 3958252 : static inline GDALDriver *FromHandle(GDALDriverH hDriver)
2397 : {
2398 3958252 : return static_cast<GDALDriver *>(hDriver);
2399 : }
2400 :
2401 : private:
2402 : CPL_DISALLOW_COPY_ASSIGN(GDALDriver)
2403 : };
2404 :
2405 : /************************************************************************/
2406 : /* GDALPluginDriverProxy */
2407 : /************************************************************************/
2408 :
2409 : // clang-format off
2410 : /** Proxy for a plugin driver.
2411 : *
2412 : * Such proxy must be registered with
2413 : * GDALDriverManager::DeclareDeferredPluginDriver().
2414 : *
2415 : * If the real driver defines any of the following metadata items, the
2416 : * proxy driver should also define them with the same value:
2417 : * <ul>
2418 : * <li>GDAL_DMD_LONGNAME</li>
2419 : * <li>GDAL_DMD_EXTENSIONS</li>
2420 : * <li>GDAL_DMD_EXTENSION</li>
2421 : * <li>GDAL_DMD_OPENOPTIONLIST</li>
2422 : * <li>GDAL_DMD_SUBDATASETS</li>
2423 : * <li>GDAL_DMD_CONNECTION_PREFIX</li>
2424 : * <li>GDAL_DCAP_RASTER</li>
2425 : * <li>GDAL_DCAP_MULTIDIM_RASTER</li>
2426 : * <li>GDAL_DCAP_VECTOR</li>
2427 : * <li>GDAL_DCAP_GNM</li>
2428 : * <li>GDAL_DCAP_MULTIPLE_VECTOR_LAYERS</li>
2429 : * <li>GDAL_DCAP_NONSPATIAL</li>
2430 : * <li>GDAL_DCAP_VECTOR_TRANSLATE_FROM</li>
2431 : * </ul>
2432 : *
2433 : * The pfnIdentify and pfnGetSubdatasetInfoFunc callbacks, if they are
2434 : * defined in the real driver, should also be set on the proxy driver.
2435 : *
2436 : * Furthermore, the following metadata items must be defined if the real
2437 : * driver sets the corresponding callback:
2438 : * <ul>
2439 : * <li>GDAL_DCAP_OPEN: must be set to YES if the real driver defines pfnOpen</li>
2440 : * <li>GDAL_DCAP_CREATE: must be set to YES if the real driver defines pfnCreate</li>
2441 : * <li>GDAL_DCAP_CREATE_MULTIDIMENSIONAL: must be set to YES if the real driver defines pfnCreateMultiDimensional</li>
2442 : * <li>GDAL_DCAP_CREATECOPY: must be set to YES if the real driver defines pfnCreateCopy</li>
2443 : * </ul>
2444 : *
2445 : * @since 3.9
2446 : */
2447 : // clang-format on
2448 :
2449 : class GDALPluginDriverProxy : public GDALDriver
2450 : {
2451 : const std::string m_osPluginFileName;
2452 : std::string m_osPluginFullPath{};
2453 : std::unique_ptr<GDALDriver> m_poRealDriver{};
2454 : std::set<std::string> m_oSetMetadataItems{};
2455 :
2456 : GDALDriver *GetRealDriver();
2457 :
2458 : CPL_DISALLOW_COPY_ASSIGN(GDALPluginDriverProxy)
2459 :
2460 : protected:
2461 : friend class GDALDriverManager;
2462 :
2463 : //! @cond Doxygen_Suppress
2464 62280 : void SetPluginFullPath(const std::string &osFullPath)
2465 : {
2466 62280 : m_osPluginFullPath = osFullPath;
2467 62280 : }
2468 :
2469 : //! @endcond
2470 :
2471 : public:
2472 : explicit GDALPluginDriverProxy(const std::string &osPluginFileName);
2473 :
2474 : /** Return the plugin file name (not a full path) */
2475 62280 : const std::string &GetPluginFileName() const
2476 : {
2477 62280 : return m_osPluginFileName;
2478 : }
2479 :
2480 : //! @cond Doxygen_Suppress
2481 : OpenCallback GetOpenCallback() override;
2482 :
2483 : CreateCallback GetCreateCallback() override;
2484 :
2485 : CreateMultiDimensionalCallback GetCreateMultiDimensionalCallback() override;
2486 :
2487 : CreateCopyCallback GetCreateCopyCallback() override;
2488 :
2489 : DeleteCallback GetDeleteCallback() override;
2490 :
2491 : RenameCallback GetRenameCallback() override;
2492 :
2493 : CopyFilesCallback GetCopyFilesCallback() override;
2494 : //! @endcond
2495 :
2496 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
2497 : const char *pszDomain = "") override;
2498 :
2499 : char **GetMetadata(const char *pszDomain) override;
2500 :
2501 : const char *GetMetadataItem(const char *pszName,
2502 : const char *pszDomain = "") override;
2503 : };
2504 :
2505 : /* ******************************************************************** */
2506 : /* GDALDriverManager */
2507 : /* ******************************************************************** */
2508 :
2509 : /**
2510 : * Class for managing the registration of file format drivers.
2511 : *
2512 : * Use GetGDALDriverManager() to fetch the global singleton instance of
2513 : * this class.
2514 : */
2515 :
2516 : class CPL_DLL GDALDriverManager : public GDALMajorObject
2517 : {
2518 : int nDrivers = 0;
2519 : GDALDriver **papoDrivers = nullptr;
2520 : std::map<CPLString, GDALDriver *> oMapNameToDrivers{};
2521 : std::string m_osPluginPath{};
2522 : std::string m_osDriversIniPath{};
2523 : mutable std::string m_osLastTriedDirectory{};
2524 : std::set<std::string> m_oSetPluginFileNames{};
2525 : bool m_bInDeferredDriverLoading = false;
2526 : std::map<std::string, std::unique_ptr<GDALDriver>> m_oMapRealDrivers{};
2527 : std::vector<std::unique_ptr<GDALDriver>> m_aoHiddenDrivers{};
2528 :
2529 19772900 : GDALDriver *GetDriver_unlocked(int iDriver)
2530 : {
2531 19772900 : return (iDriver >= 0 && iDriver < nDrivers) ? papoDrivers[iDriver]
2532 19772900 : : nullptr;
2533 : }
2534 :
2535 826387 : GDALDriver *GetDriverByName_unlocked(const char *pszName) const
2536 : {
2537 826387 : auto oIter = oMapNameToDrivers.find(CPLString(pszName).toupper());
2538 826387 : return oIter == oMapNameToDrivers.end() ? nullptr : oIter->second;
2539 : }
2540 :
2541 : static void CleanupPythonDrivers();
2542 :
2543 : std::string GetPluginFullPath(const char *pszFilename) const;
2544 :
2545 : int RegisterDriver(GDALDriver *, bool bHidden);
2546 :
2547 : CPL_DISALLOW_COPY_ASSIGN(GDALDriverManager)
2548 :
2549 : protected:
2550 : friend class GDALPluginDriverProxy;
2551 : friend GDALDatasetH CPL_STDCALL
2552 : GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags,
2553 : const char *const *papszAllowedDrivers,
2554 : const char *const *papszOpenOptions,
2555 : const char *const *papszSiblingFiles);
2556 :
2557 : //! @cond Doxygen_Suppress
2558 : static char **GetSearchPaths(const char *pszGDAL_DRIVER_PATH);
2559 : //! @endcond
2560 :
2561 : public:
2562 : GDALDriverManager();
2563 : ~GDALDriverManager();
2564 :
2565 : int GetDriverCount(void) const;
2566 : GDALDriver *GetDriver(int);
2567 : GDALDriver *GetDriverByName(const char *);
2568 :
2569 : int RegisterDriver(GDALDriver *);
2570 : void DeregisterDriver(GDALDriver *);
2571 :
2572 : // AutoLoadDrivers is a no-op if compiled with GDAL_NO_AUTOLOAD defined.
2573 : void AutoLoadDrivers();
2574 : void AutoSkipDrivers();
2575 : void ReorderDrivers();
2576 : static CPLErr LoadPlugin(const char *name);
2577 :
2578 : static void AutoLoadPythonDrivers();
2579 :
2580 : void DeclareDeferredPluginDriver(GDALPluginDriverProxy *poProxyDriver);
2581 :
2582 : //! @cond Doxygen_Suppress
2583 : int GetDriverCount(bool bIncludeHidden) const;
2584 : GDALDriver *GetDriver(int iDriver, bool bIncludeHidden);
2585 : bool IsKnownDriver(const char *pszDriverName) const;
2586 : //! @endcond
2587 : };
2588 :
2589 : CPL_C_START
2590 : GDALDriverManager CPL_DLL *GetGDALDriverManager(void);
2591 : CPL_C_END
2592 :
2593 : /* ******************************************************************** */
2594 : /* GDALAsyncReader */
2595 : /* ******************************************************************** */
2596 :
2597 : /**
2598 : * Class used as a session object for asynchronous requests. They are
2599 : * created with GDALDataset::BeginAsyncReader(), and destroyed with
2600 : * GDALDataset::EndAsyncReader().
2601 : */
2602 1 : class CPL_DLL GDALAsyncReader
2603 : {
2604 :
2605 : CPL_DISALLOW_COPY_ASSIGN(GDALAsyncReader)
2606 :
2607 : protected:
2608 : //! @cond Doxygen_Suppress
2609 : GDALDataset *poDS;
2610 : int nXOff;
2611 : int nYOff;
2612 : int nXSize;
2613 : int nYSize;
2614 : void *pBuf;
2615 : int nBufXSize;
2616 : int nBufYSize;
2617 : GDALDataType eBufType;
2618 : int nBandCount;
2619 : int *panBandMap;
2620 : int nPixelSpace;
2621 : int nLineSpace;
2622 : int nBandSpace;
2623 : //! @endcond
2624 :
2625 : public:
2626 : GDALAsyncReader();
2627 : virtual ~GDALAsyncReader();
2628 :
2629 : /** Return dataset.
2630 : * @return dataset
2631 : */
2632 : GDALDataset *GetGDALDataset()
2633 : {
2634 : return poDS;
2635 : }
2636 :
2637 : /** Return x offset.
2638 : * @return x offset.
2639 : */
2640 : int GetXOffset() const
2641 : {
2642 : return nXOff;
2643 : }
2644 :
2645 : /** Return y offset.
2646 : * @return y offset.
2647 : */
2648 : int GetYOffset() const
2649 : {
2650 : return nYOff;
2651 : }
2652 :
2653 : /** Return width.
2654 : * @return width
2655 : */
2656 : int GetXSize() const
2657 : {
2658 : return nXSize;
2659 : }
2660 :
2661 : /** Return height.
2662 : * @return height
2663 : */
2664 : int GetYSize() const
2665 : {
2666 : return nYSize;
2667 : }
2668 :
2669 : /** Return buffer.
2670 : * @return buffer
2671 : */
2672 : void *GetBuffer()
2673 : {
2674 : return pBuf;
2675 : }
2676 :
2677 : /** Return buffer width.
2678 : * @return buffer width.
2679 : */
2680 : int GetBufferXSize() const
2681 : {
2682 : return nBufXSize;
2683 : }
2684 :
2685 : /** Return buffer height.
2686 : * @return buffer height.
2687 : */
2688 : int GetBufferYSize() const
2689 : {
2690 : return nBufYSize;
2691 : }
2692 :
2693 : /** Return buffer data type.
2694 : * @return buffer data type.
2695 : */
2696 : GDALDataType GetBufferType() const
2697 : {
2698 : return eBufType;
2699 : }
2700 :
2701 : /** Return band count.
2702 : * @return band count
2703 : */
2704 : int GetBandCount() const
2705 : {
2706 : return nBandCount;
2707 : }
2708 :
2709 : /** Return band map.
2710 : * @return band map.
2711 : */
2712 : int *GetBandMap()
2713 : {
2714 : return panBandMap;
2715 : }
2716 :
2717 : /** Return pixel spacing.
2718 : * @return pixel spacing.
2719 : */
2720 : int GetPixelSpace() const
2721 : {
2722 : return nPixelSpace;
2723 : }
2724 :
2725 : /** Return line spacing.
2726 : * @return line spacing.
2727 : */
2728 : int GetLineSpace() const
2729 : {
2730 : return nLineSpace;
2731 : }
2732 :
2733 : /** Return band spacing.
2734 : * @return band spacing.
2735 : */
2736 : int GetBandSpace() const
2737 : {
2738 : return nBandSpace;
2739 : }
2740 :
2741 : virtual GDALAsyncStatusType
2742 : GetNextUpdatedRegion(double dfTimeout, int *pnBufXOff, int *pnBufYOff,
2743 : int *pnBufXSize, int *pnBufYSize) = 0;
2744 : virtual int LockBuffer(double dfTimeout = -1.0);
2745 : virtual void UnlockBuffer();
2746 : };
2747 :
2748 : /* ******************************************************************** */
2749 : /* Multidimensional array API */
2750 : /* ******************************************************************** */
2751 :
2752 : class GDALMDArray;
2753 : class GDALAttribute;
2754 : class GDALDimension;
2755 : class GDALEDTComponent;
2756 :
2757 : /* ******************************************************************** */
2758 : /* GDALExtendedDataType */
2759 : /* ******************************************************************** */
2760 :
2761 : /**
2762 : * Class used to represent potentially complex data types.
2763 : * Several classes of data types are supported: numeric (based on GDALDataType),
2764 : * compound or string.
2765 : *
2766 : * @since GDAL 3.1
2767 : */
2768 60524 : class CPL_DLL GDALExtendedDataType
2769 : {
2770 : public:
2771 : ~GDALExtendedDataType();
2772 :
2773 : GDALExtendedDataType(const GDALExtendedDataType &);
2774 :
2775 : GDALExtendedDataType &operator=(const GDALExtendedDataType &);
2776 : GDALExtendedDataType &operator=(GDALExtendedDataType &&);
2777 :
2778 : static GDALExtendedDataType Create(GDALDataType eType);
2779 : static GDALExtendedDataType
2780 : Create(const std::string &osName, size_t nTotalSize,
2781 : std::vector<std::unique_ptr<GDALEDTComponent>> &&components);
2782 : static GDALExtendedDataType
2783 : CreateString(size_t nMaxStringLength = 0,
2784 : GDALExtendedDataTypeSubType eSubType = GEDTST_NONE);
2785 :
2786 : bool operator==(const GDALExtendedDataType &) const;
2787 :
2788 : /** Non-equality operator */
2789 963 : bool operator!=(const GDALExtendedDataType &other) const
2790 : {
2791 963 : return !(operator==(other));
2792 : }
2793 :
2794 : /** Return type name.
2795 : *
2796 : * This is the same as the C function GDALExtendedDataTypeGetName()
2797 : */
2798 18 : const std::string &GetName() const
2799 : {
2800 18 : return m_osName;
2801 : }
2802 :
2803 : /** Return type class.
2804 : *
2805 : * This is the same as the C function GDALExtendedDataTypeGetClass()
2806 : */
2807 296251 : GDALExtendedDataTypeClass GetClass() const
2808 : {
2809 296251 : return m_eClass;
2810 : }
2811 :
2812 : /** Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)
2813 : *
2814 : * This is the same as the C function
2815 : * GDALExtendedDataTypeGetNumericDataType()
2816 : */
2817 1953965 : GDALDataType GetNumericDataType() const
2818 : {
2819 1953965 : return m_eNumericDT;
2820 : }
2821 :
2822 : /** Return subtype.
2823 : *
2824 : * This is the same as the C function GDALExtendedDataTypeGetSubType()
2825 : *
2826 : * @since 3.4
2827 : */
2828 311 : GDALExtendedDataTypeSubType GetSubType() const
2829 : {
2830 311 : return m_eSubType;
2831 : }
2832 :
2833 : /** Return the components of the data type (only valid when GetClass() ==
2834 : * GEDTC_COMPOUND)
2835 : *
2836 : * This is the same as the C function GDALExtendedDataTypeGetComponents()
2837 : */
2838 904 : const std::vector<std::unique_ptr<GDALEDTComponent>> &GetComponents() const
2839 : {
2840 904 : return m_aoComponents;
2841 : }
2842 :
2843 : /** Return data type size in bytes.
2844 : *
2845 : * For a string, this will be size of a char* pointer.
2846 : *
2847 : * This is the same as the C function GDALExtendedDataTypeGetSize()
2848 : */
2849 50142 : size_t GetSize() const
2850 : {
2851 50142 : return m_nSize;
2852 : }
2853 :
2854 : /** Return the maximum length of a string in bytes.
2855 : *
2856 : * 0 indicates unknown/unlimited string.
2857 : */
2858 21 : size_t GetMaxStringLength() const
2859 : {
2860 21 : return m_nMaxStringLength;
2861 : }
2862 :
2863 : bool CanConvertTo(const GDALExtendedDataType &other) const;
2864 :
2865 : bool NeedsFreeDynamicMemory() const;
2866 :
2867 : void FreeDynamicMemory(void *pBuffer) const;
2868 :
2869 : static bool CopyValue(const void *pSrc, const GDALExtendedDataType &srcType,
2870 : void *pDst, const GDALExtendedDataType &dstType);
2871 :
2872 : static bool CopyValues(const void *pSrc,
2873 : const GDALExtendedDataType &srcType,
2874 : GPtrDiff_t nSrcStrideInElts, void *pDst,
2875 : const GDALExtendedDataType &dstType,
2876 : GPtrDiff_t nDstStrideInElts, size_t nValues);
2877 :
2878 : private:
2879 : GDALExtendedDataType(size_t nMaxStringLength,
2880 : GDALExtendedDataTypeSubType eSubType);
2881 : explicit GDALExtendedDataType(GDALDataType eType);
2882 : GDALExtendedDataType(
2883 : const std::string &osName, size_t nTotalSize,
2884 : std::vector<std::unique_ptr<GDALEDTComponent>> &&components);
2885 :
2886 : std::string m_osName{};
2887 : GDALExtendedDataTypeClass m_eClass = GEDTC_NUMERIC;
2888 : GDALExtendedDataTypeSubType m_eSubType = GEDTST_NONE;
2889 : GDALDataType m_eNumericDT = GDT_Unknown;
2890 : std::vector<std::unique_ptr<GDALEDTComponent>> m_aoComponents{};
2891 : size_t m_nSize = 0;
2892 : size_t m_nMaxStringLength = 0;
2893 : };
2894 :
2895 : /* ******************************************************************** */
2896 : /* GDALEDTComponent */
2897 : /* ******************************************************************** */
2898 :
2899 : /**
2900 : * Class for a component of a compound extended data type.
2901 : *
2902 : * @since GDAL 3.1
2903 : */
2904 3344 : class CPL_DLL GDALEDTComponent
2905 : {
2906 : public:
2907 : ~GDALEDTComponent();
2908 : GDALEDTComponent(const std::string &name, size_t offset,
2909 : const GDALExtendedDataType &type);
2910 : GDALEDTComponent(const GDALEDTComponent &);
2911 :
2912 : bool operator==(const GDALEDTComponent &) const;
2913 :
2914 : /** Return the name.
2915 : *
2916 : * This is the same as the C function GDALEDTComponentGetName().
2917 : */
2918 2492 : const std::string &GetName() const
2919 : {
2920 2492 : return m_osName;
2921 : }
2922 :
2923 : /** Return the offset (in bytes) of the component in the compound data type.
2924 : *
2925 : * This is the same as the C function GDALEDTComponentGetOffset().
2926 : */
2927 6707 : size_t GetOffset() const
2928 : {
2929 6707 : return m_nOffset;
2930 : }
2931 :
2932 : /** Return the data type of the component.
2933 : *
2934 : * This is the same as the C function GDALEDTComponentGetType().
2935 : */
2936 6446 : const GDALExtendedDataType &GetType() const
2937 : {
2938 6446 : return m_oType;
2939 : }
2940 :
2941 : private:
2942 : std::string m_osName;
2943 : size_t m_nOffset;
2944 : GDALExtendedDataType m_oType;
2945 : };
2946 :
2947 : /* ******************************************************************** */
2948 : /* GDALIHasAttribute */
2949 : /* ******************************************************************** */
2950 :
2951 : /**
2952 : * Interface used to get a single GDALAttribute or a set of GDALAttribute
2953 : *
2954 : * @since GDAL 3.1
2955 : */
2956 12874 : class CPL_DLL GDALIHasAttribute
2957 : {
2958 : protected:
2959 : std::shared_ptr<GDALAttribute>
2960 : GetAttributeFromAttributes(const std::string &osName) const;
2961 :
2962 : public:
2963 : virtual ~GDALIHasAttribute();
2964 :
2965 : virtual std::shared_ptr<GDALAttribute>
2966 : GetAttribute(const std::string &osName) const;
2967 :
2968 : virtual std::vector<std::shared_ptr<GDALAttribute>>
2969 : GetAttributes(CSLConstList papszOptions = nullptr) const;
2970 :
2971 : virtual std::shared_ptr<GDALAttribute>
2972 : CreateAttribute(const std::string &osName,
2973 : const std::vector<GUInt64> &anDimensions,
2974 : const GDALExtendedDataType &oDataType,
2975 : CSLConstList papszOptions = nullptr);
2976 :
2977 : virtual bool DeleteAttribute(const std::string &osName,
2978 : CSLConstList papszOptions = nullptr);
2979 : };
2980 :
2981 : /* ******************************************************************** */
2982 : /* GDALGroup */
2983 : /* ******************************************************************** */
2984 :
2985 : /* clang-format off */
2986 : /**
2987 : * Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or
2988 : * other GDALGroup. Hence GDALGroup can describe a hierarchy of objects.
2989 : *
2990 : * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_group">HDF5 group
2991 : * concept</a>
2992 : *
2993 : * @since GDAL 3.1
2994 : */
2995 : /* clang-format on */
2996 :
2997 6640 : class CPL_DLL GDALGroup : public GDALIHasAttribute
2998 : {
2999 : protected:
3000 : //! @cond Doxygen_Suppress
3001 : std::string m_osName{};
3002 :
3003 : // This is actually a path of the form "/parent_path/{m_osName}"
3004 : std::string m_osFullName{};
3005 :
3006 : // Used for example by GDALSubsetGroup to distinguish a derived group
3007 : //from its original, without altering its name
3008 : const std::string m_osContext{};
3009 :
3010 : std::weak_ptr<GDALGroup> m_pSelf{};
3011 :
3012 : //! Can be set to false by the owing group, when deleting this object
3013 : bool m_bValid = true;
3014 :
3015 : GDALGroup(const std::string &osParentName, const std::string &osName,
3016 : const std::string &osContext = std::string());
3017 :
3018 : const GDALGroup *
3019 : GetInnerMostGroup(const std::string &osPathOrArrayOrDim,
3020 : std::shared_ptr<GDALGroup> &curGroupHolder,
3021 : std::string &osLastPart) const;
3022 :
3023 : void BaseRename(const std::string &osNewName);
3024 :
3025 : bool CheckValidAndErrorOutIfNot() const;
3026 :
3027 5780 : void SetSelf(const std::shared_ptr<GDALGroup> &self)
3028 : {
3029 5780 : m_pSelf = self;
3030 5780 : }
3031 :
3032 0 : virtual void NotifyChildrenOfRenaming()
3033 : {
3034 0 : }
3035 :
3036 0 : virtual void NotifyChildrenOfDeletion()
3037 : {
3038 0 : }
3039 :
3040 : //! @endcond
3041 :
3042 : public:
3043 : virtual ~GDALGroup();
3044 :
3045 : /** Return the name of the group.
3046 : *
3047 : * This is the same as the C function GDALGroupGetName().
3048 : */
3049 1017 : const std::string &GetName() const
3050 : {
3051 1017 : return m_osName;
3052 : }
3053 :
3054 : /** Return the full name of the group.
3055 : *
3056 : * This is the same as the C function GDALGroupGetFullName().
3057 : */
3058 23396 : const std::string &GetFullName() const
3059 : {
3060 23396 : return m_osFullName;
3061 : }
3062 :
3063 : virtual std::vector<std::string>
3064 : GetMDArrayNames(CSLConstList papszOptions = nullptr) const;
3065 : virtual std::shared_ptr<GDALMDArray>
3066 : OpenMDArray(const std::string &osName,
3067 : CSLConstList papszOptions = nullptr) const;
3068 :
3069 : virtual std::vector<std::string>
3070 : GetGroupNames(CSLConstList papszOptions = nullptr) const;
3071 : virtual std::shared_ptr<GDALGroup>
3072 : OpenGroup(const std::string &osName,
3073 : CSLConstList papszOptions = nullptr) const;
3074 :
3075 : virtual std::vector<std::string>
3076 : GetVectorLayerNames(CSLConstList papszOptions = nullptr) const;
3077 : virtual OGRLayer *
3078 : OpenVectorLayer(const std::string &osName,
3079 : CSLConstList papszOptions = nullptr) const;
3080 :
3081 : virtual std::vector<std::shared_ptr<GDALDimension>>
3082 : GetDimensions(CSLConstList papszOptions = nullptr) const;
3083 :
3084 : virtual std::shared_ptr<GDALGroup>
3085 : CreateGroup(const std::string &osName, CSLConstList papszOptions = nullptr);
3086 :
3087 : virtual bool DeleteGroup(const std::string &osName,
3088 : CSLConstList papszOptions = nullptr);
3089 :
3090 : virtual std::shared_ptr<GDALDimension>
3091 : CreateDimension(const std::string &osName, const std::string &osType,
3092 : const std::string &osDirection, GUInt64 nSize,
3093 : CSLConstList papszOptions = nullptr);
3094 :
3095 : virtual std::shared_ptr<GDALMDArray> CreateMDArray(
3096 : const std::string &osName,
3097 : const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
3098 : const GDALExtendedDataType &oDataType,
3099 : CSLConstList papszOptions = nullptr);
3100 :
3101 : virtual bool DeleteMDArray(const std::string &osName,
3102 : CSLConstList papszOptions = nullptr);
3103 :
3104 : GUInt64 GetTotalCopyCost() const;
3105 :
3106 : virtual bool CopyFrom(const std::shared_ptr<GDALGroup> &poDstRootGroup,
3107 : GDALDataset *poSrcDS,
3108 : const std::shared_ptr<GDALGroup> &poSrcGroup,
3109 : bool bStrict, GUInt64 &nCurCost,
3110 : const GUInt64 nTotalCost,
3111 : GDALProgressFunc pfnProgress, void *pProgressData,
3112 : CSLConstList papszOptions = nullptr);
3113 :
3114 : virtual CSLConstList GetStructuralInfo() const;
3115 :
3116 : std::shared_ptr<GDALMDArray>
3117 : OpenMDArrayFromFullname(const std::string &osFullName,
3118 : CSLConstList papszOptions = nullptr) const;
3119 :
3120 : std::shared_ptr<GDALMDArray>
3121 : ResolveMDArray(const std::string &osName, const std::string &osStartingPath,
3122 : CSLConstList papszOptions = nullptr) const;
3123 :
3124 : std::shared_ptr<GDALGroup>
3125 : OpenGroupFromFullname(const std::string &osFullName,
3126 : CSLConstList papszOptions = nullptr) const;
3127 :
3128 : std::shared_ptr<GDALDimension>
3129 : OpenDimensionFromFullname(const std::string &osFullName) const;
3130 :
3131 : virtual void ClearStatistics();
3132 :
3133 : virtual bool Rename(const std::string &osNewName);
3134 :
3135 : std::shared_ptr<GDALGroup>
3136 : SubsetDimensionFromSelection(const std::string &osSelection) const;
3137 :
3138 : //! @cond Doxygen_Suppress
3139 : virtual void ParentRenamed(const std::string &osNewParentFullName);
3140 :
3141 : virtual void Deleted();
3142 :
3143 : virtual void ParentDeleted();
3144 :
3145 23 : const std::string &GetContext() const
3146 : {
3147 23 : return m_osContext;
3148 : }
3149 :
3150 : //! @endcond
3151 :
3152 : //! @cond Doxygen_Suppress
3153 : static constexpr GUInt64 COPY_COST = 1000;
3154 : //! @endcond
3155 : };
3156 :
3157 : /* ******************************************************************** */
3158 : /* GDALAbstractMDArray */
3159 : /* ******************************************************************** */
3160 :
3161 : /**
3162 : * Abstract class, implemented by GDALAttribute and GDALMDArray.
3163 : *
3164 : * @since GDAL 3.1
3165 : */
3166 20239 : class CPL_DLL GDALAbstractMDArray
3167 : {
3168 : protected:
3169 : //! @cond Doxygen_Suppress
3170 : std::string m_osName{};
3171 :
3172 : // This is actually a path of the form "/parent_path/{m_osName}"
3173 : std::string m_osFullName{};
3174 : std::weak_ptr<GDALAbstractMDArray> m_pSelf{};
3175 :
3176 : //! Can be set to false by the owing object, when deleting this object
3177 : bool m_bValid = true;
3178 :
3179 : GDALAbstractMDArray(const std::string &osParentName,
3180 : const std::string &osName);
3181 :
3182 7934 : void SetSelf(const std::shared_ptr<GDALAbstractMDArray> &self)
3183 : {
3184 7934 : m_pSelf = self;
3185 7934 : }
3186 :
3187 : bool CheckValidAndErrorOutIfNot() const;
3188 :
3189 : bool CheckReadWriteParams(const GUInt64 *arrayStartIdx, const size_t *count,
3190 : const GInt64 *&arrayStep,
3191 : const GPtrDiff_t *&bufferStride,
3192 : const GDALExtendedDataType &bufferDataType,
3193 : const void *buffer,
3194 : const void *buffer_alloc_start,
3195 : size_t buffer_alloc_size,
3196 : std::vector<GInt64> &tmp_arrayStep,
3197 : std::vector<GPtrDiff_t> &tmp_bufferStride) const;
3198 :
3199 : virtual bool
3200 : IRead(const GUInt64 *arrayStartIdx, // array of size GetDimensionCount()
3201 : const size_t *count, // array of size GetDimensionCount()
3202 : const GInt64 *arrayStep, // step in elements
3203 : const GPtrDiff_t *bufferStride, // stride in elements
3204 : const GDALExtendedDataType &bufferDataType,
3205 : void *pDstBuffer) const = 0;
3206 :
3207 : virtual bool
3208 : IWrite(const GUInt64 *arrayStartIdx, // array of size GetDimensionCount()
3209 : const size_t *count, // array of size GetDimensionCount()
3210 : const GInt64 *arrayStep, // step in elements
3211 : const GPtrDiff_t *bufferStride, // stride in elements
3212 : const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer);
3213 :
3214 : void BaseRename(const std::string &osNewName);
3215 :
3216 47 : virtual void NotifyChildrenOfRenaming()
3217 : {
3218 47 : }
3219 :
3220 42 : virtual void NotifyChildrenOfDeletion()
3221 : {
3222 42 : }
3223 :
3224 : //! @endcond
3225 :
3226 : public:
3227 : virtual ~GDALAbstractMDArray();
3228 :
3229 : /** Return the name of an array or attribute.
3230 : *
3231 : * This is the same as the C function GDALMDArrayGetName() or
3232 : * GDALAttributeGetName().
3233 : */
3234 18226 : const std::string &GetName() const
3235 : {
3236 18226 : return m_osName;
3237 : }
3238 :
3239 : /** Return the name of an array or attribute.
3240 : *
3241 : * This is the same as the C function GDALMDArrayGetFullName() or
3242 : * GDALAttributeGetFullName().
3243 : */
3244 12241 : const std::string &GetFullName() const
3245 : {
3246 12241 : return m_osFullName;
3247 : }
3248 :
3249 : GUInt64 GetTotalElementsCount() const;
3250 :
3251 : virtual size_t GetDimensionCount() const;
3252 :
3253 : virtual const std::vector<std::shared_ptr<GDALDimension>> &
3254 : GetDimensions() const = 0;
3255 :
3256 : virtual const GDALExtendedDataType &GetDataType() const = 0;
3257 :
3258 : virtual std::vector<GUInt64> GetBlockSize() const;
3259 :
3260 : virtual std::vector<size_t>
3261 : GetProcessingChunkSize(size_t nMaxChunkMemory) const;
3262 :
3263 : /* clang-format off */
3264 : /** Type of pfnFunc argument of ProcessPerChunk().
3265 : * @param array Array on which ProcessPerChunk was called.
3266 : * @param chunkArrayStartIdx Values representing the starting index to use
3267 : * in each dimension (in [0, aoDims[i].GetSize()-1] range)
3268 : * for the current chunk.
3269 : * Will be nullptr for a zero-dimensional array.
3270 : * @param chunkCount Values representing the number of values to use in
3271 : * each dimension for the current chunk.
3272 : * Will be nullptr for a zero-dimensional array.
3273 : * @param iCurChunk Number of current chunk being processed.
3274 : * In [1, nChunkCount] range.
3275 : * @param nChunkCount Total number of chunks to process.
3276 : * @param pUserData User data.
3277 : * @return return true in case of success.
3278 : */
3279 : typedef bool (*FuncProcessPerChunkType)(
3280 : GDALAbstractMDArray *array,
3281 : const GUInt64 *chunkArrayStartIdx,
3282 : const size_t *chunkCount,
3283 : GUInt64 iCurChunk,
3284 : GUInt64 nChunkCount,
3285 : void *pUserData);
3286 : /* clang-format on */
3287 :
3288 : virtual bool ProcessPerChunk(const GUInt64 *arrayStartIdx,
3289 : const GUInt64 *count, const size_t *chunkSize,
3290 : FuncProcessPerChunkType pfnFunc,
3291 : void *pUserData);
3292 :
3293 : virtual bool
3294 : Read(const GUInt64 *arrayStartIdx, // array of size GetDimensionCount()
3295 : const size_t *count, // array of size GetDimensionCount()
3296 : const GInt64 *arrayStep, // step in elements
3297 : const GPtrDiff_t *bufferStride, // stride in elements
3298 : const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
3299 : const void *pDstBufferAllocStart = nullptr,
3300 : size_t nDstBufferAllocSize = 0) const;
3301 :
3302 : bool
3303 : Write(const GUInt64 *arrayStartIdx, // array of size GetDimensionCount()
3304 : const size_t *count, // array of size GetDimensionCount()
3305 : const GInt64 *arrayStep, // step in elements
3306 : const GPtrDiff_t *bufferStride, // stride in elements
3307 : const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer,
3308 : const void *pSrcBufferAllocStart = nullptr,
3309 : size_t nSrcBufferAllocSize = 0);
3310 :
3311 : virtual bool Rename(const std::string &osNewName);
3312 :
3313 : //! @cond Doxygen_Suppress
3314 : virtual void Deleted();
3315 :
3316 : virtual void ParentDeleted();
3317 :
3318 : virtual void ParentRenamed(const std::string &osNewParentFullName);
3319 : //! @endcond
3320 : };
3321 :
3322 : /* ******************************************************************** */
3323 : /* GDALRawResult */
3324 : /* ******************************************************************** */
3325 :
3326 : /**
3327 : * Store the raw result of an attribute value, which might contain dynamically
3328 : * allocated structures (like pointer to strings).
3329 : *
3330 : * @since GDAL 3.1
3331 : */
3332 : class CPL_DLL GDALRawResult
3333 : {
3334 : private:
3335 : GDALExtendedDataType m_dt;
3336 : size_t m_nEltCount;
3337 : size_t m_nSize;
3338 : GByte *m_raw;
3339 :
3340 : void FreeMe();
3341 :
3342 : GDALRawResult(const GDALRawResult &) = delete;
3343 : GDALRawResult &operator=(const GDALRawResult &) = delete;
3344 :
3345 : protected:
3346 : friend class GDALAttribute;
3347 : //! @cond Doxygen_Suppress
3348 : GDALRawResult(GByte *raw, const GDALExtendedDataType &dt, size_t nEltCount);
3349 : //! @endcond
3350 :
3351 : public:
3352 : ~GDALRawResult();
3353 : GDALRawResult(GDALRawResult &&);
3354 : GDALRawResult &operator=(GDALRawResult &&);
3355 :
3356 : /** Return byte at specified index. */
3357 : const GByte &operator[](size_t idx) const
3358 : {
3359 : return m_raw[idx];
3360 : }
3361 :
3362 : /** Return pointer to the start of data. */
3363 337 : const GByte *data() const
3364 : {
3365 337 : return m_raw;
3366 : }
3367 :
3368 : /** Return the size in bytes of the raw result. */
3369 122 : size_t size() const
3370 : {
3371 122 : return m_nSize;
3372 : }
3373 :
3374 : //! @cond Doxygen_Suppress
3375 : GByte *StealData();
3376 : //! @endcond
3377 : };
3378 :
3379 : /* ******************************************************************** */
3380 : /* GDALAttribute */
3381 : /* ******************************************************************** */
3382 :
3383 : /* clang-format off */
3384 : /**
3385 : * Class modeling an attribute that has a name, a value and a type, and is
3386 : * typically used to describe a metadata item. The value can be (for the
3387 : * HDF5 format) in the general case a multidimensional array of "any" type
3388 : * (in most cases, this will be a single value of string or numeric type)
3389 : *
3390 : * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_attribute">HDF5
3391 : * attribute concept</a>
3392 : *
3393 : * @since GDAL 3.1
3394 : */
3395 : /* clang-format on */
3396 :
3397 : class CPL_DLL GDALAttribute : virtual public GDALAbstractMDArray
3398 : {
3399 : mutable std::string m_osCachedVal{};
3400 :
3401 : protected:
3402 : //! @cond Doxygen_Suppress
3403 : GDALAttribute(const std::string &osParentName, const std::string &osName);
3404 : //! @endcond
3405 :
3406 : public:
3407 : std::vector<GUInt64> GetDimensionsSize() const;
3408 :
3409 : GDALRawResult ReadAsRaw() const;
3410 : const char *ReadAsString() const;
3411 : int ReadAsInt() const;
3412 : int64_t ReadAsInt64() const;
3413 : double ReadAsDouble() const;
3414 : CPLStringList ReadAsStringArray() const;
3415 : std::vector<int> ReadAsIntArray() const;
3416 : std::vector<int64_t> ReadAsInt64Array() const;
3417 : std::vector<double> ReadAsDoubleArray() const;
3418 :
3419 : using GDALAbstractMDArray::Write;
3420 : bool Write(const void *pabyValue, size_t nLen);
3421 : bool Write(const char *);
3422 : bool WriteInt(int);
3423 : bool WriteInt64(int64_t);
3424 : bool Write(double);
3425 : bool Write(CSLConstList);
3426 : bool Write(const int *, size_t);
3427 : bool Write(const int64_t *, size_t);
3428 : bool Write(const double *, size_t);
3429 :
3430 : //! @cond Doxygen_Suppress
3431 : static constexpr GUInt64 COPY_COST = 100;
3432 : //! @endcond
3433 : };
3434 :
3435 : /************************************************************************/
3436 : /* GDALAttributeString */
3437 : /************************************************************************/
3438 :
3439 : //! @cond Doxygen_Suppress
3440 : class CPL_DLL GDALAttributeString final : public GDALAttribute
3441 : {
3442 : std::vector<std::shared_ptr<GDALDimension>> m_dims{};
3443 : GDALExtendedDataType m_dt = GDALExtendedDataType::CreateString();
3444 : std::string m_osValue;
3445 :
3446 : protected:
3447 : bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
3448 : const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
3449 : void *pDstBuffer) const override;
3450 :
3451 : public:
3452 : GDALAttributeString(const std::string &osParentName,
3453 : const std::string &osName, const std::string &osValue,
3454 : GDALExtendedDataTypeSubType eSubType = GEDTST_NONE);
3455 :
3456 : const std::vector<std::shared_ptr<GDALDimension>> &
3457 : GetDimensions() const override;
3458 :
3459 : const GDALExtendedDataType &GetDataType() const override;
3460 : };
3461 :
3462 : //! @endcond
3463 :
3464 : /************************************************************************/
3465 : /* GDALAttributeNumeric */
3466 : /************************************************************************/
3467 :
3468 : //! @cond Doxygen_Suppress
3469 : class CPL_DLL GDALAttributeNumeric final : public GDALAttribute
3470 : {
3471 : std::vector<std::shared_ptr<GDALDimension>> m_dims{};
3472 : GDALExtendedDataType m_dt;
3473 : int m_nValue = 0;
3474 : double m_dfValue = 0;
3475 : std::vector<GUInt32> m_anValuesUInt32{};
3476 :
3477 : protected:
3478 : bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
3479 : const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
3480 : void *pDstBuffer) const override;
3481 :
3482 : public:
3483 : GDALAttributeNumeric(const std::string &osParentName,
3484 : const std::string &osName, double dfValue);
3485 : GDALAttributeNumeric(const std::string &osParentName,
3486 : const std::string &osName, int nValue);
3487 : GDALAttributeNumeric(const std::string &osParentName,
3488 : const std::string &osName,
3489 : const std::vector<GUInt32> &anValues);
3490 :
3491 : const std::vector<std::shared_ptr<GDALDimension>> &
3492 : GetDimensions() const override;
3493 :
3494 : const GDALExtendedDataType &GetDataType() const override;
3495 : };
3496 :
3497 : //! @endcond
3498 :
3499 : /* ******************************************************************** */
3500 : /* GDALMDArray */
3501 : /* ******************************************************************** */
3502 :
3503 : /* clang-format off */
3504 : /**
3505 : * Class modeling a multi-dimensional array. It has a name, values organized
3506 : * as an array and a list of GDALAttribute.
3507 : *
3508 : * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_dataset">HDF5
3509 : * dataset concept</a>
3510 : *
3511 : * @since GDAL 3.1
3512 : */
3513 : /* clang-format on */
3514 :
3515 : class CPL_DLL GDALMDArray : virtual public GDALAbstractMDArray,
3516 : public GDALIHasAttribute
3517 : {
3518 : friend class GDALMDArrayResampled;
3519 : std::shared_ptr<GDALMDArray>
3520 : GetView(const std::vector<GUInt64> &indices) const;
3521 :
3522 : inline std::shared_ptr<GDALMDArray>
3523 19 : atInternal(const std::vector<GUInt64> &indices) const
3524 : {
3525 19 : return GetView(indices);
3526 : }
3527 :
3528 : template <typename... GUInt64VarArg>
3529 : // cppcheck-suppress functionStatic
3530 : inline std::shared_ptr<GDALMDArray>
3531 7 : atInternal(std::vector<GUInt64> &indices, GUInt64 idx,
3532 : GUInt64VarArg... tail) const
3533 : {
3534 7 : indices.push_back(idx);
3535 7 : return atInternal(indices, tail...);
3536 : }
3537 :
3538 : // Used for example by GDALSubsetGroup to distinguish a derived group
3539 : //from its original, without altering its name
3540 : const std::string m_osContext{};
3541 :
3542 : mutable bool m_bHasTriedCachedArray = false;
3543 : mutable std::shared_ptr<GDALMDArray> m_poCachedArray{};
3544 :
3545 : protected:
3546 : //! @cond Doxygen_Suppress
3547 : GDALMDArray(const std::string &osParentName, const std::string &osName,
3548 : const std::string &osContext = std::string());
3549 :
3550 : virtual bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
3551 : CSLConstList papszOptions) const;
3552 :
3553 1644 : virtual bool IsCacheable() const
3554 : {
3555 1644 : return true;
3556 : }
3557 :
3558 : virtual bool SetStatistics(bool bApproxStats, double dfMin, double dfMax,
3559 : double dfMean, double dfStdDev,
3560 : GUInt64 nValidCount, CSLConstList papszOptions);
3561 :
3562 : static std::string MassageName(const std::string &inputName);
3563 :
3564 : std::shared_ptr<GDALGroup>
3565 : GetCacheRootGroup(bool bCanCreate, std::string &osCacheFilenameOut) const;
3566 :
3567 : // Returns if bufferStride values express a transposed view of the array
3568 : bool IsTransposedRequest(const size_t *count,
3569 : const GPtrDiff_t *bufferStride) const;
3570 :
3571 : // Should only be called if IsTransposedRequest() returns true
3572 : bool ReadForTransposedRequest(const GUInt64 *arrayStartIdx,
3573 : const size_t *count, const GInt64 *arrayStep,
3574 : const GPtrDiff_t *bufferStride,
3575 : const GDALExtendedDataType &bufferDataType,
3576 : void *pDstBuffer) const;
3577 :
3578 : bool IsStepOneContiguousRowMajorOrderedSameDataType(
3579 : const size_t *count, const GInt64 *arrayStep,
3580 : const GPtrDiff_t *bufferStride,
3581 : const GDALExtendedDataType &bufferDataType) const;
3582 :
3583 : // Should only be called if IsStepOneContiguousRowMajorOrderedSameDataType()
3584 : // returns false
3585 : bool ReadUsingContiguousIRead(const GUInt64 *arrayStartIdx,
3586 : const size_t *count, const GInt64 *arrayStep,
3587 : const GPtrDiff_t *bufferStride,
3588 : const GDALExtendedDataType &bufferDataType,
3589 : void *pDstBuffer) const;
3590 :
3591 : static std::shared_ptr<GDALMDArray> CreateGLTOrthorectified(
3592 : const std::shared_ptr<GDALMDArray> &poParent,
3593 : const std::shared_ptr<GDALGroup> &poRootGroup,
3594 : const std::shared_ptr<GDALMDArray> &poGLTX,
3595 : const std::shared_ptr<GDALMDArray> &poGLTY, int nGLTIndexOffset,
3596 : const std::vector<double> &adfGeoTransform, CSLConstList papszOptions);
3597 :
3598 : //! @endcond
3599 :
3600 : public:
3601 : GUInt64 GetTotalCopyCost() const;
3602 :
3603 : virtual bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray,
3604 : bool bStrict, GUInt64 &nCurCost,
3605 : const GUInt64 nTotalCost,
3606 : GDALProgressFunc pfnProgress, void *pProgressData);
3607 :
3608 : /** Return whether an array is writable. */
3609 : virtual bool IsWritable() const = 0;
3610 :
3611 : /** Return the filename that contains that array.
3612 : *
3613 : * This is used in particular for caching.
3614 : *
3615 : * Might be empty if the array is not linked to a file.
3616 : *
3617 : * @since GDAL 3.4
3618 : */
3619 : virtual const std::string &GetFilename() const = 0;
3620 :
3621 : virtual CSLConstList GetStructuralInfo() const;
3622 :
3623 : virtual const std::string &GetUnit() const;
3624 :
3625 : virtual bool SetUnit(const std::string &osUnit);
3626 :
3627 : virtual bool SetSpatialRef(const OGRSpatialReference *poSRS);
3628 :
3629 : virtual std::shared_ptr<OGRSpatialReference> GetSpatialRef() const;
3630 :
3631 : virtual const void *GetRawNoDataValue() const;
3632 :
3633 : double GetNoDataValueAsDouble(bool *pbHasNoData = nullptr) const;
3634 :
3635 : int64_t GetNoDataValueAsInt64(bool *pbHasNoData = nullptr) const;
3636 :
3637 : uint64_t GetNoDataValueAsUInt64(bool *pbHasNoData = nullptr) const;
3638 :
3639 : virtual bool SetRawNoDataValue(const void *pRawNoData);
3640 :
3641 : //! @cond Doxygen_Suppress
3642 2 : bool SetNoDataValue(int nNoData)
3643 : {
3644 2 : return SetNoDataValue(static_cast<int64_t>(nNoData));
3645 : }
3646 :
3647 : //! @endcond
3648 :
3649 : bool SetNoDataValue(double dfNoData);
3650 :
3651 : bool SetNoDataValue(int64_t nNoData);
3652 :
3653 : bool SetNoDataValue(uint64_t nNoData);
3654 :
3655 : virtual bool Resize(const std::vector<GUInt64> &anNewDimSizes,
3656 : CSLConstList papszOptions);
3657 :
3658 : virtual double GetOffset(bool *pbHasOffset = nullptr,
3659 : GDALDataType *peStorageType = nullptr) const;
3660 :
3661 : virtual double GetScale(bool *pbHasScale = nullptr,
3662 : GDALDataType *peStorageType = nullptr) const;
3663 :
3664 : virtual bool SetOffset(double dfOffset,
3665 : GDALDataType eStorageType = GDT_Unknown);
3666 :
3667 : virtual bool SetScale(double dfScale,
3668 : GDALDataType eStorageType = GDT_Unknown);
3669 :
3670 : std::shared_ptr<GDALMDArray> GetView(const std::string &viewExpr) const;
3671 :
3672 : std::shared_ptr<GDALMDArray> operator[](const std::string &fieldName) const;
3673 :
3674 : /** Return a view of the array using integer indexing.
3675 : *
3676 : * Equivalent of GetView("[indices_0,indices_1,.....,indices_last]")
3677 : *
3678 : * Example:
3679 : * \code
3680 : * ar->at(0,3,2)
3681 : * \endcode
3682 : */
3683 : // sphinx 4.1.0 / breathe 4.30.0 don't like typename...
3684 : //! @cond Doxygen_Suppress
3685 : template <typename... GUInt64VarArg>
3686 : //! @endcond
3687 : // cppcheck-suppress functionStatic
3688 19 : std::shared_ptr<GDALMDArray> at(GUInt64 idx, GUInt64VarArg... tail) const
3689 : {
3690 38 : std::vector<GUInt64> indices;
3691 19 : indices.push_back(idx);
3692 38 : return atInternal(indices, tail...);
3693 : }
3694 :
3695 : virtual std::shared_ptr<GDALMDArray>
3696 : Transpose(const std::vector<int> &anMapNewAxisToOldAxis) const;
3697 :
3698 : std::shared_ptr<GDALMDArray> GetUnscaled(
3699 : double dfOverriddenScale = cpl::NumericLimits<double>::quiet_NaN(),
3700 : double dfOverriddenOffset = cpl::NumericLimits<double>::quiet_NaN(),
3701 : double dfOverriddenDstNodata =
3702 : cpl::NumericLimits<double>::quiet_NaN()) const;
3703 :
3704 : virtual std::shared_ptr<GDALMDArray>
3705 : GetMask(CSLConstList papszOptions) const;
3706 :
3707 : virtual std::shared_ptr<GDALMDArray>
3708 : GetResampled(const std::vector<std::shared_ptr<GDALDimension>> &apoNewDims,
3709 : GDALRIOResampleAlg resampleAlg,
3710 : const OGRSpatialReference *poTargetSRS,
3711 : CSLConstList papszOptions) const;
3712 :
3713 : std::shared_ptr<GDALMDArray>
3714 : GetGridded(const std::string &osGridOptions,
3715 : const std::shared_ptr<GDALMDArray> &poXArray = nullptr,
3716 : const std::shared_ptr<GDALMDArray> &poYArray = nullptr,
3717 : CSLConstList papszOptions = nullptr) const;
3718 :
3719 : static std::vector<std::shared_ptr<GDALMDArray>>
3720 : GetMeshGrid(const std::vector<std::shared_ptr<GDALMDArray>> &apoArrays,
3721 : CSLConstList papszOptions = nullptr);
3722 :
3723 : virtual GDALDataset *
3724 : AsClassicDataset(size_t iXDim, size_t iYDim,
3725 : const std::shared_ptr<GDALGroup> &poRootGroup = nullptr,
3726 : CSLConstList papszOptions = nullptr) const;
3727 :
3728 : virtual CPLErr GetStatistics(bool bApproxOK, bool bForce, double *pdfMin,
3729 : double *pdfMax, double *pdfMean,
3730 : double *padfStdDev, GUInt64 *pnValidCount,
3731 : GDALProgressFunc pfnProgress,
3732 : void *pProgressData);
3733 :
3734 : virtual bool ComputeStatistics(bool bApproxOK, double *pdfMin,
3735 : double *pdfMax, double *pdfMean,
3736 : double *pdfStdDev, GUInt64 *pnValidCount,
3737 : GDALProgressFunc, void *pProgressData,
3738 : CSLConstList papszOptions);
3739 :
3740 : virtual void ClearStatistics();
3741 :
3742 : virtual std::vector<std::shared_ptr<GDALMDArray>>
3743 : GetCoordinateVariables() const;
3744 :
3745 : bool AdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
3746 : CSLConstList papszOptions = nullptr) const;
3747 :
3748 : bool IsRegularlySpaced(double &dfStart, double &dfIncrement) const;
3749 :
3750 : bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
3751 : double adfGeoTransform[6]) const;
3752 :
3753 : bool Cache(CSLConstList papszOptions = nullptr) const;
3754 :
3755 : bool
3756 : Read(const GUInt64 *arrayStartIdx, // array of size GetDimensionCount()
3757 : const size_t *count, // array of size GetDimensionCount()
3758 : const GInt64 *arrayStep, // step in elements
3759 : const GPtrDiff_t *bufferStride, // stride in elements
3760 : const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
3761 : const void *pDstBufferAllocStart = nullptr,
3762 : size_t nDstBufferAllocSize = 0) const override final;
3763 :
3764 : virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
3765 :
3766 : //! @cond Doxygen_Suppress
3767 : static constexpr GUInt64 COPY_COST = 1000;
3768 :
3769 : bool CopyFromAllExceptValues(const GDALMDArray *poSrcArray, bool bStrict,
3770 : GUInt64 &nCurCost, const GUInt64 nTotalCost,
3771 : GDALProgressFunc pfnProgress,
3772 : void *pProgressData);
3773 :
3774 : struct Range
3775 : {
3776 : GUInt64 m_nStartIdx;
3777 : GInt64 m_nIncr;
3778 :
3779 1308 : explicit Range(GUInt64 nStartIdx = 0, GInt64 nIncr = 0)
3780 1308 : : m_nStartIdx(nStartIdx), m_nIncr(nIncr)
3781 : {
3782 1308 : }
3783 : };
3784 :
3785 : struct ViewSpec
3786 : {
3787 : std::string m_osFieldName{};
3788 :
3789 : // or
3790 :
3791 : std::vector<size_t>
3792 : m_mapDimIdxToParentDimIdx{}; // of size m_dims.size()
3793 : std::vector<Range>
3794 : m_parentRanges{}; // of size m_poParent->GetDimensionCount()
3795 : };
3796 :
3797 : virtual std::shared_ptr<GDALMDArray>
3798 : GetView(const std::string &viewExpr, bool bRenameDimensions,
3799 : std::vector<ViewSpec> &viewSpecs) const;
3800 :
3801 1033 : const std::string &GetContext() const
3802 : {
3803 1033 : return m_osContext;
3804 : }
3805 :
3806 : //! @endcond
3807 : };
3808 :
3809 : //! @cond Doxygen_Suppress
3810 : bool GDALMDRasterIOFromBand(GDALRasterBand *poBand, GDALRWFlag eRWFlag,
3811 : size_t iDimX, size_t iDimY,
3812 : const GUInt64 *arrayStartIdx, const size_t *count,
3813 : const GInt64 *arrayStep,
3814 : const GPtrDiff_t *bufferStride,
3815 : const GDALExtendedDataType &bufferDataType,
3816 : void *pBuffer);
3817 :
3818 : //! @endcond
3819 :
3820 : /************************************************************************/
3821 : /* GDALMDArrayRegularlySpaced */
3822 : /************************************************************************/
3823 :
3824 : //! @cond Doxygen_Suppress
3825 : class CPL_DLL GDALMDArrayRegularlySpaced : public GDALMDArray
3826 : {
3827 : double m_dfStart;
3828 : double m_dfIncrement;
3829 : double m_dfOffsetInIncrement;
3830 : GDALExtendedDataType m_dt = GDALExtendedDataType::Create(GDT_Float64);
3831 : std::vector<std::shared_ptr<GDALDimension>> m_dims;
3832 : std::vector<std::shared_ptr<GDALAttribute>> m_attributes{};
3833 : std::string m_osEmptyFilename{};
3834 :
3835 : protected:
3836 : bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
3837 : const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
3838 : void *pDstBuffer) const override;
3839 :
3840 : public:
3841 : GDALMDArrayRegularlySpaced(const std::string &osParentName,
3842 : const std::string &osName,
3843 : const std::shared_ptr<GDALDimension> &poDim,
3844 : double dfStart, double dfIncrement,
3845 : double dfOffsetInIncrement);
3846 :
3847 : static std::shared_ptr<GDALMDArrayRegularlySpaced>
3848 : Create(const std::string &osParentName, const std::string &osName,
3849 : const std::shared_ptr<GDALDimension> &poDim, double dfStart,
3850 : double dfIncrement, double dfOffsetInIncrement);
3851 :
3852 0 : bool IsWritable() const override
3853 : {
3854 0 : return false;
3855 : }
3856 :
3857 104 : const std::string &GetFilename() const override
3858 : {
3859 104 : return m_osEmptyFilename;
3860 : }
3861 :
3862 : const std::vector<std::shared_ptr<GDALDimension>> &
3863 : GetDimensions() const override;
3864 :
3865 : const GDALExtendedDataType &GetDataType() const override;
3866 :
3867 : std::vector<std::shared_ptr<GDALAttribute>>
3868 : GetAttributes(CSLConstList) const override;
3869 :
3870 : void AddAttribute(const std::shared_ptr<GDALAttribute> &poAttr);
3871 : };
3872 :
3873 : //! @endcond
3874 :
3875 : /* ******************************************************************** */
3876 : /* GDALDimension */
3877 : /* ******************************************************************** */
3878 :
3879 : /**
3880 : * Class modeling a a dimension / axis used to index multidimensional arrays.
3881 : * It has a name, a size (that is the number of values that can be indexed along
3882 : * the dimension), a type (see GDALDimension::GetType()), a direction
3883 : * (see GDALDimension::GetDirection()), a unit and can optionally point to a
3884 : * GDALMDArray variable, typically one-dimensional, describing the values taken
3885 : * by the dimension. For a georeferenced GDALMDArray and its X dimension, this
3886 : * will be typically the values of the easting/longitude for each grid point.
3887 : *
3888 : * @since GDAL 3.1
3889 : */
3890 8145 : class CPL_DLL GDALDimension
3891 : {
3892 : public:
3893 : //! @cond Doxygen_Suppress
3894 : GDALDimension(const std::string &osParentName, const std::string &osName,
3895 : const std::string &osType, const std::string &osDirection,
3896 : GUInt64 nSize);
3897 : //! @endcond
3898 :
3899 : virtual ~GDALDimension();
3900 :
3901 : /** Return the name.
3902 : *
3903 : * This is the same as the C function GDALDimensionGetName()
3904 : */
3905 7871 : const std::string &GetName() const
3906 : {
3907 7871 : return m_osName;
3908 : }
3909 :
3910 : /** Return the full name.
3911 : *
3912 : * This is the same as the C function GDALDimensionGetFullName()
3913 : */
3914 1226 : const std::string &GetFullName() const
3915 : {
3916 1226 : return m_osFullName;
3917 : }
3918 :
3919 : /** Return the axis type.
3920 : *
3921 : * Predefined values are:
3922 : * HORIZONTAL_X, HORIZONTAL_Y, VERTICAL, TEMPORAL, PARAMETRIC
3923 : * Other values might be returned. Empty value means unknown.
3924 : *
3925 : * This is the same as the C function GDALDimensionGetType()
3926 : */
3927 1703 : const std::string &GetType() const
3928 : {
3929 1703 : return m_osType;
3930 : }
3931 :
3932 : /** Return the axis direction.
3933 : *
3934 : * Predefined values are:
3935 : * EAST, WEST, SOUTH, NORTH, UP, DOWN, FUTURE, PAST
3936 : * Other values might be returned. Empty value means unknown.
3937 : *
3938 : * This is the same as the C function GDALDimensionGetDirection()
3939 : */
3940 833 : const std::string &GetDirection() const
3941 : {
3942 833 : return m_osDirection;
3943 : }
3944 :
3945 : /** Return the size, that is the number of values along the dimension.
3946 : *
3947 : * This is the same as the C function GDALDimensionGetSize()
3948 : */
3949 80144 : GUInt64 GetSize() const
3950 : {
3951 80144 : return m_nSize;
3952 : }
3953 :
3954 : virtual std::shared_ptr<GDALMDArray> GetIndexingVariable() const;
3955 :
3956 : virtual bool
3957 : SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable);
3958 :
3959 : virtual bool Rename(const std::string &osNewName);
3960 :
3961 : //! @cond Doxygen_Suppress
3962 : virtual void ParentRenamed(const std::string &osNewParentFullName);
3963 :
3964 : virtual void ParentDeleted();
3965 : //! @endcond
3966 :
3967 : protected:
3968 : //! @cond Doxygen_Suppress
3969 : std::string m_osName;
3970 : std::string m_osFullName;
3971 : std::string m_osType;
3972 : std::string m_osDirection;
3973 : GUInt64 m_nSize;
3974 :
3975 : void BaseRename(const std::string &osNewName);
3976 :
3977 : //! @endcond
3978 : };
3979 :
3980 : /************************************************************************/
3981 : /* GDALDimensionWeakIndexingVar() */
3982 : /************************************************************************/
3983 :
3984 : //! @cond Doxygen_Suppress
3985 : class CPL_DLL GDALDimensionWeakIndexingVar : public GDALDimension
3986 : {
3987 : std::weak_ptr<GDALMDArray> m_poIndexingVariable{};
3988 :
3989 : public:
3990 : GDALDimensionWeakIndexingVar(const std::string &osParentName,
3991 : const std::string &osName,
3992 : const std::string &osType,
3993 : const std::string &osDirection, GUInt64 nSize);
3994 :
3995 : std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
3996 :
3997 : bool SetIndexingVariable(
3998 : std::shared_ptr<GDALMDArray> poIndexingVariable) override;
3999 :
4000 : void SetSize(GUInt64 nNewSize);
4001 : };
4002 : //! @endcond
4003 :
4004 : /************************************************************************/
4005 : /* GDALAntiRecursionGuard */
4006 : /************************************************************************/
4007 :
4008 : //! @cond Doxygen_Suppress
4009 : struct GDALAntiRecursionStruct;
4010 :
4011 : class GDALAntiRecursionGuard
4012 : {
4013 : GDALAntiRecursionStruct *m_psAntiRecursionStruct;
4014 : std::string m_osIdentifier;
4015 : int m_nDepth;
4016 :
4017 : GDALAntiRecursionGuard(const GDALAntiRecursionGuard &) = delete;
4018 : GDALAntiRecursionGuard &operator=(const GDALAntiRecursionGuard &) = delete;
4019 :
4020 : public:
4021 : explicit GDALAntiRecursionGuard(const std::string &osIdentifier);
4022 : GDALAntiRecursionGuard(const GDALAntiRecursionGuard &other,
4023 : const std::string &osIdentifier);
4024 : ~GDALAntiRecursionGuard();
4025 :
4026 108892 : int GetCallDepth() const
4027 : {
4028 108892 : return m_nDepth;
4029 : }
4030 : };
4031 :
4032 : //! @endcond
4033 :
4034 : /************************************************************************/
4035 : /* Relationships */
4036 : /************************************************************************/
4037 :
4038 : /**
4039 : * Definition of a table relationship.
4040 : *
4041 : * GDALRelationship describes the relationship between two tables, including
4042 : * properties such as the cardinality of the relationship and the participating
4043 : * tables.
4044 : *
4045 : * Not all relationship properties are supported by all data formats.
4046 : *
4047 : * @since GDAL 3.6
4048 : */
4049 : class CPL_DLL GDALRelationship
4050 : {
4051 : protected:
4052 : /*! @cond Doxygen_Suppress */
4053 : std::string m_osName{};
4054 : std::string m_osLeftTableName{};
4055 : std::string m_osRightTableName{};
4056 : GDALRelationshipCardinality m_eCardinality =
4057 : GDALRelationshipCardinality::GRC_ONE_TO_MANY;
4058 : std::string m_osMappingTableName{};
4059 : std::vector<std::string> m_osListLeftTableFields{};
4060 : std::vector<std::string> m_osListRightTableFields{};
4061 : std::vector<std::string> m_osListLeftMappingTableFields{};
4062 : std::vector<std::string> m_osListRightMappingTableFields{};
4063 : GDALRelationshipType m_eType = GDALRelationshipType::GRT_ASSOCIATION;
4064 : std::string m_osForwardPathLabel{};
4065 : std::string m_osBackwardPathLabel{};
4066 : std::string m_osRelatedTableType{};
4067 :
4068 : /*! @endcond */
4069 :
4070 : public:
4071 : /**
4072 : * Constructor for a relationship between two tables.
4073 : * @param osName relationship name
4074 : * @param osLeftTableName left table name
4075 : * @param osRightTableName right table name
4076 : * @param eCardinality cardinality of relationship
4077 : */
4078 349 : GDALRelationship(const std::string &osName,
4079 : const std::string &osLeftTableName,
4080 : const std::string &osRightTableName,
4081 : GDALRelationshipCardinality eCardinality =
4082 : GDALRelationshipCardinality::GRC_ONE_TO_MANY)
4083 349 : : m_osName(osName), m_osLeftTableName(osLeftTableName),
4084 349 : m_osRightTableName(osRightTableName), m_eCardinality(eCardinality)
4085 : {
4086 349 : }
4087 :
4088 : /** Get the name of the relationship */
4089 393 : const std::string &GetName() const
4090 : {
4091 393 : return m_osName;
4092 : }
4093 :
4094 : /** Get the cardinality of the relationship */
4095 247 : GDALRelationshipCardinality GetCardinality() const
4096 : {
4097 247 : return m_eCardinality;
4098 : }
4099 :
4100 : /** Get the name of the left (or base/origin) table in the relationship.
4101 : *
4102 : * @see GetRightTableName()
4103 : */
4104 202 : const std::string &GetLeftTableName() const
4105 : {
4106 202 : return m_osLeftTableName;
4107 : }
4108 :
4109 : /** Get the name of the right (or related/destination) table in the
4110 : * relationship */
4111 197 : const std::string &GetRightTableName() const
4112 : {
4113 197 : return m_osRightTableName;
4114 : }
4115 :
4116 : /** Get the name of the mapping table for many-to-many relationships.
4117 : *
4118 : * @see SetMappingTableName()
4119 : */
4120 160 : const std::string &GetMappingTableName() const
4121 : {
4122 160 : return m_osMappingTableName;
4123 : }
4124 :
4125 : /** Sets the name of the mapping table for many-to-many relationships.
4126 : *
4127 : * @see GetMappingTableName()
4128 : */
4129 113 : void SetMappingTableName(const std::string &osName)
4130 : {
4131 113 : m_osMappingTableName = osName;
4132 113 : }
4133 :
4134 : /** Get the names of the participating fields from the left table in the
4135 : * relationship.
4136 : *
4137 : * @see GetRightTableFields()
4138 : * @see SetLeftTableFields()
4139 : */
4140 157 : const std::vector<std::string> &GetLeftTableFields() const
4141 : {
4142 157 : return m_osListLeftTableFields;
4143 : }
4144 :
4145 : /** Get the names of the participating fields from the right table in the
4146 : * relationship.
4147 : *
4148 : * @see GetLeftTableFields()
4149 : * @see SetRightTableFields()
4150 : */
4151 151 : const std::vector<std::string> &GetRightTableFields() const
4152 : {
4153 151 : return m_osListRightTableFields;
4154 : }
4155 :
4156 : /** Sets the names of the participating fields from the left table in the
4157 : * relationship.
4158 : *
4159 : * @see GetLeftTableFields()
4160 : * @see SetRightTableFields()
4161 : */
4162 362 : void SetLeftTableFields(const std::vector<std::string> &osListFields)
4163 : {
4164 362 : m_osListLeftTableFields = osListFields;
4165 362 : }
4166 :
4167 : /** Sets the names of the participating fields from the right table in the
4168 : * relationship.
4169 : *
4170 : * @see GetRightTableFields()
4171 : * @see SetLeftTableFields()
4172 : */
4173 363 : void SetRightTableFields(const std::vector<std::string> &osListFields)
4174 : {
4175 363 : m_osListRightTableFields = osListFields;
4176 363 : }
4177 :
4178 : /** Get the names of the mapping table fields which correspond to the
4179 : * participating fields from the left table in the relationship.
4180 : *
4181 : * @see GetRightMappingTableFields()
4182 : * @see SetLeftMappingTableFields()
4183 : */
4184 61 : const std::vector<std::string> &GetLeftMappingTableFields() const
4185 : {
4186 61 : return m_osListLeftMappingTableFields;
4187 : }
4188 :
4189 : /** Get the names of the mapping table fields which correspond to the
4190 : * participating fields from the right table in the relationship.
4191 : *
4192 : * @see GetLeftMappingTableFields()
4193 : * @see SetRightMappingTableFields()
4194 : */
4195 61 : const std::vector<std::string> &GetRightMappingTableFields() const
4196 : {
4197 61 : return m_osListRightMappingTableFields;
4198 : }
4199 :
4200 : /** Sets the names of the mapping table fields which correspond to the
4201 : * participating fields from the left table in the relationship.
4202 : *
4203 : * @see GetLeftMappingTableFields()
4204 : * @see SetRightMappingTableFields()
4205 : */
4206 313 : void SetLeftMappingTableFields(const std::vector<std::string> &osListFields)
4207 : {
4208 313 : m_osListLeftMappingTableFields = osListFields;
4209 313 : }
4210 :
4211 : /** Sets the names of the mapping table fields which correspond to the
4212 : * participating fields from the right table in the relationship.
4213 : *
4214 : * @see GetRightMappingTableFields()
4215 : * @see SetLeftMappingTableFields()
4216 : */
4217 : void
4218 313 : SetRightMappingTableFields(const std::vector<std::string> &osListFields)
4219 : {
4220 313 : m_osListRightMappingTableFields = osListFields;
4221 313 : }
4222 :
4223 : /** Get the type of the relationship.
4224 : *
4225 : * @see SetType()
4226 : */
4227 111 : GDALRelationshipType GetType() const
4228 : {
4229 111 : return m_eType;
4230 : }
4231 :
4232 : /** Sets the type of the relationship.
4233 : *
4234 : * @see GetType()
4235 : */
4236 263 : void SetType(GDALRelationshipType eType)
4237 : {
4238 263 : m_eType = eType;
4239 263 : }
4240 :
4241 : /** Get the label of the forward path for the relationship.
4242 : *
4243 : * The forward and backward path labels are free-form, user-friendly strings
4244 : * which can be used to generate descriptions of the relationship between
4245 : * features from the right and left tables.
4246 : *
4247 : * E.g. when the left table contains buildings and the right table contains
4248 : * furniture, the forward path label could be "contains" and the backward
4249 : * path label could be "is located within". A client could then generate a
4250 : * user friendly description string such as "fire hose 1234 is located
4251 : * within building 15a".
4252 : *
4253 : * @see SetForwardPathLabel()
4254 : * @see GetBackwardPathLabel()
4255 : */
4256 53 : const std::string &GetForwardPathLabel() const
4257 : {
4258 53 : return m_osForwardPathLabel;
4259 : }
4260 :
4261 : /** Sets the label of the forward path for the relationship.
4262 : *
4263 : * The forward and backward path labels are free-form, user-friendly strings
4264 : * which can be used to generate descriptions of the relationship between
4265 : * features from the right and left tables.
4266 : *
4267 : * E.g. when the left table contains buildings and the right table contains
4268 : * furniture, the forward path label could be "contains" and the backward
4269 : * path label could be "is located within". A client could then generate a
4270 : * user friendly description string such as "fire hose 1234 is located
4271 : * within building 15a".
4272 : *
4273 : * @see GetForwardPathLabel()
4274 : * @see SetBackwardPathLabel()
4275 : */
4276 260 : void SetForwardPathLabel(const std::string &osLabel)
4277 : {
4278 260 : m_osForwardPathLabel = osLabel;
4279 260 : }
4280 :
4281 : /** Get the label of the backward path for the relationship.
4282 : *
4283 : * The forward and backward path labels are free-form, user-friendly strings
4284 : * which can be used to generate descriptions of the relationship between
4285 : * features from the right and left tables.
4286 : *
4287 : * E.g. when the left table contains buildings and the right table contains
4288 : * furniture, the forward path label could be "contains" and the backward
4289 : * path label could be "is located within". A client could then generate a
4290 : * user friendly description string such as "fire hose 1234 is located
4291 : * within building 15a".
4292 : *
4293 : * @see SetBackwardPathLabel()
4294 : * @see GetForwardPathLabel()
4295 : */
4296 53 : const std::string &GetBackwardPathLabel() const
4297 : {
4298 53 : return m_osBackwardPathLabel;
4299 : }
4300 :
4301 : /** Sets the label of the backward path for the relationship.
4302 : *
4303 : * The forward and backward path labels are free-form, user-friendly strings
4304 : * which can be used to generate descriptions of the relationship between
4305 : * features from the right and left tables.
4306 : *
4307 : * E.g. when the left table contains buildings and the right table contains
4308 : * furniture, the forward path label could be "contains" and the backward
4309 : * path label could be "is located within". A client could then generate a
4310 : * user friendly description string such as "fire hose 1234 is located
4311 : * within building 15a".
4312 : *
4313 : * @see GetBackwardPathLabel()
4314 : * @see SetForwardPathLabel()
4315 : */
4316 260 : void SetBackwardPathLabel(const std::string &osLabel)
4317 : {
4318 260 : m_osBackwardPathLabel = osLabel;
4319 260 : }
4320 :
4321 : /** Get the type string of the related table.
4322 : *
4323 : * This a free-form string representing the type of related features, where
4324 : * the exact interpretation is format dependent. For instance, table types
4325 : * from GeoPackage relationships will directly reflect the categories from
4326 : * the GeoPackage related tables extension (i.e. "media", "simple
4327 : * attributes", "features", "attributes" and "tiles").
4328 : *
4329 : * @see SetRelatedTableType()
4330 : */
4331 144 : const std::string &GetRelatedTableType() const
4332 : {
4333 144 : return m_osRelatedTableType;
4334 : }
4335 :
4336 : /** Sets the type string of the related table.
4337 : *
4338 : * This a free-form string representing the type of related features, where
4339 : * the exact interpretation is format dependent. For instance, table types
4340 : * from GeoPackage relationships will directly reflect the categories from
4341 : * the GeoPackage related tables extension (i.e. "media", "simple
4342 : * attributes", "features", "attributes" and "tiles").
4343 : *
4344 : * @see GetRelatedTableType()
4345 : */
4346 340 : void SetRelatedTableType(const std::string &osType)
4347 : {
4348 340 : m_osRelatedTableType = osType;
4349 340 : }
4350 :
4351 : /** Convert a GDALRelationship* to a GDALRelationshipH.
4352 : */
4353 81 : static inline GDALRelationshipH ToHandle(GDALRelationship *poRelationship)
4354 : {
4355 81 : return static_cast<GDALRelationshipH>(poRelationship);
4356 : }
4357 :
4358 : /** Convert a GDALRelationshipH to a GDALRelationship*.
4359 : */
4360 706 : static inline GDALRelationship *FromHandle(GDALRelationshipH hRelationship)
4361 : {
4362 706 : return static_cast<GDALRelationship *>(hRelationship);
4363 : }
4364 : };
4365 :
4366 : /* ==================================================================== */
4367 : /* An assortment of overview related stuff. */
4368 : /* ==================================================================== */
4369 :
4370 : //! @cond Doxygen_Suppress
4371 : /* Only exported for drivers as plugin. Signature may change */
4372 : CPLErr CPL_DLL GDALRegenerateOverviewsMultiBand(
4373 : int nBands, GDALRasterBand *const *papoSrcBands, int nOverviews,
4374 : GDALRasterBand *const *const *papapoOverviewBands,
4375 : const char *pszResampling, GDALProgressFunc pfnProgress,
4376 : void *pProgressData, CSLConstList papszOptions);
4377 :
4378 : CPLErr CPL_DLL GDALRegenerateOverviewsMultiBand(
4379 : const std::vector<GDALRasterBand *> &apoSrcBands,
4380 : // First level of array is indexed by band (thus aapoOverviewBands.size() must be equal to apoSrcBands.size())
4381 : // Second level is indexed by overview
4382 : const std::vector<std::vector<GDALRasterBand *>> &aapoOverviewBands,
4383 : const char *pszResampling, GDALProgressFunc pfnProgress,
4384 : void *pProgressData, CSLConstList papszOptions);
4385 :
4386 : /************************************************************************/
4387 : /* GDALOverviewResampleArgs */
4388 : /************************************************************************/
4389 :
4390 : /** Arguments for overview resampling function. */
4391 : // Should not contain any dataset/rasterband object, as this might be
4392 : // read in a worker thread.
4393 : struct GDALOverviewResampleArgs
4394 : {
4395 : //! Datatype of the source band argument
4396 : GDALDataType eSrcDataType = GDT_Unknown;
4397 : //! Datatype of the destination/overview band
4398 : GDALDataType eOvrDataType = GDT_Unknown;
4399 : //! Width in pixel of the destination/overview band
4400 : int nOvrXSize = 0;
4401 : //! Height in pixel of the destination/overview band
4402 : int nOvrYSize = 0;
4403 : //! NBITS value of the destination/overview band (or 0 if not set)
4404 : int nOvrNBITS = 0;
4405 : //! Factor to convert from destination X to source X
4406 : // (source width divided by destination width)
4407 : double dfXRatioDstToSrc = 0;
4408 : //! Factor to convert from destination Y to source Y
4409 : // (source height divided by destination height)
4410 : double dfYRatioDstToSrc = 0;
4411 : //! Sub-pixel delta to add to get source X
4412 : double dfSrcXDelta = 0;
4413 : //! Sub-pixel delta to add to get source Y
4414 : double dfSrcYDelta = 0;
4415 : //! Working data type (data type of the pChunk argument)
4416 : GDALDataType eWrkDataType = GDT_Unknown;
4417 : //! Array of nChunkXSize * nChunkYSize values of mask, or nullptr
4418 : const GByte *pabyChunkNodataMask = nullptr;
4419 : //! X offset of the source chunk in the source band
4420 : int nChunkXOff = 0;
4421 : //! Width in pixel of the source chunk in the source band
4422 : int nChunkXSize = 0;
4423 : //! Y offset of the source chunk in the source band
4424 : int nChunkYOff = 0;
4425 : //! Height in pixel of the source chunk in the source band
4426 : int nChunkYSize = 0;
4427 : //! X Offset of the destination chunk in the destination band
4428 : int nDstXOff = 0;
4429 : //! X Offset of the end (not included) of the destination chunk in the destination band
4430 : int nDstXOff2 = 0;
4431 : //! Y Offset of the destination chunk in the destination band
4432 : int nDstYOff = 0;
4433 : //! Y Offset of the end (not included) of the destination chunk in the destination band
4434 : int nDstYOff2 = 0;
4435 : //! Resampling method
4436 : const char *pszResampling = nullptr;
4437 : //! Whether the source band has a nodata value
4438 : bool bHasNoData = false;
4439 : //! Source band nodata value
4440 : double dfNoDataValue = 0;
4441 : //! Source color table
4442 : const GDALColorTable *poColorTable = nullptr;
4443 : //! Whether a single contributing source pixel at nodata should result
4444 : // in the target pixel to be at nodata too (only taken into account by
4445 : // average resampling)
4446 : bool bPropagateNoData = false;
4447 : };
4448 :
4449 : typedef CPLErr (*GDALResampleFunction)(const GDALOverviewResampleArgs &args,
4450 : const void *pChunk, void **ppDstBuffer,
4451 : GDALDataType *peDstBufferDataType);
4452 :
4453 : GDALResampleFunction GDALGetResampleFunction(const char *pszResampling,
4454 : int *pnRadius);
4455 :
4456 : std::string CPL_DLL GDALGetNormalizedOvrResampling(const char *pszResampling);
4457 :
4458 : GDALDataType GDALGetOvrWorkDataType(const char *pszResampling,
4459 : GDALDataType eSrcDataType);
4460 :
4461 : CPL_C_START
4462 :
4463 : CPLErr CPL_DLL
4464 : HFAAuxBuildOverviews(const char *pszOvrFilename, GDALDataset *poParentDS,
4465 : GDALDataset **ppoDS, int nBands, const int *panBandList,
4466 : int nNewOverviews, const int *panNewOverviewList,
4467 : const char *pszResampling, GDALProgressFunc pfnProgress,
4468 : void *pProgressData, CSLConstList papszOptions);
4469 :
4470 : CPLErr CPL_DLL GTIFFBuildOverviews(const char *pszFilename, int nBands,
4471 : GDALRasterBand *const *papoBandList,
4472 : int nOverviews, const int *panOverviewList,
4473 : const char *pszResampling,
4474 : GDALProgressFunc pfnProgress,
4475 : void *pProgressData,
4476 : CSLConstList papszOptions);
4477 :
4478 : int CPL_DLL GDALBandGetBestOverviewLevel(GDALRasterBand *poBand, int &nXOff,
4479 : int &nYOff, int &nXSize, int &nYSize,
4480 : int nBufXSize, int nBufYSize)
4481 : CPL_WARN_DEPRECATED("Use GDALBandGetBestOverviewLevel2 instead");
4482 : int CPL_DLL GDALBandGetBestOverviewLevel2(GDALRasterBand *poBand, int &nXOff,
4483 : int &nYOff, int &nXSize, int &nYSize,
4484 : int nBufXSize, int nBufYSize,
4485 : GDALRasterIOExtraArg *psExtraArg);
4486 :
4487 : int CPL_DLL GDALOvLevelAdjust(int nOvLevel, int nXSize)
4488 : CPL_WARN_DEPRECATED("Use GDALOvLevelAdjust2 instead");
4489 : int CPL_DLL GDALOvLevelAdjust2(int nOvLevel, int nXSize, int nYSize);
4490 : int CPL_DLL GDALComputeOvFactor(int nOvrXSize, int nRasterXSize, int nOvrYSize,
4491 : int nRasterYSize);
4492 :
4493 : GDALDataset CPL_DLL *GDALFindAssociatedAuxFile(const char *pszBasefile,
4494 : GDALAccess eAccess,
4495 : GDALDataset *poDependentDS);
4496 :
4497 : /* ==================================================================== */
4498 : /* Infrastructure to check that dataset characteristics are valid */
4499 : /* ==================================================================== */
4500 :
4501 : int CPL_DLL GDALCheckDatasetDimensions(int nXSize, int nYSize);
4502 : int CPL_DLL GDALCheckBandCount(int nBands, int bIsZeroAllowed);
4503 :
4504 : /* Internal use only */
4505 :
4506 : /* CPL_DLL exported, but only for in-tree drivers that can be built as plugins
4507 : */
4508 : int CPL_DLL GDALReadWorldFile2(const char *pszBaseFilename,
4509 : const char *pszExtension,
4510 : double *padfGeoTransform,
4511 : CSLConstList papszSiblingFiles,
4512 : char **ppszWorldFileNameOut);
4513 : int CPL_DLL GDALReadTabFile2(const char *pszBaseFilename,
4514 : double *padfGeoTransform, char **ppszWKT,
4515 : int *pnGCPCount, GDAL_GCP **ppasGCPs,
4516 : CSLConstList papszSiblingFiles,
4517 : char **ppszTabFileNameOut);
4518 :
4519 : void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg *psDestArg,
4520 : GDALRasterIOExtraArg *psSrcArg);
4521 :
4522 : void CPL_DLL GDALExpandPackedBitsToByteAt0Or1(
4523 : const GByte *CPL_RESTRICT pabyInput, GByte *CPL_RESTRICT pabyOutput,
4524 : size_t nInputBits);
4525 :
4526 : void CPL_DLL GDALExpandPackedBitsToByteAt0Or255(
4527 : const GByte *CPL_RESTRICT pabyInput, GByte *CPL_RESTRICT pabyOutput,
4528 : size_t nInputBits);
4529 :
4530 : CPL_C_END
4531 :
4532 : std::unique_ptr<GDALDataset> CPL_DLL
4533 : GDALGetThreadSafeDataset(std::unique_ptr<GDALDataset> poDS, int nScopeFlags);
4534 :
4535 : GDALDataset CPL_DLL *GDALGetThreadSafeDataset(GDALDataset *poDS,
4536 : int nScopeFlags);
4537 :
4538 : void GDALNullifyOpenDatasetsList();
4539 : CPLMutex **GDALGetphDMMutex();
4540 : CPLMutex **GDALGetphDLMutex();
4541 : void GDALNullifyProxyPoolSingleton();
4542 : void GDALSetResponsiblePIDForCurrentThread(GIntBig responsiblePID);
4543 : GIntBig GDALGetResponsiblePIDForCurrentThread();
4544 :
4545 : CPLString GDALFindAssociatedFile(const char *pszBasename, const char *pszExt,
4546 : CSLConstList papszSiblingFiles, int nFlags);
4547 :
4548 : CPLErr CPL_DLL EXIFExtractMetadata(char **&papszMetadata, void *fpL,
4549 : int nOffset, int bSwabflag, int nTIFFHEADER,
4550 : int &nExifOffset, int &nInterOffset,
4551 : int &nGPSOffset);
4552 :
4553 : int GDALValidateOpenOptions(GDALDriverH hDriver,
4554 : const char *const *papszOptionOptions);
4555 : int GDALValidateOptions(const char *pszOptionList,
4556 : const char *const *papszOptionsToValidate,
4557 : const char *pszErrorMessageOptionType,
4558 : const char *pszErrorMessageContainerName);
4559 :
4560 : GDALRIOResampleAlg CPL_DLL
4561 : GDALRasterIOGetResampleAlg(const char *pszResampling);
4562 : const char *GDALRasterIOGetResampleAlg(GDALRIOResampleAlg eResampleAlg);
4563 :
4564 : void GDALRasterIOExtraArgSetResampleAlg(GDALRasterIOExtraArg *psExtraArg,
4565 : int nXSize, int nYSize, int nBufXSize,
4566 : int nBufYSize);
4567 :
4568 : GDALDataset *GDALCreateOverviewDataset(GDALDataset *poDS, int nOvrLevel,
4569 : bool bThisLevelOnly);
4570 :
4571 : // Should cover particular cases of #3573, #4183, #4506, #6578
4572 : // Behavior is undefined if fVal1 or fVal2 are NaN (should be tested before
4573 : // calling this function)
4574 :
4575 : // TODO: The expression `abs(fVal1 + fVal2)` looks strange; is this a bug?
4576 : // Should this be `abs(fVal1) + abs(fVal2)` instead?
4577 :
4578 0 : inline bool ARE_REAL_EQUAL(GFloat16 dfVal1, GFloat16 dfVal2, int ulp = 2)
4579 : {
4580 : using std::abs;
4581 0 : return dfVal1 == dfVal2 || /* Should cover infinity */
4582 0 : abs(dfVal1 - dfVal2) < cpl::NumericLimits<GFloat16>::epsilon() *
4583 0 : abs(dfVal1 + dfVal2) * ulp;
4584 : }
4585 :
4586 15643113 : inline bool ARE_REAL_EQUAL(float fVal1, float fVal2, int ulp = 2)
4587 : {
4588 : using std::abs;
4589 30279718 : return fVal1 == fVal2 || /* Should cover infinity */
4590 14636605 : abs(fVal1 - fVal2) <
4591 30279718 : cpl::NumericLimits<float>::epsilon() * abs(fVal1 + fVal2) * ulp;
4592 : }
4593 :
4594 : // We are using `cpl::NumericLimits<float>::epsilon()` for backward
4595 : // compatibility
4596 3953634 : inline bool ARE_REAL_EQUAL(double dfVal1, double dfVal2, int ulp = 2)
4597 : {
4598 : using std::abs;
4599 4559699 : return dfVal1 == dfVal2 || /* Should cover infinity */
4600 606066 : abs(dfVal1 - dfVal2) < cpl::NumericLimits<float>::epsilon() *
4601 4559699 : abs(dfVal1 + dfVal2) * ulp;
4602 : }
4603 :
4604 : double GDALAdjustNoDataCloseToFloatMax(double dfVal);
4605 :
4606 : #define DIV_ROUND_UP(a, b) (((a) % (b)) == 0 ? ((a) / (b)) : (((a) / (b)) + 1))
4607 :
4608 : // Number of data samples that will be used to compute approximate statistics
4609 : // (minimum value, maximum value, etc.)
4610 : #define GDALSTAT_APPROX_NUMSAMPLES 2500
4611 :
4612 : void GDALSerializeGCPListToXML(CPLXMLNode *psParentNode,
4613 : const std::vector<gdal::GCP> &asGCPs,
4614 : const OGRSpatialReference *poGCP_SRS);
4615 : void GDALDeserializeGCPListFromXML(const CPLXMLNode *psGCPList,
4616 : std::vector<gdal::GCP> &asGCPs,
4617 : OGRSpatialReference **ppoGCP_SRS);
4618 :
4619 : void GDALSerializeOpenOptionsToXML(CPLXMLNode *psParentNode,
4620 : CSLConstList papszOpenOptions);
4621 : char CPL_DLL **
4622 : GDALDeserializeOpenOptionsFromXML(const CPLXMLNode *psParentNode);
4623 :
4624 : int GDALCanFileAcceptSidecarFile(const char *pszFilename);
4625 :
4626 : bool GDALCanReliablyUseSiblingFileList(const char *pszFilename);
4627 :
4628 : typedef enum
4629 : {
4630 : GSF_UNSIGNED_INT,
4631 : GSF_SIGNED_INT,
4632 : GSF_FLOATING_POINT,
4633 : } GDALBufferSampleFormat;
4634 :
4635 : bool CPL_DLL GDALBufferHasOnlyNoData(const void *pBuffer, double dfNoDataValue,
4636 : size_t nWidth, size_t nHeight,
4637 : size_t nLineStride, size_t nComponents,
4638 : int nBitsPerSample,
4639 : GDALBufferSampleFormat nSampleFormat);
4640 :
4641 : void CPL_DLL GDALCopyNoDataValue(GDALRasterBand *poDstBand,
4642 : GDALRasterBand *poSrcBand);
4643 :
4644 : double CPL_DLL GDALGetNoDataValueCastToDouble(int64_t nVal);
4645 : double CPL_DLL GDALGetNoDataValueCastToDouble(uint64_t nVal);
4646 :
4647 : // Remove me in GDAL 4.0. See GetMetadataItem() implementation
4648 : // Internal use in GDAL only !
4649 : // Declaration copied in swig/include/gdal.i
4650 : void CPL_DLL GDALEnablePixelTypeSignedByteWarning(GDALRasterBandH hBand,
4651 : bool b);
4652 :
4653 : std::string CPL_DLL GDALGetCompressionFormatForJPEG(VSILFILE *fp);
4654 : std::string CPL_DLL GDALGetCompressionFormatForJPEG(const void *pBuffer,
4655 : size_t nBufferSize);
4656 :
4657 : GDALRasterAttributeTable CPL_DLL *GDALCreateRasterAttributeTableFromMDArrays(
4658 : GDALRATTableType eTableType,
4659 : const std::vector<std::shared_ptr<GDALMDArray>> &apoArrays,
4660 : const std::vector<GDALRATFieldUsage> &aeUsages);
4661 :
4662 : GDALColorInterp CPL_DLL
4663 : GDALGetColorInterpFromSTACCommonName(const char *pszName);
4664 : const char CPL_DLL *
4665 : GDALGetSTACCommonNameFromColorInterp(GDALColorInterp eInterp);
4666 :
4667 : // Macro used so that Identify and driver metadata methods in drivers built
4668 : // as plugin can be duplicated in libgdal core and in the driver under different
4669 : // names
4670 : #ifdef PLUGIN_FILENAME
4671 : #define PLUGIN_SYMBOL_NAME(x) GDAL_core_##x
4672 : #else
4673 : #define PLUGIN_SYMBOL_NAME(x) GDAL_driver_##x
4674 : #endif
4675 :
4676 : //! @endcond
4677 :
4678 : #endif /* ndef GDAL_PRIV_H_INCLUDED */
|