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