GDAL
gdal_dataset.h
1/******************************************************************************
2 *
3 * Name: gdal_dataset.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALDataset class
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDALDATASET_H_INCLUDED
16#define GDALDATASET_H_INCLUDED
17
18#include "cpl_port.h"
19#include "gdal_fwd.h"
20#include "gdal.h"
21#include "gdal_geotransform.h"
22#include "gdal_majorobject.h"
23#include "gdal_defaultoverviews.h"
24#include "ogr_core.h" // for OGRErr
25#include "ogr_feature.h" // for OGRFeatureUniquePtr
26
27#include <cstddef>
28#include <iterator>
29#include <memory>
30#include <vector>
31
32/* ******************************************************************** */
33/* GDALDataset */
34/* ******************************************************************** */
35
36class OGRGeometry;
37class OGRLayer;
39class OGRStyleTable;
40class swq_select;
41class swq_select_parse_options;
42class GDALAsyncReader;
43class GDALDriver;
44class GDALGroup;
45class GDALMDArray;
46class GDALRasterBand;
48class GDALOpenInfo;
49
51typedef struct GDALSQLParseInfo GDALSQLParseInfo;
53
55#if !defined(OPTIONAL_OUTSIDE_GDAL)
56#if defined(GDAL_COMPILATION)
57#define OPTIONAL_OUTSIDE_GDAL(val)
58#else
59#define OPTIONAL_OUTSIDE_GDAL(val) = val
60#endif
61#endif
63
65// This macro can be defined to check that GDALDataset::IRasterIO()
66// implementations do not alter the passed panBandList. It is not defined
67// by default (and should not!), hence int* is used.
68#if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
69#define BANDMAP_TYPE const int *
70#else
71#define BANDMAP_TYPE int *
72#endif
74
76class CPL_DLL GDALDataset : public GDALMajorObject
77{
78 friend GDALDatasetH CPL_STDCALL
79 GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags,
80 const char *const *papszAllowedDrivers,
81 const char *const *papszOpenOptions,
82 const char *const *papszSiblingFiles);
83 friend CPLErr CPL_STDCALL GDALClose(GDALDatasetH hDS);
84
85 friend class GDALDriver;
86 friend class GDALDefaultOverviews;
87 friend class GDALProxyDataset;
88 friend class GDALDriverManager;
89
90 CPL_INTERNAL void AddToDatasetOpenList();
91
92 CPL_INTERNAL void UnregisterFromSharedDataset();
93
94 CPL_INTERNAL static void ReportErrorV(const char *pszDSName,
95 CPLErr eErrClass, CPLErrorNum err_no,
96 const char *fmt, va_list args);
97
98 protected:
100 GDALDriver *poDriver = nullptr;
101 GDALAccess eAccess = GA_ReadOnly;
102
103 // Stored raster information.
104 int nRasterXSize = 512;
105 int nRasterYSize = 512;
106 int nBands = 0;
107 GDALRasterBand **papoBands = nullptr;
108
109 static constexpr int OPEN_FLAGS_CLOSED = -1;
110 int nOpenFlags =
111 0; // set to OPEN_FLAGS_CLOSED after Close() has been called
112
113 int nRefCount = 1;
114 bool bForceCachedIO = false;
115 bool bShared = false;
116 bool bIsInternal = true;
117 bool bSuppressOnClose = false;
118
119 mutable std::map<std::string, std::unique_ptr<OGRFieldDomain>>
120 m_oMapFieldDomains{};
121
122 GDALDataset(void);
123 explicit GDALDataset(int bForceCachedIO);
124
125 void RasterInitialize(int, int);
126 void SetBand(int nNewBand, GDALRasterBand *poBand);
127 void SetBand(int nNewBand, std::unique_ptr<GDALRasterBand> poBand);
128
129 GDALDefaultOverviews oOvManager{};
130
131 virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
132 const int *panOverviewList, int nListBands,
133 const int *panBandList,
134 GDALProgressFunc pfnProgress,
135 void *pProgressData,
136 CSLConstList papszOptions);
137
138 virtual CPLErr
139 IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
140 void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
141 int nBandCount, BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
142 GSpacing nLineSpace, GSpacing nBandSpace,
144
145 /* This method should only be be overloaded by GDALProxyDataset */
146 virtual CPLErr
147 BlockBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
148 int nYSize, void *pData, int nBufXSize, int nBufYSize,
149 GDALDataType eBufType, int nBandCount,
150 const int *panBandMap, GSpacing nPixelSpace,
151 GSpacing nLineSpace, GSpacing nBandSpace,
153 CPLErr BlockBasedFlushCache(bool bAtClosing);
154
155 CPLErr
156 BandBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
157 int nYSize, void *pData, int nBufXSize, int nBufYSize,
158 GDALDataType eBufType, int nBandCount,
159 const int *panBandMap, GSpacing nPixelSpace,
160 GSpacing nLineSpace, GSpacing nBandSpace,
162
163 CPLErr
164 RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
165 int nYSize, void *pData, int nBufXSize, int nBufYSize,
166 GDALDataType eBufType, int nBandCount,
167 const int *panBandMap, GSpacing nPixelSpace,
168 GSpacing nLineSpace, GSpacing nBandSpace,
170
171 CPLErr ValidateRasterIOOrAdviseReadParameters(
172 const char *pszCallingFunc, int *pbStopProcessingOnCENone, int nXOff,
173 int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize,
174 int nBandCount, const int *panBandMap);
175
176 CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
177 int nXSize, int nYSize, void *pData,
178 int nBufXSize, int nBufYSize,
179 GDALDataType eBufType, int nBandCount,
180 const int *panBandMap, GSpacing nPixelSpace,
181 GSpacing nLineSpace, GSpacing nBandSpace,
182 GDALRasterIOExtraArg *psExtraArg, int *pbTried);
183
184 void ShareLockWithParentDataset(GDALDataset *poParentDataset);
185
186 bool m_bCanBeReopened = false;
187
188 virtual bool CanBeCloned(int nScopeFlags, bool bCanShareState) const;
189
190 friend class GDALThreadSafeDataset;
191 friend class MEMDataset;
192 virtual std::unique_ptr<GDALDataset> Clone(int nScopeFlags,
193 bool bCanShareState) const;
194
196
197 void CleanupPostFileClosing();
198
199 virtual int CloseDependentDatasets();
201 int ValidateLayerCreationOptions(const char *const *papszLCO);
202
203 char **papszOpenOptions = nullptr;
204
205 friend class GDALRasterBand;
206
207 // The below methods related to read write mutex are fragile logic, and
208 // should not be used by out-of-tree code if possible.
209 int EnterReadWrite(GDALRWFlag eRWFlag);
210 void LeaveReadWrite();
211 void InitRWLock();
212
213 void TemporarilyDropReadWriteLock();
214 void ReacquireReadWriteLock();
215
216 void DisableReadWriteMutex();
217
218 int AcquireMutex();
219 void ReleaseMutex();
220
221 bool IsAllBands(int nBandCount, const int *panBandList) const;
223
224 public:
225 ~GDALDataset() override;
226
227 virtual CPLErr Close(GDALProgressFunc pfnProgress = nullptr,
228 void *pProgressData = nullptr);
229
230 virtual bool GetCloseReportsProgress() const;
231
232 virtual bool CanReopenWithCurrentDescription() const;
233
234 int GetRasterXSize() const;
235 int GetRasterYSize() const;
236 int GetRasterCount() const;
237 GDALRasterBand *GetRasterBand(int);
238 const GDALRasterBand *GetRasterBand(int) const;
239
246 virtual bool SetQueryLoggerFunc(GDALQueryLoggerFunc pfnQueryLoggerFuncIn,
247 void *poQueryLoggerArgIn);
248
251 class CPL_DLL Bands
252 {
253 private:
254 friend class GDALDataset;
255 GDALDataset *m_poSelf;
256
257 CPL_INTERNAL explicit Bands(GDALDataset *poSelf) : m_poSelf(poSelf)
258 {
259 }
260
261 class CPL_DLL Iterator
262 {
263 struct Private;
264 std::unique_ptr<Private> m_poPrivate;
265
266 public:
267 Iterator(GDALDataset *poDS, bool bStart);
268 Iterator(const Iterator &oOther); // declared but not defined.
269 // Needed for gcc 5.4 at least
270 Iterator(Iterator &&oOther) noexcept; // declared but not defined.
271 // Needed for gcc 5.4 at least
272 ~Iterator();
273 GDALRasterBand *operator*();
274 Iterator &operator++();
275 bool operator!=(const Iterator &it) const;
276 };
277
278 public:
279 const Iterator begin() const;
280
281 const Iterator end() const;
282
283 size_t size() const;
284
285 GDALRasterBand *operator[](int iBand);
286 GDALRasterBand *operator[](size_t iBand);
287 };
288
289 Bands GetBands();
290
293 class CPL_DLL ConstBands
294 {
295 private:
296 friend class GDALDataset;
297 const GDALDataset *const m_poSelf;
298
299 CPL_INTERNAL explicit ConstBands(const GDALDataset *poSelf)
300 : m_poSelf(poSelf)
301 {
302 }
303
304 class CPL_DLL Iterator
305 {
306 struct Private;
307 std::unique_ptr<Private> m_poPrivate;
308
309 public:
310 Iterator(const GDALDataset *poDS, bool bStart);
311 ~Iterator();
312 const GDALRasterBand *operator*() const;
313 Iterator &operator++();
314 bool operator!=(const Iterator &it) const;
315 };
316
317 public:
318 const Iterator begin() const;
319
320 const Iterator end() const;
321
322 size_t size() const;
323
324 const GDALRasterBand *operator[](int iBand) const;
325 const GDALRasterBand *operator[](size_t iBand) const;
326 };
327
328 ConstBands GetBands() const;
329
330 virtual CPLErr FlushCache(bool bAtClosing = false);
331 virtual CPLErr DropCache();
332
333 virtual GIntBig GetEstimatedRAMUsage();
334
335 virtual const OGRSpatialReference *GetSpatialRef() const;
336 virtual CPLErr SetSpatialRef(const OGRSpatialReference *poSRS);
337
338 virtual const OGRSpatialReference *GetSpatialRefRasterOnly() const;
339 virtual const OGRSpatialReference *GetSpatialRefVectorOnly() const;
340
341 // Compatibility layer
342 const char *GetProjectionRef(void) const;
343 CPLErr SetProjection(const char *pszProjection);
344
345 virtual CPLErr GetGeoTransform(GDALGeoTransform &gt) const;
346 virtual CPLErr SetGeoTransform(const GDALGeoTransform &gt);
347
348 CPLErr GetGeoTransform(double *padfGeoTransform) const
349#if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
350 CPL_WARN_DEPRECATED("Use GetGeoTransform(GDALGeoTransform&) instead")
351#endif
352 ;
353
354 CPLErr SetGeoTransform(const double *padfGeoTransform)
355#if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
356 CPL_WARN_DEPRECATED(
357 "Use SetGeoTransform(const GDALGeoTransform&) instead")
358#endif
359 ;
360
361 virtual CPLErr GetExtent(OGREnvelope *psExtent,
362 const OGRSpatialReference *poCRS = nullptr) const;
363 virtual CPLErr GetExtentWGS84LongLat(OGREnvelope *psExtent) const;
364
365 CPLErr GeolocationToPixelLine(
366 double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
367 double *pdfPixel, double *pdfLine,
368 CSLConstList papszTransformerOptions = nullptr) const;
369
370 virtual CPLErr AddBand(GDALDataType eType,
371 CSLConstList papszOptions = nullptr);
372
373 virtual void *GetInternalHandle(const char *pszHandleName);
374 virtual GDALDriver *GetDriver(void) const;
375 virtual char **GetFileList(void);
376
377 const char *GetDriverName() const;
378
379 virtual const OGRSpatialReference *GetGCPSpatialRef() const;
380 virtual int GetGCPCount();
381 virtual const GDAL_GCP *GetGCPs();
382 virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
383 const OGRSpatialReference *poGCP_SRS);
384
385 // Compatibility layer
386 const char *GetGCPProjection() const;
387 CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
388 const char *pszGCPProjection);
389
390 virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
391 int nBufXSize, int nBufYSize, GDALDataType eDT,
392 int nBandCount, int *panBandList,
393 CSLConstList papszOptions);
394
395 virtual CPLErr CreateMaskBand(int nFlagsIn);
396
397 virtual GDALAsyncReader *
398 BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf,
399 int nBufXSize, int nBufYSize, GDALDataType eBufType,
400 int nBandCount, int *panBandMap, int nPixelSpace,
401 int nLineSpace, int nBandSpace, CSLConstList papszOptions);
402 virtual void EndAsyncReader(GDALAsyncReader *poARIO);
403
405 struct RawBinaryLayout
406 {
407 enum class Interleaving
408 {
409 UNKNOWN,
410 BIP,
411 BIL,
412 BSQ
413 };
414 std::string osRawFilename{};
415 Interleaving eInterleaving = Interleaving::UNKNOWN;
416 GDALDataType eDataType = GDT_Unknown;
417 bool bLittleEndianOrder = false;
418
419 vsi_l_offset nImageOffset = 0;
420 GIntBig nPixelOffset = 0;
421 GIntBig nLineOffset = 0;
422 GIntBig nBandOffset = 0;
423 };
424
425 virtual bool GetRawBinaryLayout(RawBinaryLayout &);
427
428#ifndef DOXYGEN_SKIP
429 CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
430 int nYSize, void *pData, int nBufXSize, int nBufYSize,
431 GDALDataType eBufType, int nBandCount,
432 const int *panBandMap, GSpacing nPixelSpace,
433 GSpacing nLineSpace, GSpacing nBandSpace,
434 GDALRasterIOExtraArg *psExtraArg
435 OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
436#else
437 CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
438 int nYSize, void *pData, int nBufXSize, int nBufYSize,
439 GDALDataType eBufType, int nBandCount,
440 const int *panBandMap, GSpacing nPixelSpace,
441 GSpacing nLineSpace, GSpacing nBandSpace,
443#endif
444
445 virtual CPLStringList GetCompressionFormats(int nXOff, int nYOff,
446 int nXSize, int nYSize,
447 int nBandCount,
448 const int *panBandList);
449 virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
450 int nYOff, int nXSize, int nYSize,
451 int nBands, const int *panBandList,
452 void **ppBuffer, size_t *pnBufferSize,
453 char **ppszDetailedFormat);
454
455 int Reference();
456 int Dereference();
457 int ReleaseRef();
458
463 {
464 return eAccess;
465 }
466
467 int GetShared() const;
468 void MarkAsShared();
469
470 void MarkSuppressOnClose();
471 void UnMarkSuppressOnClose();
472
477 {
478 return bSuppressOnClose;
479 }
480
485 {
486 return papszOpenOptions;
487 }
488
489 bool IsThreadSafe(int nScopeFlags) const;
490
491#ifndef DOXYGEN_SKIP
495 CSLConstList GetOpenOptions() const
496 {
497 return papszOpenOptions;
498 }
499#endif
500
501 static GDALDataset **GetOpenDatasets(int *pnDatasetCount);
502
503#ifndef DOXYGEN_SKIP
504 CPLErr
505 BuildOverviews(const char *pszResampling, int nOverviews,
506 const int *panOverviewList, int nListBands,
507 const int *panBandList, GDALProgressFunc pfnProgress,
508 void *pProgressData,
509 CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(nullptr));
510#else
511 CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
512 const int *panOverviewList, int nListBands,
513 const int *panBandList, GDALProgressFunc pfnProgress,
514 void *pProgressData, CSLConstList papszOptions);
515#endif
516
517 virtual CPLErr AddOverviews(const std::vector<GDALDataset *> &apoSrcOvrDS,
518 GDALProgressFunc pfnProgress,
519 void *pProgressData, CSLConstList papszOptions);
520
521 CPLErr GetInterBandCovarianceMatrix(
522 double *padfCovMatrix, size_t nSize, int nBandCount = 0,
523 const int *panBandList = nullptr, bool bApproxOK = false,
524 bool bForce = false, bool bWriteIntoMetadata = true,
525 int nDeltaDegreeOfFreedom = 1, GDALProgressFunc pfnProgress = nullptr,
526 void *pProgressData = nullptr);
527
528 std::vector<double> GetInterBandCovarianceMatrix(
529 int nBandCount = 0, const int *panBandList = nullptr,
530 bool bApproxOK = false, bool bForce = false,
531 bool bWriteIntoMetadata = true, int nDeltaDegreeOfFreedom = 1,
532 GDALProgressFunc pfnProgress = nullptr, void *pProgressData = nullptr);
533
534 CPLErr ComputeInterBandCovarianceMatrix(
535 double *padfCovMatrix, size_t nSize, int nBandCount = 0,
536 const int *panBandList = nullptr, bool bApproxOK = false,
537 bool bWriteIntoMetadata = true, int nDeltaDegreeOfFreedom = 1,
538 GDALProgressFunc pfnProgress = nullptr, void *pProgressData = nullptr);
539
540 std::vector<double> ComputeInterBandCovarianceMatrix(
541 int nBandCount = 0, const int *panBandList = nullptr,
542 bool bApproxOK = false, bool bWriteIntoMetadata = true,
543 int nDeltaDegreeOfFreedom = 1, GDALProgressFunc pfnProgress = nullptr,
544 void *pProgressData = nullptr);
545
546#ifndef DOXYGEN_XML
547 void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
548 ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
549
550 static void ReportError(const char *pszDSName, CPLErr eErrClass,
551 CPLErrorNum err_no, const char *fmt, ...)
553#endif
554
555 CSLConstList GetMetadata(const char *pszDomain = "") override;
556
557// Only defined when Doxygen enabled
558#ifdef DOXYGEN_SKIP
559 CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
560 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
561 const char *pszDomain) override;
562#endif
563
564 char **GetMetadataDomainList() override;
565
566 virtual void ClearStatistics();
567
568 std::shared_ptr<GDALMDArray> AsMDArray(CSLConstList papszOptions = nullptr);
569
572 static inline GDALDatasetH ToHandle(GDALDataset *poDS)
573 {
574 return static_cast<GDALDatasetH>(poDS);
575 }
576
580 {
581 return static_cast<GDALDataset *>(hDS);
582 }
583
586 static GDALDataset *Open(const char *pszFilename,
587 unsigned int nOpenFlags = 0,
588 const char *const *papszAllowedDrivers = nullptr,
589 const char *const *papszOpenOptions = nullptr,
590 const char *const *papszSiblingFiles = nullptr)
591 {
592 return FromHandle(GDALOpenEx(pszFilename, nOpenFlags,
593 papszAllowedDrivers, papszOpenOptions,
594 papszSiblingFiles));
595 }
596
597 static std::unique_ptr<GDALDataset>
598 Open(GDALOpenInfo *poOpenInfo,
599 const char *const *papszAllowedDrivers = nullptr,
600 const char *const *papszOpenOptions = nullptr);
601
604 {
607
609 OGRLayer *layer = nullptr;
610 };
611
613 // SetEnableOverviews() only to be used by GDALOverviewDataset
614 void SetEnableOverviews(bool bEnable);
615
616 // Only to be used by driver's GetOverviewCount() method.
617 bool AreOverviewsEnabled() const;
618
619 static void ReportUpdateNotSupportedByDriver(const char *pszDriverName);
621
622 private:
623 class Private;
624 Private *m_poPrivate;
625
626 CPL_INTERNAL OGRLayer *BuildLayerFromSelectInfo(
627 swq_select *psSelectInfo, OGRGeometry *poSpatialFilter,
628 const char *pszDialect, swq_select_parse_options *poSelectParseOptions);
629 CPLStringList oDerivedMetadataList{};
630
631 public:
632 virtual int GetLayerCount() const;
633 virtual const OGRLayer *GetLayer(int iLayer) const;
634
635 OGRLayer *GetLayer(int iLayer)
636 {
637 return const_cast<OGRLayer *>(
638 const_cast<const GDALDataset *>(this)->GetLayer(iLayer));
639 }
640
641 virtual bool IsLayerPrivate(int iLayer) const;
642
645 class CPL_DLL Layers
646 {
647 private:
648 friend class GDALDataset;
649 GDALDataset *m_poSelf;
650
651 CPL_INTERNAL explicit Layers(GDALDataset *poSelf) : m_poSelf(poSelf)
652 {
653 }
654
655 public:
658 class CPL_DLL Iterator
659 {
660 struct Private;
661 std::unique_ptr<Private> m_poPrivate;
662
663 public:
665 using reference = OGRLayer *;
666 using difference_type = void;
667 using pointer = void;
669 std::input_iterator_tag;
671 Iterator();
672 Iterator(GDALDataset *poDS, bool bStart);
673 Iterator(const Iterator &oOther);
674 Iterator(Iterator &&oOther) noexcept;
677 Iterator &
678 operator=(const Iterator &oOther);
679 Iterator &operator=(
680 Iterator &&oOther) noexcept;
682 value_type operator*() const;
683 Iterator &operator++();
684 Iterator operator++(int);
685 bool operator!=(const Iterator &it)
686 const;
687 };
688
689 Iterator begin() const;
690 Iterator end() const;
691
692 size_t size() const;
693
694 OGRLayer *operator[](int iLayer);
695 OGRLayer *operator[](size_t iLayer);
696 OGRLayer *operator[](const char *pszLayername);
697 };
698
699 Layers GetLayers();
700
704 class CPL_DLL ConstLayers
705 {
706 private:
707 friend class GDALDataset;
708 const GDALDataset *m_poSelf;
709
710 CPL_INTERNAL explicit ConstLayers(const GDALDataset *poSelf)
711 : m_poSelf(poSelf)
712 {
713 }
714
715 public:
719 class CPL_DLL Iterator
720 {
721 struct Private;
722 std::unique_ptr<Private> m_poPrivate;
723
724 public:
725 using value_type = const OGRLayer *;
726 using reference = const OGRLayer *;
727 using difference_type = void;
728 using pointer = void;
730 std::input_iterator_tag;
732 Iterator();
733 Iterator(const GDALDataset *poDS, bool bStart);
734 Iterator(const Iterator &oOther);
735 Iterator(Iterator &&oOther) noexcept;
738 Iterator &
739 operator=(const Iterator &oOther);
740 Iterator &operator=(
741 Iterator &&oOther) noexcept;
743 value_type operator*() const;
744 Iterator &operator++();
745 Iterator operator++(int);
746 bool operator!=(const Iterator &it)
747 const;
748 };
749
750 Iterator begin() const;
751 Iterator end() const;
752
753 size_t size() const;
754
755 const OGRLayer *operator[](int iLayer);
756 const OGRLayer *operator[](size_t iLayer);
757 const OGRLayer *operator[](const char *pszLayername);
758 };
759
760 ConstLayers GetLayers() const;
761
762 virtual OGRLayer *GetLayerByName(const char *);
763
764 int GetLayerIndex(const char *pszName) const;
765
766 virtual OGRErr DeleteLayer(int iLayer);
767
768 virtual void ResetReading();
769 virtual OGRFeature *GetNextFeature(OGRLayer **ppoBelongingLayer,
770 double *pdfProgressPct,
771 GDALProgressFunc pfnProgress,
772 void *pProgressData);
773
776 class CPL_DLL Features
777 {
778 private:
779 friend class GDALDataset;
780 GDALDataset *m_poSelf;
781
782 CPL_INTERNAL explicit Features(GDALDataset *poSelf) : m_poSelf(poSelf)
783 {
784 }
785
786 class CPL_DLL Iterator
787 {
788 struct Private;
789 std::unique_ptr<Private> m_poPrivate;
790
791 public:
792 Iterator(GDALDataset *poDS, bool bStart);
793 Iterator(const Iterator &oOther); // declared but not defined.
794 // Needed for gcc 5.4 at least
795 Iterator(Iterator &&oOther) noexcept; // declared but not defined.
796 // Needed for gcc 5.4 at least
797 ~Iterator();
798 const FeatureLayerPair &operator*() const;
799 Iterator &operator++();
800 bool operator!=(const Iterator &it) const;
801 };
802
803 public:
804 const Iterator begin() const;
805
806 const Iterator end() const;
807 };
808
809 Features GetFeatures();
810
811 virtual int TestCapability(const char *) const;
812
813 virtual std::vector<std::string>
814 GetFieldDomainNames(CSLConstList papszOptions = nullptr) const;
815
816 virtual const OGRFieldDomain *GetFieldDomain(const std::string &name) const;
817
818 virtual bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
819 std::string &failureReason);
820
821 virtual bool DeleteFieldDomain(const std::string &name,
822 std::string &failureReason);
823
824 virtual bool UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
825 std::string &failureReason);
826
827 virtual std::vector<std::string>
828 GetRelationshipNames(CSLConstList papszOptions = nullptr) const;
829
830 virtual const GDALRelationship *
831 GetRelationship(const std::string &name) const;
832
833 virtual bool
834 AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
835 std::string &failureReason);
836
837 virtual bool DeleteRelationship(const std::string &name,
838 std::string &failureReason);
839
840 virtual bool
841 UpdateRelationship(std::unique_ptr<GDALRelationship> &&relationship,
842 std::string &failureReason);
843
845 OGRLayer *CreateLayer(const char *pszName);
846
847 OGRLayer *CreateLayer(const char *pszName, std::nullptr_t);
849
850 OGRLayer *CreateLayer(const char *pszName,
851 const OGRSpatialReference *poSpatialRef,
853 CSLConstList papszOptions = nullptr);
854
855 OGRLayer *CreateLayer(const char *pszName,
856 const OGRGeomFieldDefn *poGeomFieldDefn,
857 CSLConstList papszOptions = nullptr);
858
859 virtual OGRLayer *CopyLayer(OGRLayer *poSrcLayer, const char *pszNewName,
860 CSLConstList papszOptions = nullptr);
861
862 virtual OGRStyleTable *GetStyleTable();
863 virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
864
865 virtual void SetStyleTable(OGRStyleTable *poStyleTable);
866
867 virtual OGRLayer *ExecuteSQL(const char *pszStatement,
868 OGRGeometry *poSpatialFilter,
869 const char *pszDialect);
870 virtual void ReleaseResultSet(OGRLayer *poResultsSet);
871 virtual OGRErr AbortSQL();
872
873 int GetRefCount() const;
874 int GetSummaryRefCount() const;
875 OGRErr Release();
876
877 virtual OGRErr StartTransaction(int bForce = FALSE);
878 virtual OGRErr CommitTransaction();
879 virtual OGRErr RollbackTransaction();
880
881 virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
882
883 static std::string BuildFilename(const char *pszFilename,
884 const char *pszReferencePath,
885 bool bRelativeToReferencePath);
886
888 static int IsGenericSQLDialect(const char *pszDialect);
889
890 // Semi-public methods. Only to be used by in-tree drivers.
891 GDALSQLParseInfo *
892 BuildParseInfo(swq_select *psSelectInfo,
893 swq_select_parse_options *poSelectParseOptions);
894 static void DestroyParseInfo(GDALSQLParseInfo *psParseInfo);
895 OGRLayer *ExecuteSQL(const char *pszStatement, OGRGeometry *poSpatialFilter,
896 const char *pszDialect,
897 swq_select_parse_options *poSelectParseOptions);
898
899 static constexpr const char *const apszSpecialSubDatasetSyntax[] = {
900 "NITF_IM:{ANY}:{FILENAME}", "PDF:{ANY}:{FILENAME}",
901 "RASTERLITE:{FILENAME},{ANY}", "TILEDB:\"{FILENAME}\":{ANY}",
902 "TILEDB:{FILENAME}:{ANY}"};
903
905
906 protected:
907 virtual OGRLayer *ICreateLayer(const char *pszName,
908 const OGRGeomFieldDefn *poGeomFieldDefn,
909 CSLConstList papszOptions);
910
912 OGRErr ProcessSQLCreateIndex(const char *);
913 OGRErr ProcessSQLDropIndex(const char *);
914 OGRErr ProcessSQLDropTable(const char *);
915 OGRErr ProcessSQLAlterTableAddColumn(const char *);
916 OGRErr ProcessSQLAlterTableDropColumn(const char *);
917 OGRErr ProcessSQLAlterTableAlterColumn(const char *);
918 OGRErr ProcessSQLAlterTableRenameColumn(const char *);
919
920 OGRStyleTable *m_poStyleTable = nullptr;
921
922 friend class GDALProxyPoolDataset;
924
925 private:
927};
928
930struct CPL_DLL GDALDatasetUniquePtrDeleter
931{
932 void operator()(GDALDataset *poDataset) const
933 {
934 GDALClose(poDataset);
935 }
936};
937
939
941struct CPL_DLL GDALDatasetUniquePtrReleaser
942{
943 void operator()(GDALDataset *poDataset) const
944 {
945 if (poDataset)
946 poDataset->Release();
947 }
948};
949
951
956using GDALDatasetUniquePtr =
957 std::unique_ptr<GDALDataset, GDALDatasetUniquePtrDeleter>;
958
959#endif
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:476
Class used as a session object for asynchronous requests.
Definition gdal_asyncreader.h:32
Class returned by GetBands() that act as a container for raster bands.
Definition gdal_dataset.h:252
Class returned by GetBands() that act as a container for raster bands.
Definition gdal_dataset.h:294
Layer iterator.
Definition gdal_dataset.h:720
std::input_iterator_tag iterator_category
iterator_category
Definition gdal_dataset.h:730
void difference_type
difference_type
Definition gdal_dataset.h:727
void pointer
pointer
Definition gdal_dataset.h:728
Class returned by GetLayers() that acts as a range of layers.
Definition gdal_dataset.h:705
Class returned by GetFeatures() that act as a container for vector features.
Definition gdal_dataset.h:777
Layer iterator.
Definition gdal_dataset.h:659
void pointer
pointer
Definition gdal_dataset.h:667
void difference_type
difference_type
Definition gdal_dataset.h:666
std::input_iterator_tag iterator_category
iterator_category
Definition gdal_dataset.h:669
Class returned by GetLayers() that acts as a range of layers.
Definition gdal_dataset.h:646
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:77
virtual bool SetQueryLoggerFunc(GDALQueryLoggerFunc pfnQueryLoggerFuncIn, void *poQueryLoggerArgIn)
SetQueryLoggerFunc.
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_dataset.h:586
OGRErr Release()
Drop a reference to this dataset, and if the reference count drops to one close (destroy) the dataset...
Definition gdaldataset.cpp:6166
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
char ** GetOpenOptions()
Return open options.
Definition gdal_dataset.h:484
bool IsMarkedSuppressOnClose() const
Return MarkSuppressOnClose flag.
Definition gdal_dataset.h:476
static GDALDataset * FromHandle(GDALDatasetH hDS)
Convert a GDALDatasetH to a GDALDataset*.
Definition gdal_dataset.h:579
static GDALDatasetH ToHandle(GDALDataset *poDS)
Convert a GDALDataset* to a GDALDatasetH.
Definition gdal_dataset.h:572
OGRLayer * GetLayer(int iLayer)
Fetch a layer by index.
Definition gdal_dataset.h:635
GDALAccess GetAccess() const
Return access mode.
Definition gdal_dataset.h:462
Class for managing the registration of file format drivers.
Definition gdal_drivermanager.h:42
Format specific driver.
Definition gdal_driver.h:63
Class that encapsulates a geotransform matrix.
Definition gdal_geotransform.h:42
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition gdal_multidim.h:305
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
Object with metadata.
Definition gdal_majorobject.h:43
Class for dataset open functions.
Definition gdal_openinfo.h:30
A single raster band (or channel).
Definition gdal_rasterband.h:108
Definition of a table relationship.
Definition gdal_relationship.h:38
Simple container for a bounding region (rectangle)
Definition ogr_core.h:44
A simple feature, including geometry and attributes.
Definition ogr_feature.h:1041
Definition of a field domain.
Definition ogr_feature.h:1780
Definition of a geometry field of an OGRFeatureDefn.
Definition ogr_feature.h:335
Abstract base class for all geometry classes.
Definition ogr_geometry.h:357
This class represents a layer of simple features, with access methods.
Definition ogrsf_frmts.h:61
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
This class represents a style table.
Definition ogr_featurestyle.h:69
CPLErr
Error category / error level.
Definition cpl_error.h:45
int CPLErrorNum
Error number.
Definition cpl_error.h:103
Core portability definitions for CPL.
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:412
void(* GDALQueryLoggerFunc)(const char *pszSQL, const char *pszError, int64_t lNumRecords, int64_t lExecutionTimeMilliseconds, void *pQueryLoggerArg)
Type of functions to pass to GDALDatasetSetQueryLoggerFunc.
Definition gdal.h:1541
GDALAccess
Definition gdal.h:120
@ GA_ReadOnly
Definition gdal.h:121
GDALDataType
Definition gdal.h:48
@ GDT_Unknown
Definition gdal.h:49
CPLErr GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition gdaldataset.cpp:4723
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:4044
GDALRWFlag
Definition gdal.h:127
Forward definitions of GDAL/OGR/OSR C handle types.
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition gdal_fwd.h:42
Core portability services for cross-platform OGR code.
OGRwkbGeometryType
List of well known binary geometry types.
Definition ogr_core.h:423
@ wkbUnknown
unknown type, non-standard
Definition ogr_core.h:424
int OGRErr
Type for a OGR error.
Definition ogr_core.h:388
Simple feature classes.
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition ogr_feature.h:1723
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition ogrsf_frmts.h:478
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition ogrsf_frmts.h:486
Object returned by GetFeatures() iterators.
Definition gdal_dataset.h:604
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:174
Ground Control Point.
Definition gdal.h:1261