15#ifndef GDALDATASET_H_INCLUDED
16#define GDALDATASET_H_INCLUDED
21#include "gdal_geotransform.h"
22#include "gdal_majorobject.h"
23#include "gdal_defaultoverviews.h"
41class swq_select_parse_options;
51typedef struct GDALSQLParseInfo GDALSQLParseInfo;
55#if !defined(OPTIONAL_OUTSIDE_GDAL)
56#if defined(GDAL_COMPILATION)
57#define OPTIONAL_OUTSIDE_GDAL(val)
59#define OPTIONAL_OUTSIDE_GDAL(val) = val
68#if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
69#define BANDMAP_TYPE const int *
71#define BANDMAP_TYPE int *
79 GDALOpenEx(
const char *pszFilename,
unsigned int nOpenFlags,
80 const char *
const *papszAllowedDrivers,
81 const char *
const *papszOpenOptions,
82 const char *
const *papszSiblingFiles);
86 friend class GDALDefaultOverviews;
87 friend class GDALProxyDataset;
90 CPL_INTERNAL
void AddToDatasetOpenList();
92 CPL_INTERNAL
void UnregisterFromSharedDataset();
94 CPL_INTERNAL
static void ReportErrorV(
const char *pszDSName,
96 const char *fmt, va_list args);
104 int nRasterXSize = 512;
105 int nRasterYSize = 512;
109 static constexpr int OPEN_FLAGS_CLOSED = -1;
114 bool bForceCachedIO =
false;
115 bool bShared =
false;
116 bool bIsInternal =
true;
117 bool bSuppressOnClose =
false;
119 mutable std::map<std::string, std::unique_ptr<OGRFieldDomain>>
120 m_oMapFieldDomains{};
125 void RasterInitialize(
int,
int);
127 void SetBand(
int nNewBand, std::unique_ptr<GDALRasterBand> poBand);
129 GDALDefaultOverviews oOvManager{};
131 virtual CPLErr IBuildOverviews(
const char *pszResampling,
int nOverviews,
132 const int *panOverviewList,
int nListBands,
133 const int *panBandList,
134 GDALProgressFunc pfnProgress,
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,
147 BlockBasedRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
148 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
150 const int *panBandMap,
GSpacing nPixelSpace,
153 CPLErr BlockBasedFlushCache(
bool bAtClosing);
156 BandBasedRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
157 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
159 const int *panBandMap,
GSpacing nPixelSpace,
164 RasterIOResampled(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
165 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
167 const int *panBandMap,
GSpacing nPixelSpace,
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);
177 int nXSize,
int nYSize,
void *pData,
178 int nBufXSize,
int nBufYSize,
180 const int *panBandMap,
GSpacing nPixelSpace,
184 void ShareLockWithParentDataset(
GDALDataset *poParentDataset);
186 bool m_bCanBeReopened =
false;
188 virtual bool CanBeCloned(
int nScopeFlags,
bool bCanShareState)
const;
190 friend class GDALThreadSafeDataset;
191 friend class MEMDataset;
192 virtual std::unique_ptr<GDALDataset> Clone(
int nScopeFlags,
193 bool bCanShareState)
const;
197 void CleanupPostFileClosing();
199 virtual int CloseDependentDatasets();
201 int ValidateLayerCreationOptions(
const char *
const *papszLCO);
203 char **papszOpenOptions =
nullptr;
210 void LeaveReadWrite();
213 void TemporarilyDropReadWriteLock();
214 void ReacquireReadWriteLock();
216 void DisableReadWriteMutex();
221 bool IsAllBands(
int nBandCount,
const int *panBandList)
const;
227 virtual CPLErr Close(GDALProgressFunc pfnProgress =
nullptr,
228 void *pProgressData =
nullptr);
230 virtual bool GetCloseReportsProgress()
const;
232 virtual bool CanReopenWithCurrentDescription()
const;
234 int GetRasterXSize()
const;
235 int GetRasterYSize()
const;
236 int GetRasterCount()
const;
247 void *poQueryLoggerArgIn);
261 class CPL_DLL Iterator
264 std::unique_ptr<Private> m_poPrivate;
268 Iterator(
const Iterator &oOther);
270 Iterator(Iterator &&oOther)
noexcept;
274 Iterator &operator++();
275 bool operator!=(
const Iterator &it)
const;
279 const Iterator
begin()
const;
281 const Iterator
end()
const;
304 class CPL_DLL Iterator
307 std::unique_ptr<Private> m_poPrivate;
313 Iterator &operator++();
314 bool operator!=(
const Iterator &it)
const;
318 const Iterator
begin()
const;
320 const Iterator
end()
const;
330 virtual CPLErr FlushCache(
bool bAtClosing =
false);
331 virtual CPLErr DropCache();
333 virtual GIntBig GetEstimatedRAMUsage();
342 const char *GetProjectionRef(
void)
const;
343 CPLErr SetProjection(
const char *pszProjection);
348 CPLErr GetGeoTransform(
double *padfGeoTransform)
const
349#if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
350 CPL_WARN_DEPRECATED(
"Use GetGeoTransform(GDALGeoTransform&) instead")
354 CPLErr SetGeoTransform(
const double *padfGeoTransform)
355#if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
357 "Use SetGeoTransform(const GDALGeoTransform&) instead")
365 CPLErr GeolocationToPixelLine(
367 double *pdfPixel,
double *pdfLine,
373 virtual void *GetInternalHandle(
const char *pszHandleName);
375 virtual char **GetFileList(
void);
377 const char *GetDriverName()
const;
380 virtual int GetGCPCount();
386 const char *GetGCPProjection()
const;
388 const char *pszGCPProjection);
390 virtual CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
392 int nBandCount,
int *panBandList,
395 virtual CPLErr CreateMaskBand(
int nFlagsIn);
398 BeginAsyncReader(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
void *pBuf,
400 int nBandCount,
int *panBandMap,
int nPixelSpace,
401 int nLineSpace,
int nBandSpace,
CSLConstList papszOptions);
405 struct RawBinaryLayout
407 enum class Interleaving
414 std::string osRawFilename{};
415 Interleaving eInterleaving = Interleaving::UNKNOWN;
417 bool bLittleEndianOrder =
false;
425 virtual bool GetRawBinaryLayout(RawBinaryLayout &);
430 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
432 const int *panBandMap,
GSpacing nPixelSpace,
438 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
440 const int *panBandMap,
GSpacing nPixelSpace,
445 virtual CPLStringList GetCompressionFormats(
int nXOff,
int nYOff,
446 int nXSize,
int nYSize,
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);
467 int GetShared()
const;
470 void MarkSuppressOnClose();
471 void UnMarkSuppressOnClose();
478 return bSuppressOnClose;
486 return papszOpenOptions;
489 bool IsThreadSafe(
int nScopeFlags)
const;
497 return papszOpenOptions;
501 static GDALDataset **GetOpenDatasets(
int *pnDatasetCount);
505 BuildOverviews(
const char *pszResampling,
int nOverviews,
506 const int *panOverviewList,
int nListBands,
507 const int *panBandList, GDALProgressFunc pfnProgress,
509 CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(
nullptr));
511 CPLErr BuildOverviews(
const char *pszResampling,
int nOverviews,
512 const int *panOverviewList,
int nListBands,
513 const int *panBandList, GDALProgressFunc pfnProgress,
517 virtual CPLErr AddOverviews(
const std::vector<GDALDataset *> &apoSrcOvrDS,
518 GDALProgressFunc pfnProgress,
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);
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);
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);
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);
550 static
void ReportError(const
char *pszDSName,
CPLErr eErrClass,
555 CSLConstList GetMetadata(
const char *pszDomain =
"")
override;
561 const char *pszDomain)
override;
564 char **GetMetadataDomainList()
override;
566 virtual void ClearStatistics();
568 std::shared_ptr<GDALMDArray> AsMDArray(
CSLConstList papszOptions =
nullptr);
587 unsigned int nOpenFlags = 0,
588 const char *
const *papszAllowedDrivers =
nullptr,
589 const char *
const *papszOpenOptions =
nullptr,
590 const char *
const *papszSiblingFiles =
nullptr)
592 return FromHandle(
GDALOpenEx(pszFilename, nOpenFlags,
593 papszAllowedDrivers, papszOpenOptions,
597 static std::unique_ptr<GDALDataset>
599 const char *
const *papszAllowedDrivers =
nullptr,
600 const char *
const *papszOpenOptions =
nullptr);
614 void SetEnableOverviews(
bool bEnable);
617 bool AreOverviewsEnabled()
const;
619 static void ReportUpdateNotSupportedByDriver(
const char *pszDriverName);
624 Private *m_poPrivate;
626 CPL_INTERNAL
OGRLayer *BuildLayerFromSelectInfo(
627 swq_select *psSelectInfo,
OGRGeometry *poSpatialFilter,
628 const char *pszDialect, swq_select_parse_options *poSelectParseOptions);
632 virtual int GetLayerCount()
const;
633 virtual const OGRLayer *GetLayer(
int iLayer)
const;
638 const_cast<const GDALDataset *
>(
this)->GetLayer(iLayer));
641 virtual bool IsLayerPrivate(
int iLayer)
const;
661 std::unique_ptr<Private> m_poPrivate;
669 std::input_iterator_tag;
695 OGRLayer *operator[](
size_t iLayer);
696 OGRLayer *operator[](
const char *pszLayername);
722 std::unique_ptr<Private> m_poPrivate;
730 std::input_iterator_tag;
755 const OGRLayer *operator[](
int iLayer);
756 const OGRLayer *operator[](
size_t iLayer);
757 const OGRLayer *operator[](
const char *pszLayername);
762 virtual OGRLayer *GetLayerByName(
const char *);
764 int GetLayerIndex(
const char *pszName)
const;
766 virtual OGRErr DeleteLayer(
int iLayer);
768 virtual void ResetReading();
770 double *pdfProgressPct,
771 GDALProgressFunc pfnProgress,
772 void *pProgressData);
786 class CPL_DLL Iterator
789 std::unique_ptr<Private> m_poPrivate;
793 Iterator(
const Iterator &oOther);
795 Iterator(Iterator &&oOther)
noexcept;
799 Iterator &operator++();
800 bool operator!=(
const Iterator &it)
const;
804 const Iterator
begin()
const;
806 const Iterator
end()
const;
811 virtual int TestCapability(
const char *)
const;
813 virtual std::vector<std::string>
814 GetFieldDomainNames(
CSLConstList papszOptions =
nullptr)
const;
816 virtual const OGRFieldDomain *GetFieldDomain(
const std::string &name)
const;
818 virtual bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
819 std::string &failureReason);
821 virtual bool DeleteFieldDomain(
const std::string &name,
822 std::string &failureReason);
824 virtual bool UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
825 std::string &failureReason);
827 virtual std::vector<std::string>
828 GetRelationshipNames(
CSLConstList papszOptions =
nullptr)
const;
831 GetRelationship(
const std::string &name)
const;
834 AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
835 std::string &failureReason);
837 virtual bool DeleteRelationship(
const std::string &name,
838 std::string &failureReason);
841 UpdateRelationship(std::unique_ptr<GDALRelationship> &&relationship,
842 std::string &failureReason);
845 OGRLayer *CreateLayer(
const char *pszName);
847 OGRLayer *CreateLayer(
const char *pszName, std::nullptr_t);
850 OGRLayer *CreateLayer(
const char *pszName,
855 OGRLayer *CreateLayer(
const char *pszName,
863 virtual void SetStyleTableDirectly(
OGRStyleTable *poStyleTable);
867 virtual OGRLayer *ExecuteSQL(
const char *pszStatement,
869 const char *pszDialect);
870 virtual void ReleaseResultSet(
OGRLayer *poResultsSet);
871 virtual OGRErr AbortSQL();
873 int GetRefCount()
const;
874 int GetSummaryRefCount()
const;
877 virtual OGRErr StartTransaction(
int bForce = FALSE);
878 virtual OGRErr CommitTransaction();
879 virtual OGRErr RollbackTransaction();
881 virtual std::shared_ptr<GDALGroup> GetRootGroup()
const;
883 static std::string BuildFilename(
const char *pszFilename,
884 const char *pszReferencePath,
885 bool bRelativeToReferencePath);
888 static int IsGenericSQLDialect(
const char *pszDialect);
892 BuildParseInfo(swq_select *psSelectInfo,
893 swq_select_parse_options *poSelectParseOptions);
894 static void DestroyParseInfo(GDALSQLParseInfo *psParseInfo);
896 const char *pszDialect,
897 swq_select_parse_options *poSelectParseOptions);
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}"};
907 virtual OGRLayer *ICreateLayer(
const char *pszName,
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 *);
922 friend class GDALProxyPoolDataset;
930struct CPL_DLL GDALDatasetUniquePtrDeleter
941struct CPL_DLL GDALDatasetUniquePtrReleaser
956using GDALDatasetUniquePtr =
957 std::unique_ptr<GDALDataset, GDALDatasetUniquePtrDeleter>;
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 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
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
Ground Control Point.
Definition gdal.h:1261