GDAL
gdal_priv.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: gdal_priv.h a52e59ceeaf2526250d1aab947c5cf914104db22 2021-12-06 15:41:59 +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
89 
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
336 
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;
734  ~Iterator();
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:
1032  ~GDALColorTable();
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 {
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 )
1654  { return oMapNameToDrivers[CPLString(pszName).toupper()]; }
1655 
1656  static char** GetSearchPaths(const char* pszGDAL_DRIVER_PATH);
1657 
1658  static void CleanupPythonDrivers();
1659 
1661 
1662  public:
1664  ~GDALDriverManager();
1665 
1666  int GetDriverCount( void ) const;
1667  GDALDriver *GetDriver( int );
1668  GDALDriver *GetDriverByName( const char * );
1669 
1670  int RegisterDriver( GDALDriver * );
1671  void DeregisterDriver( GDALDriver * );
1672 
1673  // AutoLoadDrivers is a no-op if compiled with GDAL_NO_AUTOLOAD defined.
1674  static void AutoLoadDrivers();
1675  void AutoSkipDrivers();
1676 
1677  static void AutoLoadPythonDrivers();
1678 };
1679 
1681 GDALDriverManager CPL_DLL * GetGDALDriverManager( void );
1682 CPL_C_END
1683 
1684 /* ******************************************************************** */
1685 /* GDALAsyncReader */
1686 /* ******************************************************************** */
1687 
1693 class CPL_DLL GDALAsyncReader
1694 {
1695 
1697 
1698  protected:
1700  GDALDataset* poDS;
1701  int nXOff;
1702  int nYOff;
1703  int nXSize;
1704  int nYSize;
1705  void * pBuf;
1706  int nBufXSize;
1707  int nBufYSize;
1708  GDALDataType eBufType;
1709  int nBandCount;
1710  int* panBandMap;
1711  int nPixelSpace;
1712  int nLineSpace;
1713  int nBandSpace;
1715 
1716  public:
1717  GDALAsyncReader();
1718  virtual ~GDALAsyncReader();
1719 
1723  GDALDataset* GetGDALDataset() {return poDS;}
1727  int GetXOffset() const { return nXOff; }
1731  int GetYOffset() const { return nYOff; }
1735  int GetXSize() const { return nXSize; }
1739  int GetYSize() const { return nYSize; }
1743  void * GetBuffer() {return pBuf;}
1747  int GetBufferXSize() const { return nBufXSize; }
1751  int GetBufferYSize() const { return nBufYSize; }
1755  GDALDataType GetBufferType() const { return eBufType; }
1759  int GetBandCount() const { return nBandCount; }
1763  int* GetBandMap() { return panBandMap; }
1767  int GetPixelSpace() const { return nPixelSpace; }
1771  int GetLineSpace() const { return nLineSpace; }
1775  int GetBandSpace() const { return nBandSpace; }
1776 
1777  virtual GDALAsyncStatusType
1778  GetNextUpdatedRegion(double dfTimeout,
1779  int* pnBufXOff, int* pnBufYOff,
1780  int* pnBufXSize, int* pnBufYSize) = 0;
1781  virtual int LockBuffer( double dfTimeout = -1.0 );
1782  virtual void UnlockBuffer();
1783 };
1784 
1785 /* ******************************************************************** */
1786 /* Multidimensional array API */
1787 /* ******************************************************************** */
1788 
1789 class GDALMDArray;
1790 class GDALAttribute;
1791 class GDALDimension;
1792 class GDALEDTComponent;
1793 
1794 /* ******************************************************************** */
1795 /* GDALExtendedDataType */
1796 /* ******************************************************************** */
1797 
1806 {
1807 public:
1809 
1811 
1813 
1814  static GDALExtendedDataType Create(GDALDataType eType);
1815  static GDALExtendedDataType Create(const std::string& osName,
1816  size_t nTotalSize,
1817  std::vector<std::unique_ptr<GDALEDTComponent>>&& components);
1818  static GDALExtendedDataType CreateString(size_t nMaxStringLength = 0,
1820 
1821  bool operator== (const GDALExtendedDataType& ) const;
1823  bool operator!= (const GDALExtendedDataType& other) const { return !(operator==(other)); }
1824 
1829  const std::string& GetName() const { return m_osName; }
1830 
1835  GDALExtendedDataTypeClass GetClass() const { return m_eClass; }
1836 
1841  GDALDataType GetNumericDataType() const { return m_eNumericDT; }
1842 
1849  GDALExtendedDataTypeSubType GetSubType() const { return m_eSubType; }
1850 
1855  const std::vector<std::unique_ptr<GDALEDTComponent>>& GetComponents() const { return m_aoComponents; }
1856 
1863  size_t GetSize() const { return m_nSize; }
1864 
1869  size_t GetMaxStringLength() const { return m_nMaxStringLength; }
1870 
1871  bool CanConvertTo(const GDALExtendedDataType& other) const;
1872 
1873  bool NeedsFreeDynamicMemory() const;
1874 
1875  void FreeDynamicMemory(void* pBuffer) const;
1876 
1877  static
1878  bool CopyValue(const void* pSrc, const GDALExtendedDataType& srcType,
1879  void* pDst, const GDALExtendedDataType& dstType);
1880 
1881 private:
1882  GDALExtendedDataType(size_t nMaxStringLength, GDALExtendedDataTypeSubType eSubType);
1883  explicit GDALExtendedDataType(GDALDataType eType);
1884  GDALExtendedDataType(const std::string& osName,
1885  size_t nTotalSize,
1886  std::vector<std::unique_ptr<GDALEDTComponent>>&& components);
1887 
1888  std::string m_osName{};
1891  GDALDataType m_eNumericDT = GDT_Unknown;
1892  std::vector<std::unique_ptr<GDALEDTComponent>> m_aoComponents{};
1893  size_t m_nSize = 0;
1894  size_t m_nMaxStringLength = 0;
1895 };
1896 
1897 /* ******************************************************************** */
1898 /* GDALEDTComponent */
1899 /* ******************************************************************** */
1900 
1906 class CPL_DLL GDALEDTComponent
1907 {
1908 public:
1909  ~GDALEDTComponent();
1910  GDALEDTComponent(const std::string& name, size_t offset, const GDALExtendedDataType& type);
1912 
1913  bool operator== (const GDALEDTComponent& ) const;
1914 
1919  const std::string& GetName() const { return m_osName; }
1920 
1925  size_t GetOffset() const { return m_nOffset; }
1926 
1931  const GDALExtendedDataType& GetType() const { return m_oType; }
1932 
1933 private:
1934  std::string m_osName;
1935  size_t m_nOffset;
1936  GDALExtendedDataType m_oType;
1937 };
1938 
1939 /* ******************************************************************** */
1940 /* GDALIHasAttribute */
1941 /* ******************************************************************** */
1942 
1948 class CPL_DLL GDALIHasAttribute
1949 {
1950 protected:
1951  std::shared_ptr<GDALAttribute> GetAttributeFromAttributes(const std::string& osName) const;
1952 
1953 public:
1954  virtual ~GDALIHasAttribute();
1955 
1956  virtual std::shared_ptr<GDALAttribute> GetAttribute(const std::string& osName) const;
1957 
1958  virtual std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList papszOptions = nullptr) const;
1959 
1960  virtual std::shared_ptr<GDALAttribute> CreateAttribute(
1961  const std::string& osName,
1962  const std::vector<GUInt64>& anDimensions,
1963  const GDALExtendedDataType& oDataType,
1964  CSLConstList papszOptions = nullptr);
1965 };
1966 
1967 /* ******************************************************************** */
1968 /* GDALGroup */
1969 /* ******************************************************************** */
1970 
1979 class CPL_DLL GDALGroup: public GDALIHasAttribute
1980 {
1981 protected:
1983  std::string m_osName{};
1984  std::string m_osFullName{};
1985 
1986  GDALGroup(const std::string& osParentName, const std::string& osName);
1987 
1988  const GDALGroup* GetInnerMostGroup(const std::string& osPathOrArrayOrDim,
1989  std::shared_ptr<GDALGroup>& curGroupHolder,
1990  std::string& osLastPart) const;
1992 
1993 public:
1994  virtual ~GDALGroup();
1995 
2000  const std::string& GetName() const { return m_osName; }
2001 
2006  const std::string& GetFullName() const { return m_osFullName; }
2007 
2008  virtual std::vector<std::string> GetMDArrayNames(CSLConstList papszOptions = nullptr) const;
2009  virtual std::shared_ptr<GDALMDArray> OpenMDArray(const std::string& osName,
2010  CSLConstList papszOptions = nullptr) const;
2011 
2012  virtual std::vector<std::string> GetGroupNames(CSLConstList papszOptions = nullptr) const;
2013  virtual std::shared_ptr<GDALGroup> OpenGroup(const std::string& osName,
2014  CSLConstList papszOptions = nullptr) const;
2015 
2016  virtual std::vector<std::string> GetVectorLayerNames(CSLConstList papszOptions = nullptr) const;
2017  virtual OGRLayer* OpenVectorLayer(const std::string& osName,
2018  CSLConstList papszOptions = nullptr) const;
2019 
2020  virtual std::vector<std::shared_ptr<GDALDimension>> GetDimensions(CSLConstList papszOptions = nullptr) const;
2021 
2022  virtual std::shared_ptr<GDALGroup> CreateGroup(const std::string& osName,
2023  CSLConstList papszOptions = nullptr);
2024 
2025  virtual std::shared_ptr<GDALDimension> CreateDimension(const std::string& osName,
2026  const std::string& osType,
2027  const std::string& osDirection,
2028  GUInt64 nSize,
2029  CSLConstList papszOptions = nullptr);
2030 
2031  virtual std::shared_ptr<GDALMDArray> CreateMDArray(const std::string& osName,
2032  const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
2033  const GDALExtendedDataType& oDataType,
2034  CSLConstList papszOptions = nullptr);
2035 
2036  GUInt64 GetTotalCopyCost() const;
2037 
2038  virtual bool CopyFrom(const std::shared_ptr<GDALGroup>& poDstRootGroup,
2039  GDALDataset* poSrcDS,
2040  const std::shared_ptr<GDALGroup>& poSrcGroup,
2041  bool bStrict,
2042  GUInt64& nCurCost,
2043  const GUInt64 nTotalCost,
2044  GDALProgressFunc pfnProgress,
2045  void * pProgressData,
2046  CSLConstList papszOptions = nullptr);
2047 
2048  virtual CSLConstList GetStructuralInfo() const;
2049 
2050  std::shared_ptr<GDALMDArray> OpenMDArrayFromFullname(
2051  const std::string& osFullName,
2052  CSLConstList papszOptions = nullptr) const;
2053 
2054  std::shared_ptr<GDALMDArray> ResolveMDArray(const std::string& osName,
2055  const std::string& osStartingPath,
2056  CSLConstList papszOptions = nullptr) const;
2057 
2058  std::shared_ptr<GDALGroup> OpenGroupFromFullname(
2059  const std::string& osFullName,
2060  CSLConstList papszOptions = nullptr) const;
2061 
2062  std::shared_ptr<GDALDimension> OpenDimensionFromFullname(
2063  const std::string& osFullName) const;
2064 
2065  virtual void ClearStatistics();
2066 
2068  static constexpr GUInt64 COPY_COST = 1000;
2070 };
2071 
2072 /* ******************************************************************** */
2073 /* GDALAbstractMDArray */
2074 /* ******************************************************************** */
2075 
2081 class CPL_DLL GDALAbstractMDArray
2082 {
2083 protected:
2085  std::string m_osName{};
2086  std::string m_osFullName{};
2087  std::weak_ptr<GDALAbstractMDArray> m_pSelf{};
2088 
2089  GDALAbstractMDArray(const std::string& osParentName, const std::string& osName);
2090 
2091  void SetSelf(std::weak_ptr<GDALAbstractMDArray> self) { m_pSelf = self; }
2092 
2093  bool CheckReadWriteParams(const GUInt64* arrayStartIdx,
2094  const size_t* count,
2095  const GInt64*& arrayStep,
2096  const GPtrDiff_t*& bufferStride,
2097  const GDALExtendedDataType& bufferDataType,
2098  const void* buffer,
2099  const void* buffer_alloc_start,
2100  size_t buffer_alloc_size,
2101  std::vector<GInt64>& tmp_arrayStep,
2102  std::vector<GPtrDiff_t>& tmp_bufferStride) const;
2103 
2104  virtual bool IRead(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2105  const size_t* count, // array of size GetDimensionCount()
2106  const GInt64* arrayStep, // step in elements
2107  const GPtrDiff_t* bufferStride, // stride in elements
2108  const GDALExtendedDataType& bufferDataType,
2109  void* pDstBuffer) const = 0;
2110 
2111  virtual bool IWrite(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2112  const size_t* count, // array of size GetDimensionCount()
2113  const GInt64* arrayStep, // step in elements
2114  const GPtrDiff_t* bufferStride, // stride in elements
2115  const GDALExtendedDataType& bufferDataType,
2116  const void* pSrcBuffer);
2118 
2119 public:
2120  virtual ~GDALAbstractMDArray();
2121 
2126  const std::string& GetName() const{ return m_osName; }
2127 
2132  const std::string& GetFullName() const{ return m_osFullName; }
2133 
2134  GUInt64 GetTotalElementsCount() const;
2135 
2136  virtual size_t GetDimensionCount() const;
2137 
2138  virtual const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const = 0;
2139 
2140  virtual const GDALExtendedDataType &GetDataType() const = 0;
2141 
2142  virtual std::vector<GUInt64> GetBlockSize() const;
2143 
2144  virtual std::vector<size_t> GetProcessingChunkSize(size_t nMaxChunkMemory) const;
2145 
2161  typedef bool (*FuncProcessPerChunkType)(
2162  GDALAbstractMDArray* array,
2163  const GUInt64* chunkArrayStartIdx,
2164  const size_t* chunkCount,
2165  GUInt64 iCurChunk,
2166  GUInt64 nChunkCount,
2167  void* pUserData);
2168 
2169  virtual bool ProcessPerChunk(const GUInt64* arrayStartIdx,
2170  const GUInt64* count,
2171  const size_t* chunkSize,
2172  FuncProcessPerChunkType pfnFunc,
2173  void* pUserData);
2174 
2175  virtual bool Read(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2176  const size_t* count, // array of size GetDimensionCount()
2177  const GInt64* arrayStep, // step in elements
2178  const GPtrDiff_t* bufferStride, // stride in elements
2179  const GDALExtendedDataType& bufferDataType,
2180  void* pDstBuffer,
2181  const void* pDstBufferAllocStart = nullptr,
2182  size_t nDstBufferAllocSize = 0) const;
2183 
2184  bool Write(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2185  const size_t* count, // array of size GetDimensionCount()
2186  const GInt64* arrayStep, // step in elements
2187  const GPtrDiff_t* bufferStride, // stride in elements
2188  const GDALExtendedDataType& bufferDataType,
2189  const void* pSrcBuffer,
2190  const void* pSrcBufferAllocStart = nullptr,
2191  size_t nSrcBufferAllocSize = 0);
2192 };
2193 
2194 /* ******************************************************************** */
2195 /* GDALRawResult */
2196 /* ******************************************************************** */
2197 
2204 class CPL_DLL GDALRawResult
2205 {
2206 private:
2207  GDALExtendedDataType m_dt;
2208  size_t m_nEltCount;
2209  size_t m_nSize;
2210  GByte* m_raw;
2211 
2212  void FreeMe();
2213 
2214  GDALRawResult(const GDALRawResult&) = delete;
2215  GDALRawResult& operator=(const GDALRawResult&) = delete;
2216 
2217 protected:
2218  friend class GDALAttribute;
2220  GDALRawResult(GByte* raw,
2221  const GDALExtendedDataType& dt,
2222  size_t nEltCount);
2224 
2225 public:
2226  ~GDALRawResult();
2228  GDALRawResult& operator=(GDALRawResult&&);
2229 
2231  const GByte& operator[](size_t idx) const { return m_raw[idx]; }
2233  const GByte* data() const { return m_raw; }
2235  size_t size() const { return m_nSize; }
2236 
2238  GByte* StealData();
2240 };
2241 
2242 
2243 /* ******************************************************************** */
2244 /* GDALAttribute */
2245 /* ******************************************************************** */
2246 
2257 class CPL_DLL GDALAttribute: virtual public GDALAbstractMDArray
2258 {
2259  mutable std::string m_osCachedVal{};
2260 
2261 protected:
2263  GDALAttribute(const std::string& osParentName, const std::string& osName);
2265 
2266 public:
2267 
2268  std::vector<GUInt64> GetDimensionsSize() const;
2269 
2270  GDALRawResult ReadAsRaw() const;
2271  const char* ReadAsString() const;
2272  int ReadAsInt() const;
2273  double ReadAsDouble() const;
2274  CPLStringList ReadAsStringArray() const;
2275  std::vector<int> ReadAsIntArray() const;
2276  std::vector<double> ReadAsDoubleArray() const;
2277 
2279  bool Write(const void* pabyValue, size_t nLen);
2280  bool Write(const char*);
2281  bool WriteInt(int);
2282  bool Write(double);
2283  bool Write(CSLConstList);
2284  bool Write(const double*, size_t);
2285 
2287  static constexpr GUInt64 COPY_COST = 100;
2289 
2290 };
2291 
2292 /************************************************************************/
2293 /* GDALAttributeString */
2294 /************************************************************************/
2295 
2297 class CPL_DLL GDALAttributeString final: public GDALAttribute
2298 {
2299  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2301  std::string m_osValue;
2302 
2303 protected:
2304 
2305  bool IRead(const GUInt64* ,
2306  const size_t* ,
2307  const GInt64* ,
2308  const GPtrDiff_t* ,
2309  const GDALExtendedDataType& bufferDataType,
2310  void* pDstBuffer) const override;
2311 
2312 public:
2313  GDALAttributeString(const std::string& osParentName,
2314  const std::string& osName,
2315  const std::string& osValue,
2317 
2318  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2319 
2320  const GDALExtendedDataType &GetDataType() const override;
2321 };
2323 
2324 /************************************************************************/
2325 /* GDALAttributeNumeric */
2326 /************************************************************************/
2327 
2329 class CPL_DLL GDALAttributeNumeric final: public GDALAttribute
2330 {
2331  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2332  GDALExtendedDataType m_dt;
2333  int m_nValue = 0;
2334  double m_dfValue = 0;
2335  std::vector<GUInt32> m_anValuesUInt32{};
2336 
2337 protected:
2338 
2339  bool IRead(const GUInt64* ,
2340  const size_t* ,
2341  const GInt64* ,
2342  const GPtrDiff_t* ,
2343  const GDALExtendedDataType& bufferDataType,
2344  void* pDstBuffer) const override;
2345 
2346 public:
2347  GDALAttributeNumeric(const std::string& osParentName,
2348  const std::string& osName,
2349  double dfValue);
2350  GDALAttributeNumeric(const std::string& osParentName,
2351  const std::string& osName,
2352  int nValue);
2353  GDALAttributeNumeric(const std::string& osParentName,
2354  const std::string& osName,
2355  const std::vector<GUInt32>& anValues);
2356 
2357  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2358 
2359  const GDALExtendedDataType &GetDataType() const override;
2360 };
2362 
2363 /* ******************************************************************** */
2364 /* GDALMDArray */
2365 /* ******************************************************************** */
2366 
2375 class CPL_DLL GDALMDArray: virtual public GDALAbstractMDArray, public GDALIHasAttribute
2376 {
2377  friend class GDALMDArrayResampled;
2378  std::shared_ptr<GDALMDArray> GetView(const std::vector<GUInt64>& indices) const;
2379 
2380  inline std::shared_ptr<GDALMDArray> atInternal(std::vector<GUInt64>& indices) const
2381  {
2382  return GetView(indices);
2383  }
2384 
2385  template<typename... GUInt64VarArg>
2386  // cppcheck-suppress functionStatic
2387  inline std::shared_ptr<GDALMDArray> atInternal(std::vector<GUInt64>& indices,
2388  GUInt64 idx, GUInt64VarArg... tail) const
2389  {
2390  indices.push_back(idx);
2391  return atInternal(indices, tail...);
2392  }
2393 
2394  mutable bool m_bHasTriedCachedArray = false;
2395  mutable std::shared_ptr<GDALMDArray> m_poCachedArray{};
2396 
2397 protected:
2399  GDALMDArray(const std::string& osParentName, const std::string& osName);
2400 
2401  virtual bool IAdviseRead(const GUInt64* arrayStartIdx,
2402  const size_t* count,
2403  CSLConstList papszOptions) const;
2404 
2405  virtual bool IsCacheable() const { return true; }
2406 
2407  virtual bool SetStatistics( bool bApproxStats,
2408  double dfMin, double dfMax,
2409  double dfMean, double dfStdDev,
2410  GUInt64 nValidCount );
2411 
2412  static std::string MassageName(const std::string& inputName);
2413 
2414  std::shared_ptr<GDALGroup> GetCacheRootGroup(bool bCanCreate,
2415  std::string& osCacheFilenameOut) const;
2417 
2418 public:
2419 
2420  GUInt64 GetTotalCopyCost() const;
2421 
2422  virtual bool CopyFrom(GDALDataset* poSrcDS,
2423  const GDALMDArray* poSrcArray,
2424  bool bStrict,
2425  GUInt64& nCurCost,
2426  const GUInt64 nTotalCost,
2427  GDALProgressFunc pfnProgress,
2428  void * pProgressData);
2429 
2431  virtual bool IsWritable() const = 0;
2432 
2441  virtual const std::string& GetFilename() const = 0;
2442 
2443  virtual CSLConstList GetStructuralInfo() const;
2444 
2445  virtual const std::string& GetUnit() const;
2446 
2447  virtual bool SetUnit(const std::string& osUnit);
2448 
2449  virtual bool SetSpatialRef(const OGRSpatialReference* poSRS);
2450 
2451  virtual std::shared_ptr<OGRSpatialReference> GetSpatialRef() const;
2452 
2453  virtual const void* GetRawNoDataValue() const;
2454 
2455  double GetNoDataValueAsDouble(bool* pbHasNoData = nullptr) const;
2456 
2457  virtual bool SetRawNoDataValue(const void* pRawNoData);
2458 
2459  bool SetNoDataValue(double dfNoData);
2460 
2461  virtual double GetOffset(bool* pbHasOffset = nullptr, GDALDataType* peStorageType = nullptr) const;
2462 
2463  virtual double GetScale(bool* pbHasScale = nullptr, GDALDataType* peStorageType = nullptr) const;
2464 
2465  virtual bool SetOffset(double dfOffset, GDALDataType eStorageType = GDT_Unknown);
2466 
2467  virtual bool SetScale(double dfScale, GDALDataType eStorageType = GDT_Unknown);
2468 
2469  std::shared_ptr<GDALMDArray> GetView(const std::string& viewExpr) const;
2470 
2471  std::shared_ptr<GDALMDArray> operator[](const std::string& fieldName) const;
2472 
2482  // sphinx 4.1.0 / breathe 4.30.0 don't like typename...
2484  template<typename... GUInt64VarArg>
2486  // cppcheck-suppress functionStatic
2487  std::shared_ptr<GDALMDArray> at(GUInt64 idx, GUInt64VarArg... tail) const
2488  {
2489  std::vector<GUInt64> indices;
2490  indices.push_back(idx);
2491  return atInternal(indices, tail...);
2492  }
2493 
2494  virtual std::shared_ptr<GDALMDArray> Transpose(const std::vector<int>& anMapNewAxisToOldAxis) const;
2495 
2496  std::shared_ptr<GDALMDArray> GetUnscaled() const;
2497 
2498  virtual std::shared_ptr<GDALMDArray> GetMask(CSLConstList papszOptions) const;
2499 
2500  std::shared_ptr<GDALMDArray>
2501  GetResampled( const std::vector<std::shared_ptr<GDALDimension>>& apoNewDims,
2502  GDALRIOResampleAlg resampleAlg,
2503  const OGRSpatialReference* poTargetSRS,
2504  CSLConstList papszOptions ) const;
2505 
2506  virtual GDALDataset* AsClassicDataset(size_t iXDim, size_t iYDim) const;
2507 
2508  virtual CPLErr GetStatistics( bool bApproxOK, bool bForce,
2509  double *pdfMin, double *pdfMax,
2510  double *pdfMean, double *padfStdDev,
2511  GUInt64* pnValidCount,
2512  GDALProgressFunc pfnProgress, void *pProgressData );
2513 
2514  virtual bool ComputeStatistics( bool bApproxOK,
2515  double *pdfMin, double *pdfMax,
2516  double *pdfMean, double *pdfStdDev,
2517  GUInt64* pnValidCount,
2518  GDALProgressFunc, void *pProgressData );
2519 
2520  virtual void ClearStatistics();
2521 
2522  virtual std::vector<std::shared_ptr<GDALMDArray>> GetCoordinateVariables() const;
2523 
2524  bool AdviseRead(const GUInt64* arrayStartIdx,
2525  const size_t* count,
2526  CSLConstList papszOptions = nullptr) const;
2527 
2528  bool IsRegularlySpaced(double& dfStart, double& dfIncrement) const;
2529 
2530  bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
2531  double adfGeoTransform[6]) const;
2532 
2533  bool Cache( CSLConstList papszOptions = nullptr ) const;
2534 
2535  bool Read(const GUInt64* arrayStartIdx, // array of size GetDimensionCount()
2536  const size_t* count, // array of size GetDimensionCount()
2537  const GInt64* arrayStep, // step in elements
2538  const GPtrDiff_t* bufferStride, // stride in elements
2539  const GDALExtendedDataType& bufferDataType,
2540  void* pDstBuffer,
2541  const void* pDstBufferAllocStart = nullptr,
2542  size_t nDstBufferAllocSize = 0) const override final;
2543 
2545  static constexpr GUInt64 COPY_COST = 1000;
2546 
2547  bool CopyFromAllExceptValues(const GDALMDArray* poSrcArray,
2548  bool bStrict,
2549  GUInt64& nCurCost,
2550  const GUInt64 nTotalCost,
2551  GDALProgressFunc pfnProgress,
2552  void * pProgressData);
2553  struct Range
2554  {
2555  GUInt64 m_nStartIdx;
2556  GInt64 m_nIncr;
2557  Range(GUInt64 nStartIdx = 0, GInt64 nIncr = 0):
2558  m_nStartIdx(nStartIdx), m_nIncr(nIncr) {}
2559  };
2560 
2561  struct ViewSpec
2562  {
2563  std::string m_osFieldName{};
2564 
2565  // or
2566 
2567  std::vector<size_t> m_mapDimIdxToParentDimIdx{}; // of size m_dims.size()
2568  std::vector<Range> m_parentRanges{} ; // of size m_poParent->GetDimensionCount()
2569  };
2570 
2571  virtual std::shared_ptr<GDALMDArray> GetView(const std::string& viewExpr,
2572  bool bRenameDimensions,
2573  std::vector<ViewSpec>& viewSpecs) const;
2575 };
2576 
2578 bool GDALMDRasterIOFromBand(GDALRasterBand* poBand,
2579  GDALRWFlag eRWFlag,
2580  size_t iDimX,
2581  size_t iDimY,
2582  const GUInt64* arrayStartIdx,
2583  const size_t* count,
2584  const GInt64* arrayStep,
2585  const GPtrDiff_t* bufferStride,
2586  const GDALExtendedDataType& bufferDataType,
2587  void* pBuffer);
2589 
2590 /************************************************************************/
2591 /* GDALMDArrayRegularlySpaced */
2592 /************************************************************************/
2593 
2595 class CPL_DLL GDALMDArrayRegularlySpaced: public GDALMDArray
2596 {
2597  double m_dfStart;
2598  double m_dfIncrement;
2599  double m_dfOffsetInIncrement;
2601  std::vector<std::shared_ptr<GDALDimension>> m_dims;
2602  std::vector<std::shared_ptr<GDALAttribute>> m_attributes{};
2603  std::string m_osEmptyFilename{};
2604 
2605 protected:
2606 
2607  bool IRead(const GUInt64* ,
2608  const size_t* ,
2609  const GInt64* ,
2610  const GPtrDiff_t* ,
2611  const GDALExtendedDataType& bufferDataType,
2612  void* pDstBuffer) const override;
2613 
2614 public:
2615  GDALMDArrayRegularlySpaced(
2616  const std::string& osParentName,
2617  const std::string& osName,
2618  const std::shared_ptr<GDALDimension>& poDim,
2619  double dfStart, double dfIncrement,
2620  double dfOffsetInIncrement);
2621 
2622  bool IsWritable() const override { return false; }
2623 
2624  const std::string& GetFilename() const override { return m_osEmptyFilename; }
2625 
2626  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override;
2627 
2628  const GDALExtendedDataType &GetDataType() const override;
2629 
2630  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
2631 
2632  void AddAttribute(const std::shared_ptr<GDALAttribute>& poAttr);
2633 };
2635 
2636 /* ******************************************************************** */
2637 /* GDALDimension */
2638 /* ******************************************************************** */
2639 
2651 class CPL_DLL GDALDimension
2652 {
2653 public:
2655  GDALDimension(const std::string& osParentName,
2656  const std::string& osName,
2657  const std::string& osType,
2658  const std::string& osDirection,
2659  GUInt64 nSize);
2661 
2662  virtual ~GDALDimension();
2663 
2668  const std::string& GetName() const { return m_osName; }
2669 
2674  const std::string& GetFullName() const { return m_osFullName; }
2675 
2684  const std::string& GetType() const { return m_osType; }
2685 
2694  const std::string& GetDirection() const { return m_osDirection; }
2695 
2700  GUInt64 GetSize() const { return m_nSize; }
2701 
2702  virtual std::shared_ptr<GDALMDArray> GetIndexingVariable() const;
2703 
2704  virtual bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable);
2705 
2706 protected:
2708  std::string m_osName;
2709  std::string m_osFullName;
2710  std::string m_osType;
2711  std::string m_osDirection;
2712  GUInt64 m_nSize;
2714 };
2715 
2716 
2717 /************************************************************************/
2718 /* GDALDimensionWeakIndexingVar() */
2719 /************************************************************************/
2720 
2722 class CPL_DLL GDALDimensionWeakIndexingVar: public GDALDimension
2723 {
2724  std::weak_ptr<GDALMDArray> m_poIndexingVariable{};
2725 
2726 public:
2727  GDALDimensionWeakIndexingVar(const std::string& osParentName,
2728  const std::string& osName,
2729  const std::string& osType,
2730  const std::string& osDirection,
2731  GUInt64 nSize);
2732 
2733  std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
2734 
2735  bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable) override;
2736 };
2738 
2739 /************************************************************************/
2740 /* GDALAntiRecursionGuard */
2741 /************************************************************************/
2742 
2744 struct GDALAntiRecursionStruct;
2745 class GDALAntiRecursionGuard
2746 {
2747  GDALAntiRecursionStruct* m_psAntiRecursionStruct;
2748  std::string m_osIdentifier;
2749  int m_nDepth;
2750 
2751  GDALAntiRecursionGuard(const GDALAntiRecursionGuard&) = delete;
2752  GDALAntiRecursionGuard& operator= (const GDALAntiRecursionGuard&) = delete;
2753 
2754 public:
2755  explicit GDALAntiRecursionGuard(const std::string& osIdentifier);
2756  GDALAntiRecursionGuard(const GDALAntiRecursionGuard& other, const std::string& osIdentifier);
2757  ~GDALAntiRecursionGuard();
2758  int GetCallDepth() const { return m_nDepth; }
2759 };
2761 
2762 
2763 /* ==================================================================== */
2764 /* An assortment of overview related stuff. */
2765 /* ==================================================================== */
2766 
2768 /* Only exported for drivers as plugin. Signature may change */
2769 CPLErr CPL_DLL
2770 GDALRegenerateOverviewsMultiBand(int nBands, GDALRasterBand** papoSrcBands,
2771  int nOverviews,
2772  GDALRasterBand*** papapoOverviewBands,
2773  const char * pszResampling,
2774  GDALProgressFunc pfnProgress, void * pProgressData );
2775 
2776 typedef CPLErr (*GDALResampleFunction)
2777  ( double dfXRatioDstToSrc,
2778  double dfYRatioDstToSrc,
2779  double dfSrcXDelta,
2780  double dfSrcYDelta,
2781  GDALDataType eWrkDataType,
2782  const void * pChunk,
2783  const GByte * pabyChunkNodataMask,
2784  int nChunkXOff, int nChunkXSize,
2785  int nChunkYOff, int nChunkYSize,
2786  int nDstXOff, int nDstXOff2,
2787  int nDstYOff, int nDstYOff2,
2788  GDALRasterBand * poOverview,
2789  void** ppDstBuffer,
2790  GDALDataType* peDstBufferDataType,
2791  const char * pszResampling,
2792  int bHasNoData, float fNoDataValue,
2793  GDALColorTable* poColorTable,
2794  GDALDataType eSrcDataType,
2795  bool bPropagateNoData );
2796 
2797 GDALResampleFunction GDALGetResampleFunction(const char* pszResampling,
2798  int* pnRadius);
2799 
2800 GDALDataType GDALGetOvrWorkDataType(const char* pszResampling,
2801  GDALDataType eSrcDataType);
2802 
2804 
2805 CPLErr CPL_DLL
2806 HFAAuxBuildOverviews( const char *pszOvrFilename, GDALDataset *poParentDS,
2807  GDALDataset **ppoDS,
2808  int nBands, int *panBandList,
2809  int nNewOverviews, int *panNewOverviewList,
2810  const char *pszResampling,
2811  GDALProgressFunc pfnProgress,
2812  void *pProgressData );
2813 
2814 CPLErr CPL_DLL
2815 GTIFFBuildOverviews( const char * pszFilename,
2816  int nBands, GDALRasterBand **papoBandList,
2817  int nOverviews, int * panOverviewList,
2818  const char * pszResampling,
2819  GDALProgressFunc pfnProgress, void * pProgressData );
2820 
2821 int CPL_DLL GDALBandGetBestOverviewLevel(GDALRasterBand* poBand,
2822  int &nXOff, int &nYOff,
2823  int &nXSize, int &nYSize,
2824  int nBufXSize, int nBufYSize) CPL_WARN_DEPRECATED("Use GDALBandGetBestOverviewLevel2 instead");
2825 int CPL_DLL GDALBandGetBestOverviewLevel2(GDALRasterBand* poBand,
2826  int &nXOff, int &nYOff,
2827  int &nXSize, int &nYSize,
2828  int nBufXSize, int nBufYSize,
2829  GDALRasterIOExtraArg* psExtraArg);
2830 
2831 int CPL_DLL GDALOvLevelAdjust( int nOvLevel, int nXSize ) CPL_WARN_DEPRECATED("Use GDALOvLevelAdjust2 instead");
2832 int CPL_DLL GDALOvLevelAdjust2( int nOvLevel, int nXSize, int nYSize );
2833 int CPL_DLL GDALComputeOvFactor( int nOvrXSize, int nRasterXSize,
2834  int nOvrYSize, int nRasterYSize );
2835 
2836 GDALDataset CPL_DLL *
2837 GDALFindAssociatedAuxFile( const char *pszBasefile, GDALAccess eAccess,
2838  GDALDataset *poDependentDS );
2839 
2840 /* ==================================================================== */
2841 /* Infrastructure to check that dataset characteristics are valid */
2842 /* ==================================================================== */
2843 
2844 int CPL_DLL GDALCheckDatasetDimensions( int nXSize, int nYSize );
2845 int CPL_DLL GDALCheckBandCount( int nBands, int bIsZeroAllowed );
2846 
2847 /* Internal use only */
2848 
2849 /* CPL_DLL exported, but only for in-tree drivers that can be built as plugins */
2850 int CPL_DLL GDALReadWorldFile2( const char *pszBaseFilename, const char *pszExtension,
2851  double *padfGeoTransform, char** papszSiblingFiles,
2852  char** ppszWorldFileNameOut);
2853 int GDALReadTabFile2( const char * pszBaseFilename,
2854  double *padfGeoTransform, char **ppszWKT,
2855  int *pnGCPCount, GDAL_GCP **ppasGCPs,
2856  char** papszSiblingFiles, char** ppszTabFileNameOut );
2857 
2858 void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg* psDestArg,
2859  GDALRasterIOExtraArg* psSrcArg);
2860 
2861 CPL_C_END
2862 
2863 void GDALNullifyOpenDatasetsList();
2864 CPLMutex** GDALGetphDMMutex();
2865 CPLMutex** GDALGetphDLMutex();
2866 void GDALNullifyProxyPoolSingleton();
2867 void GDALSetResponsiblePIDForCurrentThread(GIntBig responsiblePID);
2868 GIntBig GDALGetResponsiblePIDForCurrentThread();
2869 
2870 CPLString GDALFindAssociatedFile( const char *pszBasename, const char *pszExt,
2871  CSLConstList papszSiblingFiles, int nFlags );
2872 
2873 CPLErr CPL_DLL EXIFExtractMetadata(char**& papszMetadata,
2874  void *fpL, int nOffset,
2875  int bSwabflag, int nTIFFHEADER,
2876  int& nExifOffset, int& nInterOffset, int& nGPSOffset);
2877 
2878 int GDALValidateOpenOptions( GDALDriverH hDriver,
2879  const char* const* papszOptionOptions);
2880 int GDALValidateOptions( const char* pszOptionList,
2881  const char* const* papszOptionsToValidate,
2882  const char* pszErrorMessageOptionType,
2883  const char* pszErrorMessageContainerName);
2884 
2885 GDALRIOResampleAlg GDALRasterIOGetResampleAlg(const char* pszResampling);
2886 const char* GDALRasterIOGetResampleAlg(GDALRIOResampleAlg eResampleAlg);
2887 
2888 void GDALRasterIOExtraArgSetResampleAlg(GDALRasterIOExtraArg* psExtraArg,
2889  int nXSize, int nYSize,
2890  int nBufXSize, int nBufYSize);
2891 
2892 
2893 GDALDataset* GDALCreateOverviewDataset(GDALDataset* poDS, int nOvrLevel,
2894  int bThisLevelOnly);
2895 
2896 // Should cover particular cases of #3573, #4183, #4506, #6578
2897 // Behavior is undefined if fVal1 or fVal2 are NaN (should be tested before
2898 // calling this function)
2899 template<class T> inline bool ARE_REAL_EQUAL(T fVal1, T fVal2, int ulp = 2)
2900 {
2901  return fVal1 == fVal2 || /* Should cover infinity */
2902  std::abs(fVal1 - fVal2) < std::numeric_limits<float>::epsilon() * std::abs(fVal1+fVal2) * ulp;
2903 }
2904 
2905 double GDALAdjustNoDataCloseToFloatMax(double dfVal);
2906 
2907 #define DIV_ROUND_UP(a, b) ( ((a) % (b)) == 0 ? ((a) / (b)) : (((a) / (b)) + 1) )
2908 
2909 // Number of data samples that will be used to compute approximate statistics
2910 // (minimum value, maximum value, etc.)
2911 #define GDALSTAT_APPROX_NUMSAMPLES 2500
2912 
2913 void GDALSerializeGCPListToXML( CPLXMLNode* psParentNode,
2914  GDAL_GCP* pasGCPList,
2915  int nGCPCount,
2916  const OGRSpatialReference* poGCP_SRS );
2917 void GDALDeserializeGCPListFromXML( CPLXMLNode* psGCPList,
2918  GDAL_GCP** ppasGCPList,
2919  int* pnGCPCount,
2920  OGRSpatialReference** ppoGCP_SRS );
2921 
2922 void GDALSerializeOpenOptionsToXML( CPLXMLNode* psParentNode, char** papszOpenOptions);
2923 char** GDALDeserializeOpenOptionsFromXML( CPLXMLNode* psParentNode );
2924 
2925 int GDALCanFileAcceptSidecarFile(const char* pszFilename);
2926 
2927 bool GDALCanReliablyUseSiblingFileList(const char* pszFilename);
2928 
2929 bool CPL_DLL GDALIsDriverDeprecatedForGDAL35StillEnabled(const char* pszDriverName, const char* pszExtraMsg = "");
2930 
2931 typedef enum
2932 {
2933  GSF_UNSIGNED_INT,
2934  GSF_SIGNED_INT,
2935  GSF_FLOATING_POINT,
2936 } GDALBufferSampleFormat;
2937 
2938 bool CPL_DLL GDALBufferHasOnlyNoData(const void* pBuffer,
2939  double dfNoDataValue,
2940  size_t nWidth, size_t nHeight,
2941  size_t nLineStride,
2942  size_t nComponents,
2943  int nBitsPerSample,
2944  GDALBufferSampleFormat nSampleFormat);
2945 
2947 
2948 #endif /* ndef GDAL_PRIV_H_INCLUDED */
const GByte & operator[](size_t idx) const
Return byte at specified index.
Definition: gdal_priv.h:2231
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:47
Layer iterator.
Definition: gdal_priv.h:718
size_t size() const
Return the size in bytes of the raw result.
Definition: gdal_priv.h:2235
std::shared_ptr< GDALMDArray > at(GUInt64 idx, GUInt64VarArg... tail) const
Return a view of the array using integer indexing.
Definition: gdal_priv.h:2487
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition: ogr_feature.h:796
GDALExtendedDataTypeClass GetClass() const
Return type class.
Definition: gdal_priv.h:1835
int GetYSize() const
Return height.
Definition: gdal_priv.h:1739
GDALDataType
Definition: gdal.h:62
Definition of a field domain.
Definition: ogr_feature.h:835
Identify could not determine if the file is recognized or not by the probed driver.
Definition: gdal_priv.h:1466
Document node structure.
Definition: cpl_minixml.h:69
Standard C Covers.
virtual GDALRasterBand * GetMaskBand()
Return the mask band associated with the band.
Definition: gdalrasterband.cpp:5957
size_t GetMaxStringLength() const
Return the maximum length of a string in bytes.
Definition: gdal_priv.h:1869
Definitions for CPL mini XML Parser/Serializer.
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition: gdal_priv.h:1348
Definition: gdal.h:64
Definition: gdal.h:232
GDALDataset * GetGDALDataset()
Return dataset.
Definition: gdal_priv.h:1723
int GetBandCount() const
Return band count.
Definition: gdal_priv.h:1759
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:329
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:1855
Object returned by GetFeatures() iterators.
Definition: gdal_priv.h:668
const char *const * papszAllowedDrivers
Allowed drivers (NULL for all)
Definition: gdal_priv.h:303
int GetXOffset() const
Return x offset.
Definition: gdal_priv.h:1727
GUInt64 GetSize() const
Return the size, that is the number of values along the dimension.
Definition: gdal_priv.h:2700
GDALExtendedDataTypeSubType
Enumeration giving the subtype of a GDALExtendedDataType.
Definition: gdal.h:303
GDALDataType GetNumericDataType() const
Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)
Definition: gdal_priv.h:1841
int * GetBandMap()
Return band map.
Definition: gdal_priv.h:1763
int DropLock(void)
Decrement the lock count.
Definition: gdal_priv.h:950
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup...
Definition: gdal_priv.h:1979
FILE VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition: cpl_vsi.h:156
char ** GetOpenOptions()
Return open options.
Definition: gdal_priv.h:610
virtual bool IsWritable() const =0
Return whether an array is writable.
void pointer
pointer
Definition: gdal_priv.h:727
GByte * pabyHeader
Buffer with first bytes of the file.
Definition: gdal_priv.h:300
size_t GetSize() const
Return data type size in bytes.
Definition: gdal_priv.h:1863
int GetLineSpace() const
Return line spacing.
Definition: gdal_priv.h:1771
GDALAccess eAccess
Access flag.
Definition: gdal_priv.h:285
const std::string & GetName() const
Return type name.
Definition: gdal_priv.h:1829
GDALDataType GetDataType() const
Return the data type.
Definition: gdal_priv.h:958
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:130
VSILFILE * fpL
Pointer to the file.
Definition: gdal_priv.h:295
int GetBufferYSize() const
Return buffer height.
Definition: gdal_priv.h:1751
const std::string & GetName() const
Return the name of the group.
Definition: gdal_priv.h:2000
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition: gdal_priv.h:1354
virtual bool Read(const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep, const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType, void *pDstBuffer, const void *pDstBufferAllocStart=nullptr, size_t nDstBufferAllocSize=0) const
Read part or totality of a multidimensional array or attribute.
Definition: gdalmultidim.cpp:1724
int GetBandSpace() const
Return band spacing.
Definition: gdal_priv.h:1775
GDALRWFlag
Definition: gdal.h:121
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:268
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
char * pszFilename
Filename.
Definition: gdal_priv.h:280
Color tuple.
Definition: gdal.h:1286
int nOpenFlags
Open flags.
Definition: gdal_priv.h:287
A single raster block in the block cache.
Definition: gdal_priv.h:909
virtual int GetMaskFlags()
Return the status flags of the mask band associated with the band.
Definition: gdalrasterband.cpp:6222
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:271
int AddLock(void)
Increment the lock count.
Definition: gdal_priv.h:948
Convenient string class based on std::string.
Definition: cpl_string.h:332
Definition: gdal.h:63
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:869
Class modeling an attribute that has a name, a value and a type, and is typically used to describe a ...
Definition: gdal_priv.h:2257
virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev, GDALProgressFunc, void *pProgressData)
Compute image statistics.
Definition: gdalrasterband.cpp:4927
unknown type, non-standard
Definition: ogr_core.h:347
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:62
const std::string & GetFullName() const
Return the full name of the group.
Definition: gdal_priv.h:2006
const GDALExtendedDataType & GetType() const
Return the data type of the component.
Definition: gdal_priv.h:1931
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Read a block of data.
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition: gdal_priv.h:2651
GDALExtendedDataTypeSubType GetSubType() const
Return subtype.
Definition: gdal_priv.h:1849
CPLErr BuildOverviews(const char *, int, int *, int, int *, GDALProgressFunc, void *)
Build raster overview(s)
Definition: gdaldataset.cpp:1980
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition: gdalmultidim.cpp:8033
Various convenience functions for working with strings and string lists.
virtual const GDALExtendedDataType & GetDataType() const =0
Return the data type of an attribute/array.
virtual std::vector< std::shared_ptr< GDALAttribute > > GetAttributes(CSLConstList papszOptions=nullptr) const
Return the list of attributes contained in a GDALMDArray or GDALGroup.
Definition: gdalmultidim.cpp:223
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:286
int bIsDirectory
Whether the file is a directory.
Definition: gdal_priv.h:292
static GDALColorTableH ToHandle(GDALColorTable *poCT)
Convert a GDALColorTable* to a GDALRasterBandH.
Definition: gdal_priv.h:1050
int GetDirty() const
Return the dirty flag.
Definition: gdal_priv.h:978
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:265
int GetXOff() const
Return the x offset of the top-left corner of the block.
Definition: gdal_priv.h:962
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:282
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:345
static GDALDriverH ToHandle(GDALDriver *poDriver)
Convert a GDALDriver* to a GDALDriverH.
Definition: gdal_priv.h:1619
Public (C callable) GDAL entry points.
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
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
GDALAsyncStatusType
status of the asynchronous stream
Definition: gdal.h:102
const std::string & GetFullName() const
Return the full name.
Definition: gdal_priv.h:2674
int GetPixelSpace() const
Return pixel spacing.
Definition: gdal_priv.h:1767
virtual const std::vector< std::shared_ptr< GDALDimension > > & GetDimensions() const =0
Return the dimensions of an attribute/array.
GPtrDiff_t GetBlockSize() const
Return the block size in bytes.
Definition: gdal_priv.h:986
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:326
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition: gdalmajorobject.cpp:292
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
GDALExtendedDataTypeClass
Enumeration giving the class of a GDALExtendedDataType.
Definition: gdal.h:291
void * GetBuffer()
Return buffer.
Definition: gdal_priv.h:1743
GDALRasterBand * GetBand()
Accessor to source GDALRasterBand object.
Definition: gdal_priv.h:994
Class for dataset open functions.
Definition: gdal_priv.h:268
GDALAccess GetAccess() const
Return access mode.
Definition: gdal_priv.h:600
Class used to represent potentially complex data types.
Definition: gdal_priv.h:1805
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
const std::string & GetDirection() const
Return the axis direction.
Definition: gdal_priv.h:2694
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:441
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition: gdal_priv.h:1625
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition: gdal.h:160
Identify determined the file is recognized by the probed driver.
Definition: gdal_priv.h:1470
const std::string & GetType() const
Return the axis type.
Definition: gdal_priv.h:2684
static GDALMajorObjectH ToHandle(GDALMajorObject *poMajorObject)
Convert a GDALMajorObject* to a GDALMajorObjectH.
Definition: gdal_priv.h:171
const std::string & GetName() const
Return the name of an array or attribute.
Definition: gdal_priv.h:2126
GDALPaletteInterp
Definition: gdal.h:229
Core portability services for cross-platform OGR code.
int bStatOK
Whether stat()&#39;ing the file was successful.
Definition: gdal_priv.h:290
int nHeaderBytes
Number of bytes in pabyHeader.
Definition: gdal_priv.h:298
Class returned by GetBands() that act as a container for raster bands.
Definition: gdal_priv.h:475
virtual int CloseDependentDatasets()
Drop references to any other datasets referenced by this dataset.
Definition: gdaldataset.cpp:4144
Store the raw result of an attribute value, which might contain dynamically allocated structures (lik...
Definition: gdal_priv.h:2204
void * GetDataRef(void)
Return the data buffer.
Definition: gdal_priv.h:982
virtual CPLErr CreateMaskBand(int nFlagsIn)
Adds a mask band to the dataset.
Definition: gdaldataset.cpp:3147
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:247
int CPLErrorNum
Error number.
Definition: cpl_error.h:94
Various convenience functions for CPL.
std::unique_ptr< GDALDataset, GDALDatasetUniquePtrDeleter > GDALDatasetUniquePtr
Unique pointer type for GDALDataset.
Definition: gdal_priv.h:899
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:157
int GetXSize() const
Return width.
Definition: gdal_priv.h:1735
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition: gdal_priv.h:2081
void * GDALDriverH
Opaque type used for the C bindings of the C++ GDALDriver class.
Definition: gdal.h:274
int GetXSize() const
Return the width of the block.
Definition: gdal_priv.h:970
void GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:3757
static GDALDatasetH ToHandle(GDALDataset *poDS)
Convert a GDALDataset* to a GDALDatasetH.
Definition: gdal_priv.h:643
void * GDALMajorObjectH
Opaque type used for the C bindings of the C++ GDALMajorObject class.
Definition: gdal.h:265
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition: gdalmultidim.cpp:8054
Definition: gdal.h:72
char ** papszOpenOptions
Open options.
Definition: gdal_priv.h:282
Object with metadata.
Definition: gdal_priv.h:135
int GetYSize() const
Return the height of the block.
Definition: gdal_priv.h:974
Class returned by GetLayers() that acts as a range of layers.
Definition: gdal_priv.h:705
static GDALDataset * FromHandle(GDALDatasetH hDS)
Convert a GDALDatasetH to a GDALDataset*.
Definition: gdal_priv.h:649
None.
Definition: gdal.h:305
std::input_iterator_tag iterator_category
iterator_category
Definition: gdal_priv.h:728
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:70
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140
const std::string & GetName() const
Return the name.
Definition: gdal_priv.h:1919
int GetYOffset() const
Return y offset.
Definition: gdal_priv.h:1731
A single raster band (or channel).
Definition: gdal_priv.h:1133
GDALAccess
Definition: gdal.h:115
const GByte * data() const
Return pointer to the start of data.
Definition: gdal_priv.h:2233
Simple feature classes.
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:370
This class represents a style table.
Definition: ogr_featurestyle.h:84
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:339
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:331
GDALDataType GetBufferType() const
Return buffer data type.
Definition: gdal_priv.h:1755
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:244
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition: gdal.h:277
static GDALExtendedDataType CreateString(size_t nMaxStringLength=0, GDALExtendedDataTypeSubType eSubType=GEDTST_NONE)
Return a new GDALExtendedDataType of class GEDTC_STRING.
Definition: gdalmultidim.cpp:7780
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
Class for managing the registration of file format drivers.
Definition: gdal_priv.h:1643
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:287
#define CPL_NULL_TERMINATED
Null terminated variadic.
Definition: cpl_port.h:859
int GetYOff() const
Return the y offset of the top-left corner of the block.
Definition: gdal_priv.h:966
CPLString & toupper(void)
Convert to upper case in place.
Definition: cplstring.cpp:316
Interface used to get a single GDALAttribute or a set of GDALAttribute.
Definition: gdal_priv.h:1948
GDALIdentifyEnum
Enumeration used by GDALDriver::pfnIdentify().
Definition: gdal_priv.h:1463
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:318
GDALColorInterp
Definition: gdal.h:203
int GDALGetDataTypeSizeBytes(GDALDataType)
Get data type size in bytes.
Definition: gdal_misc.cpp:308
Class modeling a multi-dimensional array.
Definition: gdal_priv.h:2375
virtual CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain="")
Set single metadata item.
Definition: gdalmajorobject.cpp:388
Numeric value.
Definition: gdal.h:293
Class returned by GetFeatures() that act as a container for vector features.
Definition: gdal_priv.h:768
static GDALMajorObject * FromHandle(GDALMajorObjectH hMajorObject)
Convert a GDALMajorObjectH to a GDALMajorObject*.
Definition: gdal_priv.h:177
const std::string & GetName() const
Return the name.
Definition: gdal_priv.h:2668
Identify determined the file is not recognized by the probed driver.
Definition: gdal_priv.h:1468
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:292
size_t GetOffset() const
Return the offset (in bytes) of the component in the compound data type.
Definition: gdal_priv.h:1925
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:263
Class for a component of a compound extended data type.
Definition: gdal_priv.h:1906
static GDALExtendedDataType Create(GDALDataType eType)
Return a new GDALExtendedDataType of class GEDTC_NUMERIC.
Definition: gdalmultidim.cpp:7716
void difference_type
difference_type
Definition: gdal_priv.h:726
Definition: gdal.h:116
Format specific driver.
Definition: gdal_priv.h:1488
A color table / palette.
Definition: gdal_priv.h:1024
const std::string & GetFullName() const
Return the name of an array or attribute.
Definition: gdal_priv.h:2132
Ground Control Point.
Definition: gdal.h:710
CPLErr
Error category.
Definition: cpl_error.h:52
GDALDriverManager * GetGDALDriverManager(void)
Fetch the global GDAL driver manager.
Definition: gdaldrivermanager.cpp:99
#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
int GetBufferXSize() const
Return buffer width.
Definition: gdal_priv.h:1747
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:894
Class used as a session object for asynchronous requests.
Definition: gdal_priv.h:1693
static GDALColorTable * FromHandle(GDALColorTableH hCT)
Convert a GDALColorTableH to a GDALColorTable*.
Definition: gdal_priv.h:1056