GDAL
gdal_priv.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: gdal_priv.h 4aba1e09e5ccedeb26e5c625c38c0a18b7b3575f 2022-01-28 22:25:42 +0100 Even Rouault $
3  *
4  * Name: gdal_priv.h
5  * Project: GDAL Core
6  * Purpose: GDAL Core C++/Private declarations.
7  * Author: Frank Warmerdam, warmerdam@pobox.com
8  *
9  ******************************************************************************
10  * Copyright (c) 1998, Frank Warmerdam
11  * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef GDAL_PRIV_H_INCLUDED
33 #define GDAL_PRIV_H_INCLUDED
34 
41 /* -------------------------------------------------------------------- */
42 /* Predeclare various classes before pulling in gdal.h, the */
43 /* public declarations. */
44 /* -------------------------------------------------------------------- */
45 class GDALMajorObject;
46 class GDALDataset;
47 class GDALRasterBand;
48 class GDALDriver;
50 class GDALProxyDataset;
51 class GDALProxyRasterBand;
52 class GDALAsyncReader;
53 
54 /* -------------------------------------------------------------------- */
55 /* Pull in the public declarations. This gets the C apis, and */
56 /* also various constants. However, we will still get to */
57 /* provide the real class definitions for the GDAL classes. */
58 /* -------------------------------------------------------------------- */
59 
60 #include "gdal.h"
61 #include "gdal_frmts.h"
62 #include "cpl_vsi.h"
63 #include "cpl_conv.h"
64 #include "cpl_string.h"
65 #include "cpl_minixml.h"
66 #include "cpl_multiproc.h"
67 #include "cpl_atomic_ops.h"
68 
69 #include <stdarg.h>
70 
71 #include <cmath>
72 #include <cstdint>
73 #include <iterator>
74 #include <limits>
75 #include <map>
76 #include <memory>
77 #include <vector>
78 
79 #include "ogr_core.h"
80 #include "ogr_feature.h"
81 
83 #define GMO_VALID 0x0001
84 #define GMO_IGNORE_UNIMPLEMENTED 0x0002
85 #define GMO_SUPPORT_MD 0x0004
86 #define GMO_SUPPORT_MDMD 0x0008
87 #define GMO_MD_DIRTY 0x0010
88 #define GMO_PAM_CLASS 0x0020
90 
91 /************************************************************************/
92 /* GDALMultiDomainMetadata */
93 /************************************************************************/
94 
96 class CPL_DLL GDALMultiDomainMetadata
97 {
98 private:
99  char **papszDomainList;
100  CPLStringList **papoMetadataLists;
101 
102 public:
103  GDALMultiDomainMetadata();
104  ~GDALMultiDomainMetadata();
105 
106  int XMLInit( CPLXMLNode *psMetadata, int bMerge );
107  CPLXMLNode *Serialize();
108 
109  char **GetDomainList() { return papszDomainList; }
110 
111  char **GetMetadata( const char * pszDomain = "" );
112  CPLErr SetMetadata( char ** papszMetadata,
113  const char * pszDomain = "" );
114  const char *GetMetadataItem( const char * pszName,
115  const char * pszDomain = "" );
116  CPLErr SetMetadataItem( const char * pszName,
117  const char * pszValue,
118  const char * pszDomain = "" );
119 
120  void Clear();
121 
122  private:
123  CPL_DISALLOW_COPY_ASSIGN(GDALMultiDomainMetadata)
124 };
126 
127 /* ******************************************************************** */
128 /* GDALMajorObject */
129 /* */
130 /* Base class providing metadata, description and other */
131 /* services shared by major objects. */
132 /* ******************************************************************** */
133 
135 class CPL_DLL GDALMajorObject
136 {
137  protected:
139  int nFlags; // GMO_* flags.
140  CPLString sDescription{};
141  GDALMultiDomainMetadata oMDMD{};
142 
144 
145  char **BuildMetadataDomainList( char** papszList,
146  int bCheckNonEmpty, ... ) CPL_NULL_TERMINATED;
147  public:
148  GDALMajorObject();
149  virtual ~GDALMajorObject();
150 
151  int GetMOFlags() const;
152  void SetMOFlags( int nFlagsIn );
153 
154  virtual const char *GetDescription() const;
155  virtual void SetDescription( const char * );
156 
157  virtual char **GetMetadataDomainList();
158 
159  virtual char **GetMetadata( const char * pszDomain = "" );
160  virtual CPLErr SetMetadata( char ** papszMetadata,
161  const char * pszDomain = "" );
162  virtual const char *GetMetadataItem( const char * pszName,
163  const char * pszDomain = "" );
164  virtual CPLErr SetMetadataItem( const char * pszName,
165  const char * pszValue,
166  const char * pszDomain = "" );
167 
171  static inline GDALMajorObjectH ToHandle(GDALMajorObject* poMajorObject)
172  { return static_cast<GDALMajorObjectH>(poMajorObject); }
173 
177  static inline GDALMajorObject* FromHandle(GDALMajorObjectH hMajorObject)
178  { return static_cast<GDALMajorObject*>(hMajorObject); }
179 };
180 
181 /* ******************************************************************** */
182 /* GDALDefaultOverviews */
183 /* ******************************************************************** */
184 
186 class CPL_DLL GDALDefaultOverviews
187 {
188  friend class GDALDataset;
189 
190  GDALDataset *poDS;
191  GDALDataset *poODS;
192 
193  CPLString osOvrFilename{};
194 
195  bool bOvrIsAux;
196 
197  bool bCheckedForMask;
198  bool bOwnMaskDS;
199  GDALDataset *poMaskDS;
200 
201  // For "overview datasets" we record base level info so we can
202  // find our way back to get overview masks.
203  GDALDataset *poBaseDS;
204 
205  // Stuff for deferred initialize/overviewscans.
206  bool bCheckedForOverviews;
207  void OverviewScan();
208  char *pszInitName;
209  bool bInitNameIsOVR;
210  char **papszInitSiblingFiles;
211 
212  public:
213  GDALDefaultOverviews();
214  ~GDALDefaultOverviews();
215 
216  void Initialize( GDALDataset *poDSIn, const char *pszName = nullptr,
217  char **papszSiblingFiles = nullptr,
218  int bNameIsOVR = FALSE );
219 
220  void TransferSiblingFiles( char** papszSiblingFiles );
221 
222  int IsInitialized();
223 
225 
226  // Overview Related
227 
228  int GetOverviewCount( int nBand );
229  GDALRasterBand *GetOverview( int nBand, int iOverview );
230 
231  CPLErr BuildOverviews( const char * pszBasename,
232  const char * pszResampling,
233  int nOverviews, int * panOverviewList,
234  int nBands, int * panBandList,
235  GDALProgressFunc pfnProgress,
236  void *pProgressData );
237 
238  CPLErr BuildOverviewsSubDataset( const char * pszPhysicalFile,
239  const char * pszResampling,
240  int nOverviews, int * panOverviewList,
241  int nBands, int * panBandList,
242  GDALProgressFunc pfnProgress,
243  void *pProgressData );
244 
245  CPLErr CleanOverviews();
246 
247  // Mask Related
248 
249  CPLErr CreateMaskBand( int nFlags, int nBand = -1 );
250  GDALRasterBand *GetMaskBand( int nBand );
251  int GetMaskFlags( int nBand );
252 
253  int HaveMaskFile( char **papszSiblings = nullptr,
254  const char *pszBasename = nullptr );
255 
256  char** GetSiblingFiles() { return papszInitSiblingFiles; }
257 
258  private:
259  CPL_DISALLOW_COPY_ASSIGN(GDALDefaultOverviews)
260 };
262 
263 /* ******************************************************************** */
264 /* GDALOpenInfo */
265 /* ******************************************************************** */
266 
268 class CPL_DLL GDALOpenInfo
269 {
270  bool bHasGotSiblingFiles;
271  char **papszSiblingFiles;
272  int nHeaderBytesTried;
273 
274  public:
275  GDALOpenInfo( const char * pszFile, int nOpenFlagsIn,
276  const char * const * papszSiblingFiles = nullptr );
277  ~GDALOpenInfo( void );
278 
280  char *pszFilename;
283 
288 
290  int bStatOK;
293 
296 
301 
303  const char* const* papszAllowedDrivers;
304 
305  int TryToIngest(int nBytes);
306  char **GetSiblingFiles();
307  char **StealSiblingFiles();
308  bool AreSiblingFilesLoaded() const;
309 
310  private:
312 };
313 
314 /* ******************************************************************** */
315 /* GDALDataset */
316 /* ******************************************************************** */
317 
318 class OGRLayer;
319 class OGRGeometry;
320 class OGRSpatialReference;
321 class OGRStyleTable;
322 class swq_select;
323 class swq_select_parse_options;
324 class GDALGroup;
325 
327 typedef struct GDALSQLParseInfo GDALSQLParseInfo;
329 
331 #ifdef GDAL_COMPILATION
332 #define OPTIONAL_OUTSIDE_GDAL(val)
333 #else
334 #define OPTIONAL_OUTSIDE_GDAL(val) = val
335 #endif
337 
339 class CPL_DLL GDALDataset : public GDALMajorObject
340 {
341  friend GDALDatasetH CPL_STDCALL GDALOpenEx( const char* pszFilename,
342  unsigned int nOpenFlags,
343  const char* const* papszAllowedDrivers,
344  const char* const* papszOpenOptions,
345  const char* const* papszSiblingFiles );
346  friend void CPL_STDCALL GDALClose( GDALDatasetH hDS );
347 
348  friend class GDALDriver;
349  friend class GDALDefaultOverviews;
350  friend class GDALProxyDataset;
351  friend class GDALDriverManager;
352 
353  CPL_INTERNAL void AddToDatasetOpenList();
354 
355  CPL_INTERNAL static void ReportErrorV(
356  const char* pszDSName,
357  CPLErr eErrClass, CPLErrorNum err_no,
358  const char *fmt, va_list args);
359  protected:
361  GDALDriver *poDriver = nullptr;
362  GDALAccess eAccess = GA_ReadOnly;
363 
364  // Stored raster information.
365  int nRasterXSize = 512;
366  int nRasterYSize = 512;
367  int nBands = 0;
368  GDALRasterBand **papoBands = nullptr;
369 
370  int nOpenFlags = 0;
371 
372  int nRefCount = 1;
373  bool bForceCachedIO = false;
374  bool bShared = false;
375  bool bIsInternal = true;
376  bool bSuppressOnClose = false;
377 
378  mutable std::map<std::string, std::unique_ptr<OGRFieldDomain>> m_oMapFieldDomains{};
379 
380  GDALDataset(void);
381  explicit GDALDataset(int bForceCachedIO);
382 
383  void RasterInitialize( int, int );
384  void SetBand( int, GDALRasterBand * );
385 
386  GDALDefaultOverviews oOvManager{};
387 
388  virtual CPLErr IBuildOverviews( const char *, int, int *,
389  int, int *, GDALProgressFunc, void * );
390 
391  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
392  void *, int, int, GDALDataType,
393  int, int *, GSpacing, GSpacing, GSpacing,
395 
396  CPLErr BlockBasedRasterIO( GDALRWFlag, int, int, int, int,
397  void *, int, int, GDALDataType,
398  int, int *, GSpacing, GSpacing, GSpacing,
400  void BlockBasedFlushCache(bool bAtClosing);
401 
402  CPLErr BandBasedRasterIO( GDALRWFlag eRWFlag,
403  int nXOff, int nYOff, int nXSize, int nYSize,
404  void * pData, int nBufXSize, int nBufYSize,
405  GDALDataType eBufType,
406  int nBandCount, int *panBandMap,
407  GSpacing nPixelSpace, GSpacing nLineSpace,
408  GSpacing nBandSpace,
410 
411  CPLErr RasterIOResampled( GDALRWFlag eRWFlag,
412  int nXOff, int nYOff, int nXSize, int nYSize,
413  void * pData, int nBufXSize, int nBufYSize,
414  GDALDataType eBufType,
415  int nBandCount, int *panBandMap,
416  GSpacing nPixelSpace, GSpacing nLineSpace,
417  GSpacing nBandSpace,
419 
420  CPLErr ValidateRasterIOOrAdviseReadParameters(
421  const char* pszCallingFunc,
422  int* pbStopProcessingOnCENone,
423  int nXOff, int nYOff, int nXSize, int nYSize,
424  int nBufXSize, int nBufYSize,
425  int nBandCount, int *panBandMap);
426 
427  CPLErr TryOverviewRasterIO( GDALRWFlag eRWFlag,
428  int nXOff, int nYOff, int nXSize, int nYSize,
429  void * pData, int nBufXSize, int nBufYSize,
430  GDALDataType eBufType,
431  int nBandCount, int *panBandMap,
432  GSpacing nPixelSpace, GSpacing nLineSpace,
433  GSpacing nBandSpace,
434  GDALRasterIOExtraArg* psExtraArg,
435  int* pbTried);
436 
437  void ShareLockWithParentDataset(GDALDataset* poParentDataset);
438 
440 
441  void CleanupPostFileClosing();
442 
443  virtual int CloseDependentDatasets();
445  int ValidateLayerCreationOptions( const char* const* papszLCO );
446 
447  char **papszOpenOptions = nullptr;
448 
449  friend class GDALRasterBand;
450 
451  // The below methods related to read write mutex are fragile logic, and
452  // should not be used by out-of-tree code if possible.
453  int EnterReadWrite(GDALRWFlag eRWFlag);
454  void LeaveReadWrite();
455  void InitRWLock();
456 
457  void TemporarilyDropReadWriteLock();
458  void ReacquireReadWriteLock();
459 
460  void DisableReadWriteMutex();
461 
462  int AcquireMutex();
463  void ReleaseMutex();
465 
466  public:
467  ~GDALDataset() override;
468 
469  int GetRasterXSize();
470  int GetRasterYSize();
471  int GetRasterCount();
472  GDALRasterBand *GetRasterBand( int );
473 
475  class CPL_DLL Bands
476  {
477  private:
478 
479  friend class GDALDataset;
480  GDALDataset* m_poSelf;
481  CPL_INTERNAL explicit Bands(GDALDataset* poSelf): m_poSelf(poSelf) {}
482 
483  class CPL_DLL Iterator
484  {
485  struct Private;
486  std::unique_ptr<Private> m_poPrivate;
487  public:
488  Iterator(GDALDataset* poDS, bool bStart);
489  Iterator(const Iterator& oOther); // declared but not defined. Needed for gcc 5.4 at least
490  Iterator(Iterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
491  ~Iterator();
492  GDALRasterBand* operator*();
493  Iterator& operator++();
494  bool operator!=(const Iterator& it) const;
495  };
496 
497  public:
498 
499  const Iterator begin() const;
500 
501  const Iterator end() const;
502 
503  size_t size() const;
504 
505  GDALRasterBand* operator[](int iBand);
506  GDALRasterBand* operator[](size_t iBand);
507  };
508 
509  Bands GetBands();
510 
511  virtual void FlushCache(bool bAtClosing = false);
512 
513  virtual const OGRSpatialReference* GetSpatialRef() const;
514  virtual CPLErr SetSpatialRef(const OGRSpatialReference* poSRS);
515 
516  // Compatibility layer
517  const char *GetProjectionRef(void) const;
518  CPLErr SetProjection( const char * pszProjection );
519 
520  virtual CPLErr GetGeoTransform( double * padfTransform );
521  virtual CPLErr SetGeoTransform( double * padfTransform );
522 
523  virtual CPLErr AddBand( GDALDataType eType,
524  char **papszOptions=nullptr );
525 
526  virtual void *GetInternalHandle( const char * pszHandleName );
527  virtual GDALDriver *GetDriver(void);
528  virtual char **GetFileList(void);
529 
530  virtual const char* GetDriverName();
531 
532  virtual const OGRSpatialReference* GetGCPSpatialRef() const;
533  virtual int GetGCPCount();
534  virtual const GDAL_GCP *GetGCPs();
535  virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
536  const OGRSpatialReference * poGCP_SRS );
537 
538  // Compatibility layer
539  const char *GetGCPProjection();
540  CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
541  const char *pszGCPProjection );
542 
543  virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
544  int nBufXSize, int nBufYSize,
545  GDALDataType eDT,
546  int nBandCount, int *panBandList,
547  char **papszOptions );
548 
549  virtual CPLErr CreateMaskBand( int nFlagsIn );
550 
551  virtual GDALAsyncReader*
552  BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize,
553  void *pBuf, int nBufXSize, int nBufYSize,
554  GDALDataType eBufType,
555  int nBandCount, int* panBandMap,
556  int nPixelSpace, int nLineSpace, int nBandSpace,
557  char **papszOptions);
558  virtual void EndAsyncReader(GDALAsyncReader *);
559 
561  struct RawBinaryLayout
562  {
563  enum class Interleaving
564  {
565  UNKNOWN,
566  BIP,
567  BIL,
568  BSQ
569  };
570  std::string osRawFilename{};
571  Interleaving eInterleaving = Interleaving::UNKNOWN;
572  GDALDataType eDataType = GDT_Unknown;
573  bool bLittleEndianOrder = false;
574 
575  vsi_l_offset nImageOffset = 0;
576  GIntBig nPixelOffset = 0;
577  GIntBig nLineOffset = 0;
578  GIntBig nBandOffset = 0;
579  };
580 
581  virtual bool GetRawBinaryLayout(RawBinaryLayout&);
583 
584  CPLErr RasterIO( GDALRWFlag, int, int, int, int,
585  void *, int, int, GDALDataType,
586  int, int *, GSpacing, GSpacing, GSpacing,
587  GDALRasterIOExtraArg* psExtraArg
588 #ifndef DOXYGEN_SKIP
589  OPTIONAL_OUTSIDE_GDAL(nullptr)
590 #endif
592 
593  int Reference();
594  int Dereference();
595  int ReleaseRef();
596 
600  GDALAccess GetAccess() const { return eAccess; }
601 
602  int GetShared() const;
603  void MarkAsShared();
604 
605  void MarkSuppressOnClose();
606 
610  char **GetOpenOptions() { return papszOpenOptions; }
611 
612  static GDALDataset **GetOpenDatasets( int *pnDatasetCount );
613 
614  CPLErr BuildOverviews( const char *, int, int *,
615  int, int *, GDALProgressFunc, void * );
616 
617 #ifndef DOXYGEN_XML
618  void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (4, 5);
619 
620  static void ReportError(const char* pszDSName,
621  CPLErr eErrClass, CPLErrorNum err_no,
622  const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (4, 5);
623 #endif
624 
625  char ** GetMetadata(const char * pszDomain = "") override;
626 
627 // Only defined when Doxygen enabled
628 #ifdef DOXYGEN_SKIP
629  CPLErr SetMetadata( char ** papszMetadata,
630  const char * pszDomain ) override;
631  CPLErr SetMetadataItem( const char * pszName,
632  const char * pszValue,
633  const char * pszDomain ) override;
634 #endif
635 
636  char **GetMetadataDomainList() override;
637 
638  virtual void ClearStatistics();
639 
643  static inline GDALDatasetH ToHandle(GDALDataset* poDS)
644  { return static_cast<GDALDatasetH>(poDS); }
645 
649  static inline GDALDataset* FromHandle(GDALDatasetH hDS)
650  { return static_cast<GDALDataset*>(hDS); }
651 
655  static GDALDataset* Open( const char* pszFilename,
656  unsigned int nOpenFlags = 0,
657  const char* const* papszAllowedDrivers = nullptr,
658  const char* const* papszOpenOptions = nullptr,
659  const char* const* papszSiblingFiles = nullptr )
660  {
661  return FromHandle(GDALOpenEx(pszFilename, nOpenFlags,
662  papszAllowedDrivers,
663  papszOpenOptions,
664  papszSiblingFiles));
665  }
666 
669  {
672 
674  OGRLayer* layer = nullptr;
675  };
676 
678  // SetEnableOverviews() only to be used by GDALOverviewDataset
679  void SetEnableOverviews(bool bEnable);
680 
681  // Only to be used by driver's GetOverviewCount() method.
682  bool AreOverviewsEnabled() const;
684 
685 private:
686  class Private;
687  Private *m_poPrivate;
688 
689  CPL_INTERNAL OGRLayer* BuildLayerFromSelectInfo(swq_select* psSelectInfo,
690  OGRGeometry *poSpatialFilter,
691  const char *pszDialect,
692  swq_select_parse_options* poSelectParseOptions);
693  CPLStringList oDerivedMetadataList{};
694 
695  public:
696 
697  virtual int GetLayerCount();
698  virtual OGRLayer *GetLayer(int iLayer);
699 
700  virtual bool IsLayerPrivate(int iLayer) const;
701 
705  class CPL_DLL Layers
706  {
707  private:
708 
709  friend class GDALDataset;
710  GDALDataset* m_poSelf;
711  CPL_INTERNAL explicit Layers(GDALDataset* poSelf): m_poSelf(poSelf) {}
712 
713  public:
714 
718  class CPL_DLL Iterator
719  {
720  struct Private;
721  std::unique_ptr<Private> m_poPrivate;
722  public:
723 
724  using value_type = OGRLayer*;
725  using reference = OGRLayer*;
726  using difference_type = void;
727  using pointer = void;
728  using iterator_category = std::input_iterator_tag;
730  Iterator();
731  Iterator(GDALDataset* poDS, bool bStart);
732  Iterator(const Iterator& oOther);
733  Iterator(Iterator&& oOther) noexcept;
736  Iterator& operator=(const Iterator& oOther);
737  Iterator& operator=(Iterator&& oOther) noexcept;
739  OGRLayer* operator*() const;
740  Iterator& operator++();
741  Iterator operator++(int);
742  bool operator!=(const Iterator& it) const;
743  };
744 
745  Iterator begin() const;
746  Iterator end() const;
747 
748  size_t size() const;
749 
750  OGRLayer* operator[](int iLayer);
751  OGRLayer* operator[](size_t iLayer);
752  OGRLayer* operator[](const char* pszLayername);
753  };
754 
755  Layers GetLayers();
756 
757  virtual OGRLayer *GetLayerByName(const char *);
758  virtual OGRErr DeleteLayer(int iLayer);
759 
760  virtual void ResetReading();
761  virtual OGRFeature* GetNextFeature( OGRLayer** ppoBelongingLayer,
762  double* pdfProgressPct,
763  GDALProgressFunc pfnProgress,
764  void* pProgressData );
765 
766 
768  class CPL_DLL Features
769  {
770  private:
771 
772  friend class GDALDataset;
773  GDALDataset* m_poSelf;
774  CPL_INTERNAL explicit Features(GDALDataset* poSelf): m_poSelf(poSelf) {}
775 
776  class CPL_DLL Iterator
777  {
778  struct Private;
779  std::unique_ptr<Private> m_poPrivate;
780  public:
781  Iterator(GDALDataset* poDS, bool bStart);
782  Iterator(const Iterator& oOther); // declared but not defined. Needed for gcc 5.4 at least
783  Iterator(Iterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
784  ~Iterator();
785  const FeatureLayerPair& operator*() const;
786  Iterator& operator++();
787  bool operator!=(const Iterator& it) const;
788  };
789 
790  public:
791 
792  const Iterator begin() const;
793 
794  const Iterator end() const;
795  };
796 
797  Features GetFeatures();
798 
799  virtual int TestCapability( const char * );
800 
801  virtual const OGRFieldDomain* GetFieldDomain(const std::string& name) const;
802 
803  virtual bool AddFieldDomain(std::unique_ptr<OGRFieldDomain>&& domain,
804  std::string& failureReason);
805 
806  virtual OGRLayer *CreateLayer( const char *pszName,
807  OGRSpatialReference *poSpatialRef = nullptr,
809  char ** papszOptions = nullptr );
810  virtual OGRLayer *CopyLayer( OGRLayer *poSrcLayer,
811  const char *pszNewName,
812  char **papszOptions = nullptr );
813 
814  virtual OGRStyleTable *GetStyleTable();
815  virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable );
816 
817  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
818 
819  virtual OGRLayer * ExecuteSQL( const char *pszStatement,
820  OGRGeometry *poSpatialFilter,
821  const char *pszDialect );
822  virtual void ReleaseResultSet( OGRLayer * poResultsSet );
823  virtual OGRErr AbortSQL( );
824 
825  int GetRefCount() const;
826  int GetSummaryRefCount() const;
827  OGRErr Release();
828 
829  virtual OGRErr StartTransaction(int bForce=FALSE);
830  virtual OGRErr CommitTransaction();
831  virtual OGRErr RollbackTransaction();
832 
833  virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
834 
836  static int IsGenericSQLDialect(const char* pszDialect);
837 
838  // Semi-public methods. Only to be used by in-tree drivers.
839  GDALSQLParseInfo* BuildParseInfo(swq_select* psSelectInfo,
840  swq_select_parse_options* poSelectParseOptions);
841  static void DestroyParseInfo(GDALSQLParseInfo* psParseInfo );
842  OGRLayer * ExecuteSQL( const char *pszStatement,
843  OGRGeometry *poSpatialFilter,
844  const char *pszDialect,
845  swq_select_parse_options* poSelectParseOptions);
847 
848  protected:
849  virtual OGRLayer *ICreateLayer( const char *pszName,
850  OGRSpatialReference *poSpatialRef = nullptr,
852  char ** papszOptions = nullptr );
853 
855  OGRErr ProcessSQLCreateIndex( const char * );
856  OGRErr ProcessSQLDropIndex( const char * );
857  OGRErr ProcessSQLDropTable( const char * );
858  OGRErr ProcessSQLAlterTableAddColumn( const char * );
859  OGRErr ProcessSQLAlterTableDropColumn( const char * );
860  OGRErr ProcessSQLAlterTableAlterColumn( const char * );
861  OGRErr ProcessSQLAlterTableRenameColumn( const char * );
862 
863  OGRStyleTable *m_poStyleTable = nullptr;
864 
865  // Compatibility layers
866  const OGRSpatialReference* GetSpatialRefFromOldGetProjectionRef() const;
867  CPLErr OldSetProjectionFromSetSpatialRef(const OGRSpatialReference* poSRS);
868  const OGRSpatialReference* GetGCPSpatialRefFromOldGetGCPProjection() const;
869  CPLErr OldSetGCPsFromNew( int nGCPCount, const GDAL_GCP *pasGCPList,
870  const OGRSpatialReference * poGCP_SRS );
871 
872  friend class GDALProxyPoolDataset;
873  virtual const char *_GetProjectionRef();
874  const char *GetProjectionRefFromSpatialRef(const OGRSpatialReference*) const;
875  virtual const char *_GetGCPProjection();
876  const char *GetGCPProjectionFromSpatialRef(const OGRSpatialReference* poSRS) const;
877  virtual CPLErr _SetProjection( const char * pszProjection );
878  virtual CPLErr _SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
879  const char *pszGCPProjection );
881 
882  private:
884 };
885 
887 struct CPL_DLL GDALDatasetUniquePtrDeleter
888 {
889  void operator()(GDALDataset* poDataset) const
890  { GDALClose(poDataset); }
891 };
893 
899 using GDALDatasetUniquePtr = std::unique_ptr<GDALDataset, GDALDatasetUniquePtrDeleter>;
900 
901 /* ******************************************************************** */
902 /* GDALRasterBlock */
903 /* ******************************************************************** */
904 
909 class CPL_DLL GDALRasterBlock
910 {
911  friend class GDALAbstractBandBlockCache;
912 
913  GDALDataType eType;
914 
915  bool bDirty;
916  volatile int nLockCount;
917 
918  int nXOff;
919  int nYOff;
920 
921  int nXSize;
922  int nYSize;
923 
924  void *pData;
925 
926  GDALRasterBand *poBand;
927 
928  GDALRasterBlock *poNext;
929  GDALRasterBlock *poPrevious;
930 
931  bool bMustDetach;
932 
933  CPL_INTERNAL void Detach_unlocked( void );
934  CPL_INTERNAL void Touch_unlocked( void );
935 
936  CPL_INTERNAL void RecycleFor( int nXOffIn, int nYOffIn );
937 
938  public:
939  GDALRasterBlock( GDALRasterBand *, int, int );
940  GDALRasterBlock( int nXOffIn, int nYOffIn ); /* only for lookup purpose */
941  virtual ~GDALRasterBlock();
942 
943  CPLErr Internalize( void );
944  void Touch( void );
945  void MarkDirty( void );
946  void MarkClean( void );
948  int AddLock( void ) { return CPLAtomicInc(&nLockCount); }
950  int DropLock( void ) { return CPLAtomicDec(&nLockCount); }
951  void Detach();
952 
953  CPLErr Write();
954 
958  GDALDataType GetDataType() const { return eType; }
962  int GetXOff() const { return nXOff; }
966  int GetYOff() const { return nYOff; }
970  int GetXSize() const { return nXSize; }
974  int GetYSize() const { return nYSize; }
978  int GetDirty() const { return bDirty; }
982  void *GetDataRef( void ) { return pData; }
987  return static_cast<GPtrDiff_t>(nXSize) * nYSize * GDALGetDataTypeSizeBytes(eType); }
988 
989  int TakeLock();
990  int DropLockForRemovalFromStorage();
991 
994  GDALRasterBand *GetBand() { return poBand; }
995 
996  static void FlushDirtyBlocks();
997  static int FlushCacheBlock(int bDirtyBlocksOnly = FALSE);
998  static void Verify();
999 
1000  static void EnterDisableDirtyBlockFlush();
1001  static void LeaveDisableDirtyBlockFlush();
1002 
1003 #ifdef notdef
1004  static void CheckNonOrphanedBlocks(GDALRasterBand* poBand);
1005  void DumpBlock();
1006  static void DumpAll();
1007 #endif
1008 
1009  /* Should only be called by GDALDestroyDriverManager() */
1011  CPL_INTERNAL static void DestroyRBMutex();
1013 
1014  private:
1016 };
1017 
1018 /* ******************************************************************** */
1019 /* GDALColorTable */
1020 /* ******************************************************************** */
1021 
1024 class CPL_DLL GDALColorTable
1025 {
1026  GDALPaletteInterp eInterp;
1027 
1028  std::vector<GDALColorEntry> aoEntries{};
1029 
1030 public:
1033 
1034  GDALColorTable *Clone() const;
1035  int IsSame(const GDALColorTable* poOtherCT) const;
1036 
1037  GDALPaletteInterp GetPaletteInterpretation() const;
1038 
1039  int GetColorEntryCount() const;
1040  const GDALColorEntry *GetColorEntry( int ) const;
1041  int GetColorEntryAsRGB( int, GDALColorEntry * ) const;
1042  void SetColorEntry( int, const GDALColorEntry * );
1043  int CreateColorRamp( int, const GDALColorEntry * ,
1044  int, const GDALColorEntry * );
1045  bool IsIdentity() const;
1046 
1051  { return static_cast<GDALColorTableH>(poCT); }
1052 
1057  { return static_cast<GDALColorTable*>(hCT); }
1058 
1059 };
1060 
1061 /* ******************************************************************** */
1062 /* GDALAbstractBandBlockCache */
1063 /* ******************************************************************** */
1064 
1066 
1068 // only used by GDALRasterBand implementation.
1069 
1070 class GDALAbstractBandBlockCache
1071 {
1072  // List of blocks that can be freed or recycled, and its lock
1073  CPLLock *hSpinLock = nullptr;
1074  GDALRasterBlock *psListBlocksToFree = nullptr;
1075 
1076  // Band keep alive counter, and its lock & condition
1077  CPLCond *hCond = nullptr;
1078  CPLMutex *hCondMutex = nullptr;
1079  volatile int nKeepAliveCounter = 0;
1080 
1081  volatile int m_nDirtyBlocks = 0;
1082 
1083  CPL_DISALLOW_COPY_ASSIGN(GDALAbstractBandBlockCache)
1084 
1085  protected:
1086  GDALRasterBand *poBand;
1087 
1088  int m_nInitialDirtyBlocksInFlushCache = 0;
1089  int m_nLastTick = -1;
1090  bool m_bWriteDirtyBlocks = true;
1091 
1092  void FreeDanglingBlocks();
1093  void UnreferenceBlockBase();
1094 
1095  void StartDirtyBlockFlushingLog();
1096  void UpdateDirtyBlockFlushingLog();
1097  void EndDirtyBlockFlushingLog();
1098 
1099  public:
1100  explicit GDALAbstractBandBlockCache(GDALRasterBand* poBand);
1101  virtual ~GDALAbstractBandBlockCache();
1102 
1103  GDALRasterBlock* CreateBlock(int nXBlockOff, int nYBlockOff);
1104  void AddBlockToFreeList( GDALRasterBlock * );
1105  void IncDirtyBlocks(int nInc);
1106  void WaitCompletionPendingTasks();
1107  void DisableDirtyBlockWriting() { m_bWriteDirtyBlocks = false; }
1108 
1109  virtual bool Init() = 0;
1110  virtual bool IsInitOK() = 0;
1111  virtual CPLErr FlushCache() = 0;
1112  virtual CPLErr AdoptBlock( GDALRasterBlock* poBlock ) = 0;
1113  virtual GDALRasterBlock *TryGetLockedBlockRef( int nXBlockOff,
1114  int nYBlockYOff ) = 0;
1115  virtual CPLErr UnreferenceBlock( GDALRasterBlock* poBlock ) = 0;
1116  virtual CPLErr FlushBlock( int nXBlockOff, int nYBlockOff,
1117  int bWriteDirtyBlock ) = 0;
1118 };
1119 
1120 GDALAbstractBandBlockCache* GDALArrayBandBlockCacheCreate(GDALRasterBand* poBand);
1121 GDALAbstractBandBlockCache* GDALHashSetBandBlockCacheCreate(GDALRasterBand* poBand);
1122 
1124 
1125 /* ******************************************************************** */
1126 /* GDALRasterBand */
1127 /* ******************************************************************** */
1128 
1129 class GDALMDArray;
1130 
1133 class CPL_DLL GDALRasterBand : public GDALMajorObject
1134 {
1135  private:
1136  friend class GDALArrayBandBlockCache;
1137  friend class GDALHashSetBandBlockCache;
1138  friend class GDALRasterBlock;
1139  friend class GDALDataset;
1140 
1141  CPLErr eFlushBlockErr = CE_None;
1142  GDALAbstractBandBlockCache* poBandBlockCache = nullptr;
1143 
1144  CPL_INTERNAL void SetFlushBlockErr( CPLErr eErr );
1145  CPL_INTERNAL CPLErr UnreferenceBlock( GDALRasterBlock* poBlock );
1146  CPL_INTERNAL void SetValidPercent( GUIntBig nSampleCount, GUIntBig nValidCount );
1147  CPL_INTERNAL void IncDirtyBlocks(int nInc);
1148 
1149  protected:
1151  GDALDataset *poDS = nullptr;
1152  int nBand = 0; /* 1 based */
1153 
1154  int nRasterXSize = 0;
1155  int nRasterYSize = 0;
1156 
1157  GDALDataType eDataType = GDT_Byte;
1158  GDALAccess eAccess = GA_ReadOnly;
1159 
1160  /* stuff related to blocking, and raster cache */
1161  int nBlockXSize = -1;
1162  int nBlockYSize = -1;
1163  int nBlocksPerRow = 0;
1164  int nBlocksPerColumn = 0;
1165 
1166  int nBlockReads = 0;
1167  int bForceCachedIO = 0;
1168 
1169  GDALRasterBand *poMask = nullptr;
1170  bool bOwnMask = false;
1171  int nMaskFlags = 0;
1172 
1173  void InvalidateMaskBand();
1174 
1175  friend class GDALProxyRasterBand;
1176  friend class GDALDefaultOverviews;
1177 
1178  CPLErr RasterIOResampled( GDALRWFlag, int, int, int, int,
1179  void *, int, int, GDALDataType,
1181 
1182  int EnterReadWrite(GDALRWFlag eRWFlag);
1183  void LeaveReadWrite();
1184  void InitRWLock();
1186 
1187  protected:
1188  virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void * pData ) = 0;
1189  virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void * pData );
1190 
1191  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
1192  void *, int, int, GDALDataType,
1194 
1195  virtual int IGetDataCoverageStatus( int nXOff, int nYOff,
1196  int nXSize, int nYSize,
1197  int nMaskFlagStop,
1198  double* pdfDataPct);
1200  CPLErr OverviewRasterIO( GDALRWFlag, int, int, int, int,
1201  void *, int, int, GDALDataType,
1203 
1204  CPLErr TryOverviewRasterIO( GDALRWFlag eRWFlag,
1205  int nXOff, int nYOff, int nXSize, int nYSize,
1206  void * pData, int nBufXSize, int nBufYSize,
1207  GDALDataType eBufType,
1208  GSpacing nPixelSpace, GSpacing nLineSpace,
1209  GDALRasterIOExtraArg* psExtraArg,
1210  int* pbTried );
1211 
1212  int InitBlockInfo();
1213 
1214  void AddBlockToFreeList( GDALRasterBlock * );
1216 
1217  public:
1218  GDALRasterBand();
1219  explicit GDALRasterBand(int bForceCachedIO);
1220 
1221  ~GDALRasterBand() override;
1222 
1223  int GetXSize();
1224  int GetYSize();
1225  int GetBand();
1226  GDALDataset*GetDataset();
1227 
1228  GDALDataType GetRasterDataType( void );
1229  void GetBlockSize( int *, int * );
1230  CPLErr GetActualBlockSize ( int, int, int *, int * );
1231  GDALAccess GetAccess();
1232 
1233  CPLErr RasterIO( GDALRWFlag, int, int, int, int,
1234  void *, int, int, GDALDataType,
1235  GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg
1236 #ifndef DOXYGEN_SKIP
1237  OPTIONAL_OUTSIDE_GDAL(nullptr)
1238 #endif
1240  CPLErr ReadBlock( int, int, void * ) CPL_WARN_UNUSED_RESULT;
1241 
1242  CPLErr WriteBlock( int, int, void * ) CPL_WARN_UNUSED_RESULT;
1243 
1244  GDALRasterBlock *GetLockedBlockRef( int nXBlockOff, int nYBlockOff,
1245  int bJustInitialize = FALSE ) CPL_WARN_UNUSED_RESULT;
1246  GDALRasterBlock *TryGetLockedBlockRef( int nXBlockOff, int nYBlockYOff ) CPL_WARN_UNUSED_RESULT;
1247  CPLErr FlushBlock( int, int, int bWriteDirtyBlock = TRUE );
1248 
1249  unsigned char* GetIndexColorTranslationTo(/* const */ GDALRasterBand* poReferenceBand,
1250  unsigned char* pTranslationTable = nullptr,
1251  int* pApproximateMatching = nullptr);
1252 
1253  // New OpengIS CV_SampleDimension stuff.
1254 
1255  virtual CPLErr FlushCache(bool bAtClosing = false);
1256  virtual char **GetCategoryNames();
1257  virtual double GetNoDataValue( int *pbSuccess = nullptr );
1258  virtual double GetMinimum( int *pbSuccess = nullptr );
1259  virtual double GetMaximum(int *pbSuccess = nullptr );
1260  virtual double GetOffset( int *pbSuccess = nullptr );
1261  virtual double GetScale( int *pbSuccess = nullptr );
1262  virtual const char *GetUnitType();
1263  virtual GDALColorInterp GetColorInterpretation();
1264  virtual GDALColorTable *GetColorTable();
1265  virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
1266 
1267  virtual CPLErr SetCategoryNames( char ** papszNames );
1268  virtual CPLErr SetNoDataValue( double dfNoData );
1269  virtual CPLErr DeleteNoDataValue();
1270  virtual CPLErr SetColorTable( GDALColorTable * poCT );
1271  virtual CPLErr SetColorInterpretation( GDALColorInterp eColorInterp );
1272  virtual CPLErr SetOffset( double dfNewOffset );
1273  virtual CPLErr SetScale( double dfNewScale );
1274  virtual CPLErr SetUnitType( const char * pszNewValue );
1275 
1276  virtual CPLErr GetStatistics( int bApproxOK, int bForce,
1277  double *pdfMin, double *pdfMax,
1278  double *pdfMean, double *padfStdDev );
1279  virtual CPLErr ComputeStatistics( int bApproxOK,
1280  double *pdfMin, double *pdfMax,
1281  double *pdfMean, double *pdfStdDev,
1282  GDALProgressFunc, void *pProgressData );
1283  virtual CPLErr SetStatistics( double dfMin, double dfMax,
1284  double dfMean, double dfStdDev );
1285  virtual CPLErr ComputeRasterMinMax( int, double* );
1286 
1287 // Only defined when Doxygen enabled
1288 #ifdef DOXYGEN_SKIP
1289  CPLErr SetMetadata( char ** papszMetadata,
1290  const char * pszDomain ) override;
1291  CPLErr SetMetadataItem( const char * pszName,
1292  const char * pszValue,
1293  const char * pszDomain ) override;
1294 #endif
1295 
1296  virtual int HasArbitraryOverviews();
1297  virtual int GetOverviewCount();
1298  virtual GDALRasterBand *GetOverview(int);
1299  virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig );
1300  virtual CPLErr BuildOverviews( const char * pszResampling,
1301  int nOverviews,
1302  int * panOverviewList,
1303  GDALProgressFunc pfnProgress,
1304  void * pProgressData );
1305 
1306  virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
1307  int nBufXSize, int nBufYSize,
1308  GDALDataType eBufType, char **papszOptions );
1309 
1310  virtual CPLErr GetHistogram( double dfMin, double dfMax,
1311  int nBuckets, GUIntBig * panHistogram,
1312  int bIncludeOutOfRange, int bApproxOK,
1313  GDALProgressFunc, void *pProgressData );
1314 
1315  virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
1316  int *pnBuckets, GUIntBig ** ppanHistogram,
1317  int bForce,
1318  GDALProgressFunc, void *pProgressData);
1319  virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
1320  int nBuckets, GUIntBig *panHistogram );
1321 
1322  virtual GDALRasterAttributeTable *GetDefaultRAT();
1323  virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * poRAT );
1324 
1325  virtual GDALRasterBand *GetMaskBand();
1326  virtual int GetMaskFlags();
1327  virtual CPLErr CreateMaskBand( int nFlagsIn );
1328 
1329  virtual CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
1330  int *pnPixelSpace,
1331  GIntBig *pnLineSpace,
1332  char **papszOptions ) CPL_WARN_UNUSED_RESULT;
1333 
1334  int GetDataCoverageStatus( int nXOff, int nYOff,
1335  int nXSize, int nYSize,
1336  int nMaskFlagStop = 0,
1337  double* pdfDataPct = nullptr );
1338 
1339  std::shared_ptr<GDALMDArray> AsMDArray() const;
1340 
1341 #ifndef DOXYGEN_XML
1342  void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (4, 5);
1343 #endif
1344 
1348  static inline GDALRasterBandH ToHandle(GDALRasterBand* poBand)
1349  { return static_cast<GDALRasterBandH>(poBand); }
1350 
1355  { return static_cast<GDALRasterBand*>(hBand); }
1356 
1357 private:
1359 };
1360 
1362 /* ******************************************************************** */
1363 /* GDALAllValidMaskBand */
1364 /* ******************************************************************** */
1365 
1366 class CPL_DLL GDALAllValidMaskBand : public GDALRasterBand
1367 {
1368  protected:
1369  CPLErr IReadBlock( int, int, void * ) override;
1370 
1371  CPL_DISALLOW_COPY_ASSIGN(GDALAllValidMaskBand)
1372 
1373  public:
1374  explicit GDALAllValidMaskBand( GDALRasterBand * );
1375  ~GDALAllValidMaskBand() override;
1376 
1377  GDALRasterBand *GetMaskBand() override;
1378  int GetMaskFlags() override;
1379 
1380  CPLErr ComputeStatistics( int bApproxOK,
1381  double *pdfMin, double *pdfMax,
1382  double *pdfMean, double *pdfStdDev,
1383  GDALProgressFunc, void *pProgressData ) override;
1384 
1385 };
1386 
1387 /* ******************************************************************** */
1388 /* GDALNoDataMaskBand */
1389 /* ******************************************************************** */
1390 
1391 class CPL_DLL GDALNoDataMaskBand : public GDALRasterBand
1392 {
1393  double dfNoDataValue;
1394  GDALRasterBand *poParent;
1395 
1396  CPL_DISALLOW_COPY_ASSIGN(GDALNoDataMaskBand)
1397 
1398  protected:
1399  CPLErr IReadBlock( int, int, void * ) override;
1400  CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
1401  void *, int, int, GDALDataType,
1402  GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg ) override;
1403 
1404  public:
1405  explicit GDALNoDataMaskBand( GDALRasterBand * );
1406  ~GDALNoDataMaskBand() override;
1407 
1408  static bool IsNoDataInRange(double dfNoDataValue,
1409  GDALDataType eDataType);
1410 };
1411 
1412 /* ******************************************************************** */
1413 /* GDALNoDataValuesMaskBand */
1414 /* ******************************************************************** */
1415 
1416 class CPL_DLL GDALNoDataValuesMaskBand : public GDALRasterBand
1417 {
1418  double *padfNodataValues;
1419 
1420  CPL_DISALLOW_COPY_ASSIGN(GDALNoDataValuesMaskBand)
1421 
1422  protected:
1423  CPLErr IReadBlock( int, int, void * ) override;
1424 
1425  public:
1426  explicit GDALNoDataValuesMaskBand( GDALDataset * );
1427  ~GDALNoDataValuesMaskBand() override;
1428 };
1429 
1430 /* ******************************************************************** */
1431 /* GDALRescaledAlphaBand */
1432 /* ******************************************************************** */
1433 
1434 class GDALRescaledAlphaBand : public GDALRasterBand
1435 {
1436  GDALRasterBand *poParent;
1437  void *pTemp;
1438 
1439  CPL_DISALLOW_COPY_ASSIGN(GDALRescaledAlphaBand)
1440 
1441  protected:
1442  CPLErr IReadBlock( int, int, void * ) override;
1443  CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
1444  void *, int, int, GDALDataType,
1445  GSpacing, GSpacing,
1446  GDALRasterIOExtraArg* psExtraArg ) override;
1447 
1448  public:
1449  explicit GDALRescaledAlphaBand( GDALRasterBand * );
1450  ~GDALRescaledAlphaBand() override;
1451 };
1453 
1454 /* ******************************************************************** */
1455 /* GDALIdentifyEnum */
1456 /* ******************************************************************** */
1457 
1463 typedef enum
1464 {
1470  GDAL_IDENTIFY_TRUE = 1
1472 
1473 /* ******************************************************************** */
1474 /* GDALDriver */
1475 /* ******************************************************************** */
1476 
1488 class CPL_DLL GDALDriver : public GDALMajorObject
1489 {
1490  public:
1491  GDALDriver();
1492  ~GDALDriver() override;
1493 
1494  CPLErr SetMetadataItem( const char * pszName,
1495  const char * pszValue,
1496  const char * pszDomain = "" ) override;
1497 
1498 /* -------------------------------------------------------------------- */
1499 /* Public C++ methods. */
1500 /* -------------------------------------------------------------------- */
1501  GDALDataset *Create( const char * pszName,
1502  int nXSize, int nYSize, int nBands,
1503  GDALDataType eType, CSLConstList papszOptions ) CPL_WARN_UNUSED_RESULT;
1504 
1505  GDALDataset *CreateMultiDimensional( const char * pszName,
1506  CSLConstList papszRootGroupOptions,
1507  CSLConstList papszOptions ) CPL_WARN_UNUSED_RESULT;
1508 
1509  CPLErr Delete( const char * pszName );
1510  CPLErr Rename( const char * pszNewName,
1511  const char * pszOldName );
1512  CPLErr CopyFiles( const char * pszNewName,
1513  const char * pszOldName );
1514 
1515  GDALDataset *CreateCopy( const char *, GDALDataset *,
1516  int, CSLConstList papszOptions,
1517  GDALProgressFunc pfnProgress,
1518  void * pProgressData ) CPL_WARN_UNUSED_RESULT;
1519 
1520 /* -------------------------------------------------------------------- */
1521 /* The following are semiprivate, not intended to be accessed */
1522 /* by anyone but the formats instantiating and populating the */
1523 /* drivers. */
1524 /* -------------------------------------------------------------------- */
1526  GDALDataset *(*pfnOpen)( GDALOpenInfo * );
1527 
1528  GDALDataset *(*pfnCreate)( const char * pszName,
1529  int nXSize, int nYSize, int nBands,
1530  GDALDataType eType,
1531  char ** papszOptions );
1532 
1533  GDALDataset *(*pfnCreateEx)( GDALDriver*, const char * pszName,
1534  int nXSize, int nYSize, int nBands,
1535  GDALDataType eType,
1536  char ** papszOptions );
1537 
1538  GDALDataset *(*pfnCreateMultiDimensional)( const char * pszName,
1539  CSLConstList papszRootGroupOptions,
1540  CSLConstList papszOptions );
1541 
1542  CPLErr (*pfnDelete)( const char * pszName );
1543 
1544  GDALDataset *(*pfnCreateCopy)( const char *, GDALDataset *,
1545  int, char **,
1546  GDALProgressFunc pfnProgress,
1547  void * pProgressData );
1548 
1549  void *pDriverData;
1550 
1551  void (*pfnUnloadDriver)(GDALDriver *);
1552 
1560  int (*pfnIdentify)( GDALOpenInfo * );
1561  int (*pfnIdentifyEx)( GDALDriver*, GDALOpenInfo * );
1562 
1563  CPLErr (*pfnRename)( const char * pszNewName,
1564  const char * pszOldName );
1565  CPLErr (*pfnCopyFiles)( const char * pszNewName,
1566  const char * pszOldName );
1567 
1568  // Used for legacy OGR drivers, and Python drivers
1569  GDALDataset *(*pfnOpenWithDriverArg)( GDALDriver*, GDALOpenInfo * );
1570 
1571  /* For legacy OGR drivers */
1572  GDALDataset *(*pfnCreateVectorOnly)( GDALDriver*,
1573  const char * pszName,
1574  char ** papszOptions );
1575  CPLErr (*pfnDeleteDataSource)( GDALDriver*,
1576  const char * pszName );
1578 
1579 /* -------------------------------------------------------------------- */
1580 /* Helper methods. */
1581 /* -------------------------------------------------------------------- */
1583  GDALDataset *DefaultCreateCopy( const char *, GDALDataset *,
1584  int, CSLConstList papszOptions,
1585  GDALProgressFunc pfnProgress,
1586  void * pProgressData ) CPL_WARN_UNUSED_RESULT;
1587 
1588  static CPLErr DefaultCreateCopyMultiDimensional(
1589  GDALDataset *poSrcDS,
1590  GDALDataset *poDstDS,
1591  bool bStrict,
1592  CSLConstList /*papszOptions*/,
1593  GDALProgressFunc pfnProgress,
1594  void * pProgressData );
1595 
1596  static CPLErr DefaultCopyMasks( GDALDataset *poSrcDS,
1597  GDALDataset *poDstDS,
1598  int bStrict );
1599  static CPLErr DefaultCopyMasks( GDALDataset *poSrcDS,
1600  GDALDataset *poDstDS,
1601  int bStrict,
1602  CSLConstList papszOptions,
1603  GDALProgressFunc pfnProgress,
1604  void * pProgressData );
1606  static CPLErr QuietDelete( const char * pszName,
1607  CSLConstList papszAllowedDrivers = nullptr);
1608 
1610  static CPLErr DefaultRename( const char * pszNewName,
1611  const char * pszOldName );
1612  static CPLErr DefaultCopyFiles( const char * pszNewName,
1613  const char * pszOldName );
1615 
1619  static inline GDALDriverH ToHandle(GDALDriver* poDriver)
1620  { return static_cast<GDALDriverH>(poDriver); }
1621 
1625  static inline GDALDriver* FromHandle(GDALDriverH hDriver)
1626  { return static_cast<GDALDriver*>(hDriver); }
1627 
1628 private:
1630 };
1631 
1632 /* ******************************************************************** */
1633 /* GDALDriverManager */
1634 /* ******************************************************************** */
1635 
1643 class CPL_DLL GDALDriverManager : public GDALMajorObject
1644 {
1645  int nDrivers = 0;
1646  GDALDriver **papoDrivers = nullptr;
1647  std::map<CPLString, GDALDriver*> oMapNameToDrivers{};
1648 
1649  GDALDriver *GetDriver_unlocked( int iDriver )
1650  { return (iDriver >= 0 && iDriver < nDrivers) ?
1651  papoDrivers[iDriver] : nullptr; }
1652 
1653  GDALDriver *GetDriverByName_unlocked( const char * pszName ) const
1654  { auto oIter = oMapNameToDrivers.find(CPLString(pszName).toupper());
1655  return oIter == oMapNameToDrivers.end() ? nullptr : oIter->second;
1656  }
1657 
1658  static char** GetSearchPaths(const char* pszGDAL_DRIVER_PATH);
1659 
1660  static void CleanupPythonDrivers();
1661 
1663 
1664  public:
1666  ~GDALDriverManager();
1667 
1668  int GetDriverCount( void ) const;
1669  GDALDriver *GetDriver( int );
1670  GDALDriver *GetDriverByName( const char * );
1671 
1672  int RegisterDriver( GDALDriver * );
1673  void DeregisterDriver( GDALDriver * );
1674 
1675  // AutoLoadDrivers is a no-op if compiled with GDAL_NO_AUTOLOAD defined.
1676  static void AutoLoadDrivers();
1677  void AutoSkipDrivers();
1678 
1679  static void AutoLoadPythonDrivers();
1680 };
1681 
1683 GDALDriverManager CPL_DLL * GetGDALDriverManager( void );
1684 CPL_C_END
1685 
1686 /* ******************************************************************** */
1687 /* GDALAsyncReader */
1688 /* ******************************************************************** */
1689 
1695 class CPL_DLL GDALAsyncReader
1696 {
1697 
1699 
1700  protected:
1702  GDALDataset* poDS;
1703  int nXOff;
1704  int nYOff;
1705  int nXSize;
1706  int nYSize;
1707  void * pBuf;
1708  int nBufXSize;
1709  int nBufYSize;
1710  GDALDataType eBufType;
1711  int nBandCount;
1712  int* panBandMap;
1713  int nPixelSpace;
1714  int nLineSpace;
1715  int nBandSpace;
1717 
1718  public:
1719  GDALAsyncReader();
1720  virtual ~GDALAsyncReader();
1721 
1725  GDALDataset* GetGDALDataset() {return poDS;}
1729  int GetXOffset() const { return nXOff; }
1733  int GetYOffset() const { return nYOff; }
1737  int GetXSize() const { return nXSize; }
1741  int GetYSize() const { return nYSize; }
1745  void * GetBuffer() {return pBuf;}
1749  int GetBufferXSize() const { return nBufXSize; }
1753  int GetBufferYSize() const { return nBufYSize; }
1757  GDALDataType GetBufferType() const { return eBufType; }
1761  int GetBandCount() const { return nBandCount; }
1765  int* GetBandMap() { return panBandMap; }
1769  int GetPixelSpace() const { return nPixelSpace; }
1773  int GetLineSpace() const { return nLineSpace; }
1777  int GetBandSpace() const { return nBandSpace; }
1778 
1779  virtual GDALAsyncStatusType
1780  GetNextUpdatedRegion(double dfTimeout,
1781  int* pnBufXOff, int* pnBufYOff,
1782  int* pnBufXSize, int* pnBufYSize) = 0;
1783  virtual int LockBuffer( double dfTimeout = -1.0 );
1784  virtual void UnlockBuffer();
1785 };
1786 
1787 /* ******************************************************************** */
1788 /* Multidimensional array API */
1789 /* ******************************************************************** */
1790 
1791 class GDALMDArray;
1792 class GDALAttribute;
1793 class GDALDimension;
1794 class GDALEDTComponent;
1795 
1796 /* ******************************************************************** */
1797 /* GDALExtendedDataType */
1798 /* ******************************************************************** */
1799 
1808 {
1809 public:
1811 
1813 
1815 
1816  static GDALExtendedDataType Create(GDALDataType eType);
1817  static GDALExtendedDataType Create(const std::string& osName,
1818  size_t nTotalSize,
1819  std::vector<std::unique_ptr<GDALEDTComponent>>&& components);
1820  static GDALExtendedDataType CreateString(size_t nMaxStringLength = 0,
1822 
1823  bool operator== (const GDALExtendedDataType& ) const;
1825  bool operator!= (const GDALExtendedDataType& other) const { return !(operator==(other)); }
1826 
1831  const std::string& GetName() const { return m_osName; }
1832 
1837  GDALExtendedDataTypeClass GetClass() const { return m_eClass; }
1838 
1843  GDALDataType GetNumericDataType() const { return m_eNumericDT; }
1844 
1851  GDALExtendedDataTypeSubType GetSubType() const { return m_eSubType; }
1852 
1857  const std::vector<std::unique_ptr<GDALEDTComponent>>& GetComponents() const { return m_aoComponents; }
1858 
1865  size_t GetSize() const { return m_nSize; }
1866 
1871  size_t GetMaxStringLength() const { return m_nMaxStringLength; }
1872 
1873  bool CanConvertTo(const GDALExtendedDataType& other) const;
1874 
1875  bool NeedsFreeDynamicMemory() const;
1876 
1877  void FreeDynamicMemory(void* pBuffer) const;
1878 
1879  static
1880  bool CopyValue(const void* pSrc, const GDALExtendedDataType& srcType,
1881  void* pDst, const GDALExtendedDataType& dstType);
1882 
1883 private:
1884  GDALExtendedDataType(size_t nMaxStringLength, GDALExtendedDataTypeSubType eSubType);
1885  explicit GDALExtendedDataType(GDALDataType eType);
1886  GDALExtendedDataType(const std::string& osName,
1887  size_t nTotalSize,
1888  std::vector<std::unique_ptr<GDALEDTComponent>>&& components);
1889 
1890  std::string m_osName{};
1893  GDALDataType m_eNumericDT = GDT_Unknown;
1894  std::vector<std::unique_ptr<GDALEDTComponent>> m_aoComponents{};
1895  size_t m_nSize = 0;
1896  size_t m_nMaxStringLength = 0;
1897 };
1898 
1899 /* ******************************************************************** */
1900 /* GDALEDTComponent */
1901 /* ******************************************************************** */
1902 
1908 class CPL_DLL GDALEDTComponent
1909 {
1910 public:
1911  ~GDALEDTComponent();
1912  GDALEDTComponent(const std::string& name, size_t offset, const GDALExtendedDataType& type);
1914 
1915  bool operator== (const GDALEDTComponent& ) const;
1916 
1921  const std::string& GetName() const { return m_osName; }
1922 
1927  size_t GetOffset() const { return m_nOffset; }
1928 
1933  const GDALExtendedDataType& GetType() const { return m_oType; }
1934 
1935 private:
1936  std::string m_osName;
1937  size_t m_nOffset;
1938  GDALExtendedDataType m_oType;
1939 };
1940 
1941 /* ******************************************************************** */
1942 /* GDALIHasAttribute */
1943 /* ******************************************************************** */
1944 
1950 class CPL_DLL GDALIHasAttribute
1951 {
1952 protected:
1953  std::shared_ptr<GDALAttribute> GetAttributeFromAttributes(const std::string& osName) const;
1954 
1955 public:
1956  virtual ~GDALIHasAttribute();
1957 
1958  virtual std::shared_ptr<GDALAttribute> GetAttribute(const std::string& osName) const;
1959 
1960  virtual std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList papszOptions = nullptr) const;
1961 
1962  virtual std::shared_ptr<GDALAttribute> CreateAttribute(
1963  const std::string& osName,
1964  const std::vector<GUInt64>& anDimensions,
1965  const GDALExtendedDataType& oDataType,
1966  CSLConstList papszOptions = nullptr);
1967 };
1968 
1969 /* ******************************************************************** */
1970 /* GDALGroup */
1971 /* ******************************************************************** */
1972 
1981 class CPL_DLL GDALGroup: public GDALIHasAttribute
1982 {
1983 protected:
1985  std::string m_osName{};
1986  std::string m_osFullName{};
1987 
1988  GDALGroup(const std::string& osParentName, const std::string& osName);
1989 
1990  const GDALGroup* GetInnerMostGroup(const std::string& osPathOrArrayOrDim,
1991  std::shared_ptr<GDALGroup>& curGroupHolder,
1992  std::string& osLastPart) const;
1994 
1995 public:
1996  virtual ~GDALGroup();
1997 
2002  const std::string& GetName() const { return m_osName; }
2003 
2008  const std::string& GetFullName() const { return m_osFullName; }
2009 
2010  virtual std::vector<std::string> GetMDArrayNames(CSLConstList papszOptions = nullptr) const;
2011  virtual std::shared_ptr<GDALMDArray> OpenMDArray(const std::string& osName,
2012  CSLConstList papszOptions = nullptr) const;
2013 
2014  virtual std::vector<std::string> GetGroupNames(CSLConstList papszOptions = nullptr) const;
2015  virtual std::shared_ptr<GDALGroup> OpenGroup(const std::string& osName,
2016  CSLConstList papszOptions = nullptr) const;
2017 
2018  virtual std::vector<std::string> GetVectorLayerNames(CSLConstList papszOptions = nullptr) const;
2019  virtual OGRLayer* OpenVectorLayer(const std::string& osName,
2020  CSLConstList papszOptions = nullptr) const;
2021 
2022  virtual std::vector<std::shared_ptr<GDALDimension>> GetDimensions(CSLConstList papszOptions = nullptr) const;
2023 
2024  virtual std::shared_ptr<GDALGroup> CreateGroup(const std::string& osName,
2025  CSLConstList papszOptions = nullptr);
2026 
2027  virtual std::shared_ptr<GDALDimension> CreateDimension(const std::string& osName,
2028  const std::string& osType,
2029  const std::string& osDirection,
2030  GUInt64 nSize,
2031  CSLConstList papszOptions = nullptr);
2032 
2033  virtual std::shared_ptr<GDALMDArray> CreateMDArray(const std::string& osName,
2034  const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
2035  const GDALExtendedDataType& oDataType,
2036  CSLConstList papszOptions = nullptr);
2037 
2038  GUInt64 GetTotalCopyCost() const;
2039 
2040  virtual bool CopyFrom(const std::shared_ptr<GDALGroup>& poDstRootGroup,
2041  GDALDataset* poSrcDS,
2042  const std::shared_ptr<GDALGroup>& poSrcGroup,
2043  bool bStrict,
2044  GUInt64& nCurCost,
2045  const GUInt64 nTotalCost,
2046  GDALProgressFunc pfnProgress,
2047  void * pProgressData,
2048  CSLConstList papszOptions = nullptr);
2049 
2050  virtual CSLConstList GetStructuralInfo() const;
2051 
2052  std::shared_ptr<GDALMDArray> OpenMDArrayFromFullname(
2053  const std::string& osFullName,
2054  CSLConstList papszOptions = nullptr) const;
2055 
2056  std::shared_ptr<GDALMDArray> ResolveMDArray(const std::string& osName,
2057  const std::string& osStartingPath,
2058  CSLConstList papszOptions = nullptr) const;
2059 
2060  std::shared_ptr<GDALGroup> OpenGroupFromFullname(
2061  const std::string& osFullName,
2062  CSLConstList papszOptions = nullptr) const;
2063 
2064  std::shared_ptr<GDALDimension> OpenDimensionFromFullname(
2065  const std::string& osFullName) const;
2066 
2067  virtual void ClearStatistics();
2068 
2070  static constexpr GUInt64 COPY_COST = 1000;
2072 };
2073 
2074 /* ******************************************************************** */
2075 /* GDALAbstractMDArray */
2076 /* ******************************************************************** */
2077 
2083 class CPL_DLL GDALAbstractMDArray
2084 {
2085 protected:
2087  std::string m_osName{};
2088  std::string m_osFullName{};
2089  std::weak_ptr<GDALAbstractMDArray> m_pSelf{};
2090 
2091  GDALAbstractMDArray(const std::string& osParentName, const std::string& osName);
2092 
2093  void SetSelf(std::weak_ptr<GDALAbstractMDArray> self) { m_pSelf = self; }
2094 
2095  bool CheckReadWriteParams(const GUInt64* arrayStartIdx,
2096  const size_t* count,
2097  const GInt64*& arrayStep,
2098  const GPtrDiff_t*& bufferStride,
2099  const GDALExtendedDataType& bufferDataType,
2100  const void* buffer,
2101  const void* buffer_alloc_start,
2102  size_t buffer_alloc_size,
2103  std::vector<GInt64>& tmp_arrayStep,
2104  std::vector<GPtrDiff_t>& tmp_bufferStride) const;
2105 
2106  virtual bool IRead(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2107  const size_t* count, // array of size GetDimensionCount()
2108  const GInt64* arrayStep, // step in elements
2109  const GPtrDiff_t* bufferStride, // stride in elements
2110  const GDALExtendedDataType& bufferDataType,
2111  void* pDstBuffer) const = 0;
2112 
2113  virtual bool IWrite(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2114  const size_t* count, // array of size GetDimensionCount()
2115  const GInt64* arrayStep, // step in elements
2116  const GPtrDiff_t* bufferStride, // stride in elements
2117  const GDALExtendedDataType& bufferDataType,
2118  const void* pSrcBuffer);
2120 
2121 public:
2122  virtual ~GDALAbstractMDArray();
2123 
2128  const std::string& GetName() const{ return m_osName; }
2129 
2134  const std::string& GetFullName() const{ return m_osFullName; }
2135 
2136  GUInt64 GetTotalElementsCount() const;
2137 
2138  virtual size_t GetDimensionCount() const;
2139 
2140  virtual const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const = 0;
2141 
2142  virtual const GDALExtendedDataType &GetDataType() const = 0;
2143 
2144  virtual std::vector<GUInt64> GetBlockSize() const;
2145 
2146  virtual std::vector<size_t> GetProcessingChunkSize(size_t nMaxChunkMemory) const;
2147 
2163  typedef bool (*FuncProcessPerChunkType)(
2164  GDALAbstractMDArray* array,
2165  const GUInt64* chunkArrayStartIdx,
2166  const size_t* chunkCount,
2167  GUInt64 iCurChunk,
2168  GUInt64 nChunkCount,
2169  void* pUserData);
2170 
2171  virtual bool ProcessPerChunk(const GUInt64* arrayStartIdx,
2172  const GUInt64* count,
2173  const size_t* chunkSize,
2174  FuncProcessPerChunkType pfnFunc,
2175  void* pUserData);
2176 
2177  virtual bool Read(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2178  const size_t* count, // array of size GetDimensionCount()
2179  const GInt64* arrayStep, // step in elements
2180  const GPtrDiff_t* bufferStride, // stride in elements
2181  const GDALExtendedDataType& bufferDataType,
2182  void* pDstBuffer,
2183  const void* pDstBufferAllocStart = nullptr,
2184  size_t nDstBufferAllocSize = 0) const;
2185 
2186  bool Write(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2187  const size_t* count, // array of size GetDimensionCount()
2188  const GInt64* arrayStep, // step in elements
2189  const GPtrDiff_t* bufferStride, // stride in elements
2190  const GDALExtendedDataType& bufferDataType,
2191  const void* pSrcBuffer,
2192  const void* pSrcBufferAllocStart = nullptr,
2193  size_t nSrcBufferAllocSize = 0);
2194 };
2195 
2196 /* ******************************************************************** */
2197 /* GDALRawResult */
2198 /* ******************************************************************** */
2199 
2206 class CPL_DLL GDALRawResult
2207 {
2208 private:
2209  GDALExtendedDataType m_dt;
2210  size_t m_nEltCount;
2211  size_t m_nSize;
2212  GByte* m_raw;
2213 
2214  void FreeMe();
2215 
2216  GDALRawResult(const GDALRawResult&) = delete;
2217  GDALRawResult& operator=(const GDALRawResult&) = delete;
2218 
2219 protected:
2220  friend class GDALAttribute;
2222  GDALRawResult(GByte* raw,
2223  const GDALExtendedDataType& dt,
2224  size_t nEltCount);
2226 
2227 public:
2228  ~GDALRawResult();
2230  GDALRawResult& operator=(GDALRawResult&&);
2231 
2233  const GByte& operator[](size_t idx) const { return m_raw[idx]; }
2235  const GByte* data() const { return m_raw; }
2237  size_t size() const { return m_nSize; }
2238 
2240  GByte* StealData();
2242 };
2243 
2244 
2245 /* ******************************************************************** */
2246 /* GDALAttribute */
2247 /* ******************************************************************** */
2248 
2259 class CPL_DLL GDALAttribute: virtual public GDALAbstractMDArray
2260 {
2261  mutable std::string m_osCachedVal{};
2262 
2263 protected:
2265  GDALAttribute(const std::string& osParentName, const std::string& osName);
2267 
2268 public:
2269 
2270  std::vector<GUInt64> GetDimensionsSize() const;
2271 
2272  GDALRawResult ReadAsRaw() const;
2273  const char* ReadAsString() const;
2274  int ReadAsInt() const;
2275  double ReadAsDouble() const;
2276  CPLStringList ReadAsStringArray() const;
2277  std::vector<int> ReadAsIntArray() const;
2278  std::vector<double> ReadAsDoubleArray() const;
2279 
2281  bool Write(const void* pabyValue, size_t nLen);
2282  bool Write(const char*);
2283  bool WriteInt(int);
2284  bool Write(double);
2285  bool Write(CSLConstList);
2286  bool Write(const double*, size_t);
2287 
2289  static constexpr GUInt64 COPY_COST = 100;
2291 
2292 };
2293 
2294 /************************************************************************/
2295 /* GDALAttributeString */
2296 /************************************************************************/
2297 
2299 class CPL_DLL GDALAttributeString final: public GDALAttribute
2300 {
2301  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2303  std::string m_osValue;
2304 
2305 protected:
2306 
2307  bool IRead(const GUInt64* ,
2308  const size_t* ,
2309  const GInt64* ,
2310  const GPtrDiff_t* ,
2311  const GDALExtendedDataType& bufferDataType,
2312  void* pDstBuffer) const override;
2313 
2314 public:
2315  GDALAttributeString(const std::string& osParentName,
2316  const std::string& osName,
2317  const std::string& osValue,
2319 
2320  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2321 
2322  const GDALExtendedDataType &GetDataType() const override;
2323 };
2325 
2326 /************************************************************************/
2327 /* GDALAttributeNumeric */
2328 /************************************************************************/
2329 
2331 class CPL_DLL GDALAttributeNumeric final: public GDALAttribute
2332 {
2333  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2334  GDALExtendedDataType m_dt;
2335  int m_nValue = 0;
2336  double m_dfValue = 0;
2337  std::vector<GUInt32> m_anValuesUInt32{};
2338 
2339 protected:
2340 
2341  bool IRead(const GUInt64* ,
2342  const size_t* ,
2343  const GInt64* ,
2344  const GPtrDiff_t* ,
2345  const GDALExtendedDataType& bufferDataType,
2346  void* pDstBuffer) const override;
2347 
2348 public:
2349  GDALAttributeNumeric(const std::string& osParentName,
2350  const std::string& osName,
2351  double dfValue);
2352  GDALAttributeNumeric(const std::string& osParentName,
2353  const std::string& osName,
2354  int nValue);
2355  GDALAttributeNumeric(const std::string& osParentName,
2356  const std::string& osName,
2357  const std::vector<GUInt32>& anValues);
2358 
2359  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2360 
2361  const GDALExtendedDataType &GetDataType() const override;
2362 };
2364 
2365 /* ******************************************************************** */
2366 /* GDALMDArray */
2367 /* ******************************************************************** */
2368 
2377 class CPL_DLL GDALMDArray: virtual public GDALAbstractMDArray, public GDALIHasAttribute
2378 {
2379  friend class GDALMDArrayResampled;
2380  std::shared_ptr<GDALMDArray> GetView(const std::vector<GUInt64>& indices) const;
2381 
2382  inline std::shared_ptr<GDALMDArray> atInternal(std::vector<GUInt64>& indices) const
2383  {
2384  return GetView(indices);
2385  }
2386 
2387  template<typename... GUInt64VarArg>
2388  // cppcheck-suppress functionStatic
2389  inline std::shared_ptr<GDALMDArray> atInternal(std::vector<GUInt64>& indices,
2390  GUInt64 idx, GUInt64VarArg... tail) const
2391  {
2392  indices.push_back(idx);
2393  return atInternal(indices, tail...);
2394  }
2395 
2396  mutable bool m_bHasTriedCachedArray = false;
2397  mutable std::shared_ptr<GDALMDArray> m_poCachedArray{};
2398 
2399 protected:
2401  GDALMDArray(const std::string& osParentName, const std::string& osName);
2402 
2403  virtual bool IAdviseRead(const GUInt64* arrayStartIdx,
2404  const size_t* count,
2405  CSLConstList papszOptions) const;
2406 
2407  virtual bool IsCacheable() const { return true; }
2408 
2409  virtual bool SetStatistics( bool bApproxStats,
2410  double dfMin, double dfMax,
2411  double dfMean, double dfStdDev,
2412  GUInt64 nValidCount );
2413 
2414  static std::string MassageName(const std::string& inputName);
2415 
2416  std::shared_ptr<GDALGroup> GetCacheRootGroup(bool bCanCreate,
2417  std::string& osCacheFilenameOut) const;
2419 
2420 public:
2421 
2422  GUInt64 GetTotalCopyCost() const;
2423 
2424  virtual bool CopyFrom(GDALDataset* poSrcDS,
2425  const GDALMDArray* poSrcArray,
2426  bool bStrict,
2427  GUInt64& nCurCost,
2428  const GUInt64 nTotalCost,
2429  GDALProgressFunc pfnProgress,
2430  void * pProgressData);
2431 
2433  virtual bool IsWritable() const = 0;
2434 
2443  virtual const std::string& GetFilename() const = 0;
2444 
2445  virtual CSLConstList GetStructuralInfo() const;
2446 
2447  virtual const std::string& GetUnit() const;
2448 
2449  virtual bool SetUnit(const std::string& osUnit);
2450 
2451  virtual bool SetSpatialRef(const OGRSpatialReference* poSRS);
2452 
2453  virtual std::shared_ptr<OGRSpatialReference> GetSpatialRef() const;
2454 
2455  virtual const void* GetRawNoDataValue() const;
2456 
2457  double GetNoDataValueAsDouble(bool* pbHasNoData = nullptr) const;
2458 
2459  virtual bool SetRawNoDataValue(const void* pRawNoData);
2460 
2461  bool SetNoDataValue(double dfNoData);
2462 
2463  virtual double GetOffset(bool* pbHasOffset = nullptr, GDALDataType* peStorageType = nullptr) const;
2464 
2465  virtual double GetScale(bool* pbHasScale = nullptr, GDALDataType* peStorageType = nullptr) const;
2466 
2467  virtual bool SetOffset(double dfOffset, GDALDataType eStorageType = GDT_Unknown);
2468 
2469  virtual bool SetScale(double dfScale, GDALDataType eStorageType = GDT_Unknown);
2470 
2471  std::shared_ptr<GDALMDArray> GetView(const std::string& viewExpr) const;
2472 
2473  std::shared_ptr<GDALMDArray> operator[](const std::string& fieldName) const;
2474 
2484  // sphinx 4.1.0 / breathe 4.30.0 don't like typename...
2486  template<typename... GUInt64VarArg>
2488  // cppcheck-suppress functionStatic
2489  std::shared_ptr<GDALMDArray> at(GUInt64 idx, GUInt64VarArg... tail) const
2490  {
2491  std::vector<GUInt64> indices;
2492  indices.push_back(idx);
2493  return atInternal(indices, tail...);
2494  }
2495 
2496  virtual std::shared_ptr<GDALMDArray> Transpose(const std::vector<int>& anMapNewAxisToOldAxis) const;
2497 
2498  std::shared_ptr<GDALMDArray> GetUnscaled() const;
2499 
2500  virtual std::shared_ptr<GDALMDArray> GetMask(CSLConstList papszOptions) const;
2501 
2502  std::shared_ptr<GDALMDArray>
2503  GetResampled( const std::vector<std::shared_ptr<GDALDimension>>& apoNewDims,
2504  GDALRIOResampleAlg resampleAlg,
2505  const OGRSpatialReference* poTargetSRS,
2506  CSLConstList papszOptions ) const;
2507 
2508  virtual GDALDataset* AsClassicDataset(size_t iXDim, size_t iYDim) const;
2509 
2510  virtual CPLErr GetStatistics( bool bApproxOK, bool bForce,
2511  double *pdfMin, double *pdfMax,
2512  double *pdfMean, double *padfStdDev,
2513  GUInt64* pnValidCount,
2514  GDALProgressFunc pfnProgress, void *pProgressData );
2515 
2516  virtual bool ComputeStatistics( bool bApproxOK,
2517  double *pdfMin, double *pdfMax,
2518  double *pdfMean, double *pdfStdDev,
2519  GUInt64* pnValidCount,
2520  GDALProgressFunc, void *pProgressData );
2521 
2522  virtual void ClearStatistics();
2523 
2524  virtual std::vector<std::shared_ptr<GDALMDArray>> GetCoordinateVariables() const;
2525 
2526  bool AdviseRead(const GUInt64* arrayStartIdx,
2527  const size_t* count,
2528  CSLConstList papszOptions = nullptr) const;
2529 
2530  bool IsRegularlySpaced(double& dfStart, double& dfIncrement) const;
2531 
2532  bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
2533  double adfGeoTransform[6]) const;
2534 
2535  bool Cache( CSLConstList papszOptions = nullptr ) const;
2536 
2537  bool Read(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2538  const size_t* count, // array of size GetDimensionCount()
2539  const GInt64* arrayStep, // step in elements
2540  const GPtrDiff_t* bufferStride, // stride in elements
2541  const GDALExtendedDataType& bufferDataType,
2542  void* pDstBuffer,
2543  const void* pDstBufferAllocStart = nullptr,
2544  size_t nDstBufferAllocSize = 0) const override final;
2545 
2547  static constexpr GUInt64 COPY_COST = 1000;
2548 
2549  bool CopyFromAllExceptValues(const GDALMDArray* poSrcArray,
2550  bool bStrict,
2551  GUInt64& nCurCost,
2552  const GUInt64 nTotalCost,
2553  GDALProgressFunc pfnProgress,
2554  void * pProgressData);
2555  struct Range
2556  {
2557  GUInt64 m_nStartIdx;
2558  GInt64 m_nIncr;
2559  Range(GUInt64 nStartIdx = 0, GInt64 nIncr = 0):
2560  m_nStartIdx(nStartIdx), m_nIncr(nIncr) {}
2561  };
2562 
2563  struct ViewSpec
2564  {
2565  std::string m_osFieldName{};
2566 
2567  // or
2568 
2569  std::vector<size_t> m_mapDimIdxToParentDimIdx{}; // of size m_dims.size()
2570  std::vector<Range> m_parentRanges{} ; // of size m_poParent->GetDimensionCount()
2571  };
2572 
2573  virtual std::shared_ptr<GDALMDArray> GetView(const std::string& viewExpr,
2574  bool bRenameDimensions,
2575  std::vector<ViewSpec>& viewSpecs) const;
2577 };
2578 
2580 bool GDALMDRasterIOFromBand(GDALRasterBand* poBand,
2581  GDALRWFlag eRWFlag,
2582  size_t iDimX,
2583  size_t iDimY,
2584  const GUInt64* arrayStartIdx,
2585  const size_t* count,
2586  const GInt64* arrayStep,
2587  const GPtrDiff_t* bufferStride,
2588  const GDALExtendedDataType& bufferDataType,
2589  void* pBuffer);
2591 
2592 /************************************************************************/
2593 /* GDALMDArrayRegularlySpaced */
2594 /************************************************************************/
2595 
2597 class CPL_DLL GDALMDArrayRegularlySpaced: public GDALMDArray
2598 {
2599  double m_dfStart;
2600  double m_dfIncrement;
2601  double m_dfOffsetInIncrement;
2603  std::vector<std::shared_ptr<GDALDimension>> m_dims;
2604  std::vector<std::shared_ptr<GDALAttribute>> m_attributes{};
2605  std::string m_osEmptyFilename{};
2606 
2607 protected:
2608 
2609  bool IRead(const GUInt64* ,
2610  const size_t* ,
2611  const GInt64* ,
2612  const GPtrDiff_t* ,
2613  const GDALExtendedDataType& bufferDataType,
2614  void* pDstBuffer) const override;
2615 
2616 public:
2617  GDALMDArrayRegularlySpaced(
2618  const std::string& osParentName,
2619  const std::string& osName,
2620  const std::shared_ptr<GDALDimension>& poDim,
2621  double dfStart, double dfIncrement,
2622  double dfOffsetInIncrement);
2623 
2624  bool IsWritable() const override { return false; }
2625 
2626  const std::string& GetFilename() const override { return m_osEmptyFilename; }
2627 
2628  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2629 
2630  const GDALExtendedDataType &GetDataType() const override;
2631 
2632  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
2633 
2634  void AddAttribute(const std::shared_ptr<GDALAttribute>& poAttr);
2635 };
2637 
2638 /* ******************************************************************** */
2639 /* GDALDimension */
2640 /* ******************************************************************** */
2641 
2653 class CPL_DLL GDALDimension
2654 {
2655 public:
2657  GDALDimension(const std::string& osParentName,
2658  const std::string& osName,
2659  const std::string& osType,
2660  const std::string& osDirection,
2661  GUInt64 nSize);
2663 
2664  virtual ~GDALDimension();
2665 
2670  const std::string& GetName() const { return m_osName; }
2671 
2676  const std::string& GetFullName() const { return m_osFullName; }
2677 
2686  const std::string& GetType() const { return m_osType; }
2687 
2696  const std::string& GetDirection() const { return m_osDirection; }
2697 
2702  GUInt64 GetSize() const { return m_nSize; }
2703 
2704  virtual std::shared_ptr<GDALMDArray> GetIndexingVariable() const;
2705 
2706  virtual bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable);
2707 
2708 protected:
2710  std::string m_osName;
2711  std::string m_osFullName;
2712  std::string m_osType;
2713  std::string m_osDirection;
2714  GUInt64 m_nSize;
2716 };
2717 
2718 
2719 /************************************************************************/
2720 /* GDALDimensionWeakIndexingVar() */
2721 /************************************************************************/
2722 
2724 class CPL_DLL GDALDimensionWeakIndexingVar: public GDALDimension
2725 {
2726  std::weak_ptr<GDALMDArray> m_poIndexingVariable{};
2727 
2728 public:
2729  GDALDimensionWeakIndexingVar(const std::string& osParentName,
2730  const std::string& osName,
2731  const std::string& osType,
2732  const std::string& osDirection,
2733  GUInt64 nSize);
2734 
2735  std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
2736 
2737  bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable) override;
2738 };
2740 
2741 /************************************************************************/
2742 /* GDALAntiRecursionGuard */
2743 /************************************************************************/
2744 
2746 struct GDALAntiRecursionStruct;
2747 class GDALAntiRecursionGuard
2748 {
2749  GDALAntiRecursionStruct* m_psAntiRecursionStruct;
2750  std::string m_osIdentifier;
2751  int m_nDepth;
2752 
2753  GDALAntiRecursionGuard(const GDALAntiRecursionGuard&) = delete;
2754  GDALAntiRecursionGuard& operator= (const GDALAntiRecursionGuard&) = delete;
2755 
2756 public:
2757  explicit GDALAntiRecursionGuard(const std::string& osIdentifier);
2758  GDALAntiRecursionGuard(const GDALAntiRecursionGuard& other, const std::string& osIdentifier);
2759  ~GDALAntiRecursionGuard();
2760  int GetCallDepth() const { return m_nDepth; }
2761 };
2763 
2764 
2765 /* ==================================================================== */
2766 /* An assortment of overview related stuff. */
2767 /* ==================================================================== */
2768 
2770 /* Only exported for drivers as plugin. Signature may change */
2771 CPLErr CPL_DLL
2772 GDALRegenerateOverviewsMultiBand(int nBands, GDALRasterBand** papoSrcBands,
2773  int nOverviews,
2774  GDALRasterBand*** papapoOverviewBands,
2775  const char * pszResampling,
2776  GDALProgressFunc pfnProgress, void * pProgressData );
2777 
2778 typedef CPLErr (*GDALResampleFunction)
2779  ( double dfXRatioDstToSrc,
2780  double dfYRatioDstToSrc,
2781  double dfSrcXDelta,
2782  double dfSrcYDelta,
2783  GDALDataType eWrkDataType,
2784  const void * pChunk,
2785  const GByte * pabyChunkNodataMask,
2786  int nChunkXOff, int nChunkXSize,
2787  int nChunkYOff, int nChunkYSize,
2788  int nDstXOff, int nDstXOff2,
2789  int nDstYOff, int nDstYOff2,
2790  GDALRasterBand * poOverview,
2791  void** ppDstBuffer,
2792  GDALDataType* peDstBufferDataType,
2793  const char * pszResampling,
2794  int bHasNoData, float fNoDataValue,
2795  GDALColorTable* poColorTable,
2796  GDALDataType eSrcDataType,
2797  bool bPropagateNoData );
2798 
2799 GDALResampleFunction GDALGetResampleFunction(const char* pszResampling,
2800  int* pnRadius);
2801 
2802 GDALDataType GDALGetOvrWorkDataType(const char* pszResampling,
2803  GDALDataType eSrcDataType);
2804 
2806 
2807 CPLErr CPL_DLL
2808 HFAAuxBuildOverviews( const char *pszOvrFilename, GDALDataset *poParentDS,
2809  GDALDataset **ppoDS,
2810  int nBands, int *panBandList,
2811  int nNewOverviews, int *panNewOverviewList,
2812  const char *pszResampling,
2813  GDALProgressFunc pfnProgress,
2814  void *pProgressData );
2815 
2816 CPLErr CPL_DLL
2817 GTIFFBuildOverviews( const char * pszFilename,
2818  int nBands, GDALRasterBand **papoBandList,
2819  int nOverviews, int * panOverviewList,
2820  const char * pszResampling,
2821  GDALProgressFunc pfnProgress, void * pProgressData );
2822 
2823 int CPL_DLL GDALBandGetBestOverviewLevel(GDALRasterBand* poBand,
2824  int &nXOff, int &nYOff,
2825  int &nXSize, int &nYSize,
2826  int nBufXSize, int nBufYSize) CPL_WARN_DEPRECATED("Use GDALBandGetBestOverviewLevel2 instead");
2827 int CPL_DLL GDALBandGetBestOverviewLevel2(GDALRasterBand* poBand,
2828  int &nXOff, int &nYOff,
2829  int &nXSize, int &nYSize,
2830  int nBufXSize, int nBufYSize,
2831  GDALRasterIOExtraArg* psExtraArg);
2832 
2833 int CPL_DLL GDALOvLevelAdjust( int nOvLevel, int nXSize ) CPL_WARN_DEPRECATED("Use GDALOvLevelAdjust2 instead");
2834 int CPL_DLL GDALOvLevelAdjust2( int nOvLevel, int nXSize, int nYSize );
2835 int CPL_DLL GDALComputeOvFactor( int nOvrXSize, int nRasterXSize,
2836  int nOvrYSize, int nRasterYSize );
2837 
2838 GDALDataset CPL_DLL *
2839 GDALFindAssociatedAuxFile( const char *pszBasefile, GDALAccess eAccess,
2840  GDALDataset *poDependentDS );
2841 
2842 /* ==================================================================== */
2843 /* Infrastructure to check that dataset characteristics are valid */
2844 /* ==================================================================== */
2845 
2846 int CPL_DLL GDALCheckDatasetDimensions( int nXSize, int nYSize );
2847 int CPL_DLL GDALCheckBandCount( int nBands, int bIsZeroAllowed );
2848 
2849 /* Internal use only */
2850 
2851 /* CPL_DLL exported, but only for in-tree drivers that can be built as plugins */
2852 int CPL_DLL GDALReadWorldFile2( const char *pszBaseFilename, const char *pszExtension,
2853  double *padfGeoTransform, char** papszSiblingFiles,
2854  char** ppszWorldFileNameOut);
2855 int GDALReadTabFile2( const char * pszBaseFilename,
2856  double *padfGeoTransform, char **ppszWKT,
2857  int *pnGCPCount, GDAL_GCP **ppasGCPs,
2858  char** papszSiblingFiles, char** ppszTabFileNameOut );
2859 
2860 void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg* psDestArg,
2861  GDALRasterIOExtraArg* psSrcArg);
2862 
2863 CPL_C_END
2864 
2865 void GDALNullifyOpenDatasetsList();
2866 CPLMutex** GDALGetphDMMutex();
2867 CPLMutex** GDALGetphDLMutex();
2868 void GDALNullifyProxyPoolSingleton();
2869 void GDALSetResponsiblePIDForCurrentThread(GIntBig responsiblePID);
2870 GIntBig GDALGetResponsiblePIDForCurrentThread();
2871 
2872 CPLString GDALFindAssociatedFile( const char *pszBasename, const char *pszExt,
2873  CSLConstList papszSiblingFiles, int nFlags );
2874 
2875 CPLErr CPL_DLL EXIFExtractMetadata(char**& papszMetadata,
2876  void *fpL, int nOffset,
2877  int bSwabflag, int nTIFFHEADER,
2878  int& nExifOffset, int& nInterOffset, int& nGPSOffset);
2879 
2880 int GDALValidateOpenOptions( GDALDriverH hDriver,
2881  const char* const* papszOptionOptions);
2882 int GDALValidateOptions( const char* pszOptionList,
2883  const char* const* papszOptionsToValidate,
2884  const char* pszErrorMessageOptionType,
2885  const char* pszErrorMessageContainerName);
2886 
2887 GDALRIOResampleAlg GDALRasterIOGetResampleAlg(const char* pszResampling);
2888 const char* GDALRasterIOGetResampleAlg(GDALRIOResampleAlg eResampleAlg);
2889 
2890 void GDALRasterIOExtraArgSetResampleAlg(GDALRasterIOExtraArg* psExtraArg,
2891  int nXSize, int nYSize,
2892  int nBufXSize, int nBufYSize);
2893 
2894 
2895 GDALDataset* GDALCreateOverviewDataset(GDALDataset* poDS, int nOvrLevel,
2896  int bThisLevelOnly);
2897 
2898 // Should cover particular cases of #3573, #4183, #4506, #6578
2899 // Behavior is undefined if fVal1 or fVal2 are NaN (should be tested before
2900 // calling this function)
2901 template<class T> inline bool ARE_REAL_EQUAL(T fVal1, T fVal2, int ulp = 2)
2902 {
2903  return fVal1 == fVal2 || /* Should cover infinity */
2904  std::abs(fVal1 - fVal2) < std::numeric_limits<float>::epsilon() * std::abs(fVal1+fVal2) * ulp;
2905 }
2906 
2907 double GDALAdjustNoDataCloseToFloatMax(double dfVal);
2908 
2909 #define DIV_ROUND_UP(a, b) ( ((a) % (b)) == 0 ? ((a) / (b)) : (((a) / (b)) + 1) )
2910 
2911 // Number of data samples that will be used to compute approximate statistics
2912 // (minimum value, maximum value, etc.)
2913 #define GDALSTAT_APPROX_NUMSAMPLES 2500
2914 
2915 void GDALSerializeGCPListToXML( CPLXMLNode* psParentNode,
2916  GDAL_GCP* pasGCPList,
2917  int nGCPCount,
2918  const OGRSpatialReference* poGCP_SRS );
2919 void GDALDeserializeGCPListFromXML( CPLXMLNode* psGCPList,
2920  GDAL_GCP** ppasGCPList,
2921  int* pnGCPCount,
2922  OGRSpatialReference** ppoGCP_SRS );
2923 
2924 void GDALSerializeOpenOptionsToXML( CPLXMLNode* psParentNode, char** papszOpenOptions);
2925 char** GDALDeserializeOpenOptionsFromXML( CPLXMLNode* psParentNode );
2926 
2927 int GDALCanFileAcceptSidecarFile(const char* pszFilename);
2928 
2929 bool GDALCanReliablyUseSiblingFileList(const char* pszFilename);
2930 
2931 bool CPL_DLL GDALIsDriverDeprecatedForGDAL35StillEnabled(const char* pszDriverName, const char* pszExtraMsg = "");
2932 
2933 typedef enum
2934 {
2935  GSF_UNSIGNED_INT,
2936  GSF_SIGNED_INT,
2937  GSF_FLOATING_POINT,
2938 } GDALBufferSampleFormat;
2939 
2940 bool CPL_DLL GDALBufferHasOnlyNoData(const void* pBuffer,
2941  double dfNoDataValue,
2942  size_t nWidth, size_t nHeight,
2943  size_t nLineStride,
2944  size_t nComponents,
2945  int nBitsPerSample,
2946  GDALBufferSampleFormat nSampleFormat);
2947 
2949 
2950 #endif /* ndef GDAL_PRIV_H_INCLUDED */
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:442
Convenient string class based on std::string.
Definition: cpl_string.h:333
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition: gdal_priv.h:2084
virtual const std::vector< std::shared_ptr< GDALDimension > > & GetDimensions() const =0
Return the dimensions of an attribute/array.
virtual const GDALExtendedDataType & GetDataType() const =0
Return the data type of an attribute/array.
const std::string & GetFullName() const
Return the name of an array or attribute.
Definition: gdal_priv.h:2134
const std::string & GetName() const
Return the name of an array or attribute.
Definition: gdal_priv.h:2128
bool Write(const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep, const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer, const void *pSrcBufferAllocStart=nullptr, size_t nSrcBufferAllocSize=0)
Write part or totality of a multidimensional array or attribute.
Definition: gdalmultidim.cpp:1841
Class used as a session object for asynchronous requests.
Definition: gdal_priv.h:1696
void * GetBuffer()
Return buffer.
Definition: gdal_priv.h:1745
int GetXOffset() const
Return x offset.
Definition: gdal_priv.h:1729
int GetYOffset() const
Return y offset.
Definition: gdal_priv.h:1733
int GetYSize() const
Return height.
Definition: gdal_priv.h:1741
int GetBandCount() const
Return band count.
Definition: gdal_priv.h:1761
GDALDataType GetBufferType() const
Return buffer data type.
Definition: gdal_priv.h:1757
int GetBandSpace() const
Return band spacing.
Definition: gdal_priv.h:1777
int GetBufferYSize() const
Return buffer height.
Definition: gdal_priv.h:1753
int GetXSize() const
Return width.
Definition: gdal_priv.h:1737
GDALDataset * GetGDALDataset()
Return dataset.
Definition: gdal_priv.h:1725
virtual GDALAsyncStatusType GetNextUpdatedRegion(double dfTimeout, int *pnBufXOff, int *pnBufYOff, int *pnBufXSize, int *pnBufYSize)=0
Get async IO update.
int GetPixelSpace() const
Return pixel spacing.
Definition: gdal_priv.h:1769
int * GetBandMap()
Return band map.
Definition: gdal_priv.h:1765
int GetLineSpace() const
Return line spacing.
Definition: gdal_priv.h:1773
int GetBufferXSize() const
Return buffer width.
Definition: gdal_priv.h:1749
Class modeling an attribute that has a name, a value and a type, and is typically used to describe a ...
Definition: gdal_priv.h:2260
A color table / palette.
Definition: gdal_priv.h:1025
static GDALColorTableH ToHandle(GDALColorTable *poCT)
Convert a GDALColorTable* to a GDALRasterBandH.
Definition: gdal_priv.h:1050
static GDALColorTable * FromHandle(GDALColorTableH hCT)
Convert a GDALColorTableH to a GDALColorTable*.
Definition: gdal_priv.h:1056
~GDALColorTable()
Destructor.
Class returned by GetBands() that act as a container for raster bands.
Definition: gdal_priv.h:476
Class returned by GetFeatures() that act as a container for vector features.
Definition: gdal_priv.h:769
Layer iterator.
Definition: gdal_priv.h:719
void pointer
pointer
Definition: gdal_priv.h:727
void difference_type
difference_type
Definition: gdal_priv.h:726
std::input_iterator_tag iterator_category
iterator_category
Definition: gdal_priv.h:728
Class returned by GetLayers() that acts as a range of layers.
Definition: gdal_priv.h:706
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:340
virtual int CloseDependentDatasets()
Drop references to any other datasets referenced by this dataset.
Definition: gdaldataset.cpp:4144
static GDALDataset * FromHandle(GDALDatasetH hDS)
Convert a GDALDatasetH to a GDALDataset*.
Definition: gdal_priv.h:649
CPLErr BuildOverviews(const char *, int, int *, int, int *, GDALProgressFunc, void *)
Build raster overview(s)
Definition: gdaldataset.cpp:1980
virtual CPLErr CreateMaskBand(int nFlagsIn)
Adds a mask band to the dataset.
Definition: gdaldataset.cpp:3147
static GDALDataset * Open(const char *pszFilename, unsigned int nOpenFlags=0, const char *const *papszAllowedDrivers=nullptr, const char *const *papszOpenOptions=nullptr, const char *const *papszSiblingFiles=nullptr)
Definition: gdal_priv.h:655
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
char ** GetOpenOptions()
Return open options.
Definition: gdal_priv.h:610
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
static GDALDatasetH ToHandle(GDALDataset *poDS)
Convert a GDALDataset* to a GDALDatasetH.
Definition: gdal_priv.h:643
GDALAccess GetAccess() const
Return access mode.
Definition: gdal_priv.h:600
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition: gdal_priv.h:2654
const std::string & GetName() const
Return the name.
Definition: gdal_priv.h:2670
const std::string & GetType() const
Return the axis type.
Definition: gdal_priv.h:2686
const std::string & GetDirection() const
Return the axis direction.
Definition: gdal_priv.h:2696
GUInt64 GetSize() const
Return the size, that is the number of values along the dimension.
Definition: gdal_priv.h:2702
const std::string & GetFullName() const
Return the full name.
Definition: gdal_priv.h:2676
Class for managing the registration of file format drivers.
Definition: gdal_priv.h:1644
Format specific driver.
Definition: gdal_priv.h:1489
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition: gdal_priv.h:1625
static GDALDriverH ToHandle(GDALDriver *poDriver)
Convert a GDALDriver* to a GDALDriverH.
Definition: gdal_priv.h:1619
Class for a component of a compound extended data type.
Definition: gdal_priv.h:1909
const std::string & GetName() const
Return the name.
Definition: gdal_priv.h:1921
size_t GetOffset() const
Return the offset (in bytes) of the component in the compound data type.
Definition: gdal_priv.h:1927
const GDALExtendedDataType & GetType() const
Return the data type of the component.
Definition: gdal_priv.h:1933
GDALEDTComponent(const GDALEDTComponent &)
Copy constructor.
Class used to represent potentially complex data types.
Definition: gdal_priv.h:1808
GDALExtendedDataTypeSubType GetSubType() const
Return subtype.
Definition: gdal_priv.h:1851
size_t GetSize() const
Return data type size in bytes.
Definition: gdal_priv.h:1865
size_t GetMaxStringLength() const
Return the maximum length of a string in bytes.
Definition: gdal_priv.h:1871
static GDALExtendedDataType Create(GDALDataType eType)
Return a new GDALExtendedDataType of class GEDTC_NUMERIC.
Definition: gdalmultidim.cpp:7716
const std::vector< std::unique_ptr< GDALEDTComponent > > & GetComponents() const
Return the components of the data type (only valid when GetClass() == GEDTC_COMPOUND)
Definition: gdal_priv.h:1857
static GDALExtendedDataType CreateString(size_t nMaxStringLength=0, GDALExtendedDataTypeSubType eSubType=GEDTST_NONE)
Return a new GDALExtendedDataType of class GEDTC_STRING.
Definition: gdalmultidim.cpp:7780
GDALDataType GetNumericDataType() const
Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)
Definition: gdal_priv.h:1843
GDALExtendedDataTypeClass GetClass() const
Return type class.
Definition: gdal_priv.h:1837
const std::string & GetName() const
Return type name.
Definition: gdal_priv.h:1831
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition: gdal_priv.h:1982
const std::string & GetName() const
Return the name of the group.
Definition: gdal_priv.h:2002
const std::string & GetFullName() const
Return the full name of the group.
Definition: gdal_priv.h:2008
Interface used to get a single GDALAttribute or a set of GDALAttribute.
Definition: gdal_priv.h:1951
Class modeling a multi-dimensional array.
Definition: gdal_priv.h:2378
virtual bool IsWritable() const =0
Return whether an array is writable.
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
std::shared_ptr< GDALMDArray > at(GUInt64 idx, GUInt64VarArg... tail) const
Return a view of the array using integer indexing.
Definition: gdal_priv.h:2489
Object with metadata.
Definition: gdal_priv.h:136
static GDALMajorObjectH ToHandle(GDALMajorObject *poMajorObject)
Convert a GDALMajorObject* to a GDALMajorObjectH.
Definition: gdal_priv.h:171
static GDALMajorObject * FromHandle(GDALMajorObjectH hMajorObject)
Convert a GDALMajorObjectH to a GDALMajorObject*.
Definition: gdal_priv.h:177
Class for dataset open functions.
Definition: gdal_priv.h:269
int bStatOK
Whether stat()'ing the file was successful.
Definition: gdal_priv.h:290
GByte * pabyHeader
Buffer with first bytes of the file.
Definition: gdal_priv.h:300
int bIsDirectory
Whether the file is a directory.
Definition: gdal_priv.h:292
char ** papszOpenOptions
Open options.
Definition: gdal_priv.h:282
GDALAccess eAccess
Access flag.
Definition: gdal_priv.h:285
int nOpenFlags
Open flags.
Definition: gdal_priv.h:287
VSILFILE * fpL
Pointer to the file.
Definition: gdal_priv.h:295
char * pszFilename
Filename.
Definition: gdal_priv.h:280
int nHeaderBytes
Number of bytes in pabyHeader.
Definition: gdal_priv.h:298
const char *const * papszAllowedDrivers
Allowed drivers (NULL for all)
Definition: gdal_priv.h:303
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:48
A single raster band (or channel).
Definition: gdal_priv.h:1134
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition: gdal_priv.h:1348
virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, GSpacing, GSpacing, GDALRasterIOExtraArg *psExtraArg)
Read/write a region of image data for this band.
Definition: rasterio.cpp:209
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Read a block of data.
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition: gdal_priv.h:1354
A single raster block in the block cache.
Definition: gdal_priv.h:910
int GetDirty() const
Return the dirty flag.
Definition: gdal_priv.h:978
int GetXSize() const
Return the width of the block.
Definition: gdal_priv.h:970
GPtrDiff_t GetBlockSize() const
Return the block size in bytes.
Definition: gdal_priv.h:986
int GetYSize() const
Return the height of the block.
Definition: gdal_priv.h:974
GDALDataType GetDataType() const
Return the data type.
Definition: gdal_priv.h:958
int GetXOff() const
Return the x offset of the top-left corner of the block.
Definition: gdal_priv.h:962
int AddLock(void)
Increment the lock count.
Definition: gdal_priv.h:948
GDALRasterBand * GetBand()
Accessor to source GDALRasterBand object.
Definition: gdal_priv.h:994
int GetYOff() const
Return the y offset of the top-left corner of the block.
Definition: gdal_priv.h:966
int DropLock(void)
Decrement the lock count.
Definition: gdal_priv.h:950
void * GetDataRef(void)
Return the data buffer.
Definition: gdal_priv.h:982
Store the raw result of an attribute value, which might contain dynamically allocated structures (lik...
Definition: gdal_priv.h:2207
size_t size() const
Return the size in bytes of the raw result.
Definition: gdal_priv.h:2237
const GByte * data() const
Return pointer to the start of data.
Definition: gdal_priv.h:2235
const GByte & operator[](size_t idx) const
Return byte at specified index.
Definition: gdal_priv.h:2233
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:371
Definition of a field domain.
Definition: ogr_feature.h:836
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:327
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:71
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
This class represents a style table.
Definition: ogr_featurestyle.h:85
Various convenience functions for CPL.
CPLErr
Error category.
Definition: cpl_error.h:53
int CPLErrorNum
Error number.
Definition: cpl_error.h:94
Definitions for CPL mini XML Parser/Serializer.
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:285
#define CPL_NULL_TERMINATED
Null terminated variadic.
Definition: cpl_port.h:859
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:247
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:331
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:329
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:263
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:869
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:955
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:265
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:894
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:244
Various convenience functions for working with strings and string lists.
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:62
Standard C Covers.
FILE VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition: cpl_vsi.h:156
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:286
GDALAccess
Definition: gdal.h:115
@ GA_ReadOnly
Definition: gdal.h:116
void GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:3757
GDALPaletteInterp
Definition: gdal.h:230
@ GPI_RGB
Definition: gdal.h:232
GDALDataType
Definition: gdal.h:62
@ GDT_Byte
Definition: gdal.h:64
@ GDT_Float64
Definition: gdal.h:72
@ GDT_Unknown
Definition: gdal.h:63
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:268
GDALExtendedDataTypeClass
Enumeration giving the class of a GDALExtendedDataType.
Definition: gdal.h:291
@ GEDTC_NUMERIC
Numeric value.
Definition: gdal.h:293
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:131
int GDALGetDataTypeSizeBytes(GDALDataType)
Get data type size in bytes.
Definition: gdal_misc.cpp:308
GDALDatasetH GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags, const char *const *papszAllowedDrivers, const char *const *papszOpenOptions, const char *const *papszSiblingFiles)
Open a raster or vector file as a GDALDataset.
Definition: gdaldataset.cpp:3338
GDALExtendedDataTypeSubType
Enumeration giving the subtype of a GDALExtendedDataType.
Definition: gdal.h:303
@ GEDTST_NONE
None.
Definition: gdal.h:305
void * GDALMajorObjectH
Opaque type used for the C bindings of the C++ GDALMajorObject class.
Definition: gdal.h:265
GDALColorInterp
Definition: gdal.h:204
GDALAsyncStatusType
status of the asynchronous stream
Definition: gdal.h:103
void * GDALDriverH
Opaque type used for the C bindings of the C++ GDALDriver class.
Definition: gdal.h:274
GDALRWFlag
Definition: gdal.h:121
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:271
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition: gdal.h:277
std::unique_ptr< GDALDataset, GDALDatasetUniquePtrDeleter > GDALDatasetUniquePtr
Unique pointer type for GDALDataset.
Definition: gdal_priv.h:899
GDALDriverManager * GetGDALDriverManager(void)
Fetch the global GDAL driver manager.
Definition: gdaldrivermanager.cpp:99
GDALIdentifyEnum
Enumeration used by GDALDriver::pfnIdentify().
Definition: gdal_priv.h:1464
@ GDAL_IDENTIFY_TRUE
Identify determined the file is recognized by the probed driver.
Definition: gdal_priv.h:1470
@ GDAL_IDENTIFY_FALSE
Identify determined the file is not recognized by the probed driver.
Definition: gdal_priv.h:1468
@ GDAL_IDENTIFY_UNKNOWN
Identify could not determine if the file is recognized or not by the probed driver.
Definition: gdal_priv.h:1466
Core portability services for cross-platform OGR code.
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:369
@ wkbUnknown
unknown type, non-standard
Definition: ogr_core.h:370
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:341
Simple feature classes.
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition: ogr_feature.h:796
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:287
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:292
Document node structure.
Definition: cpl_minixml.h:70
Color tuple.
Definition: gdal.h:1287
Object returned by GetFeatures() iterators.
Definition: gdal_priv.h:669
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition: gdal.h:161
Ground Control Point.
Definition: gdal.h:711