QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | Friends | List of all members
QgsGdalUtils Class Reference

Utilities for working with GDAL. More...

#include <qgsgdalutils.h>

Classes

struct  VsiNetworkFileSystemDetails
 Encapsulates details for a GDAL VSI network file system. More...
 

Static Public Member Functions

static bool applyVsiCredentialOptions (const QString &prefix, const QString &path, const QVariantMap &options)
 Attempts to apply VSI credential options.
 
static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset (const QgsRectangle &extent, QgsRasterBlock *block)
 Converts a raster block to a single band GDAL memory dataset.
 
static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset (double rotation, const QgsPointXY &origin, double gridXSize, double gridYSize, QgsRasterBlock *block)
 Converts a raster block to a single band GDAL memory dataset with rotation angle,side sizes of the grid, origin if the grid (top left if rotation == 0)
 
static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset (int pixelWidth, int pixelHeight, const QgsRectangle &extent, void *block, GDALDataType dataType)
 Converts a data block to a single band GDAL memory dataset.
 
static gdal::dataset_unique_ptr createMultiBandMemoryDataset (GDALDataType dataType, int bands, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs)
 Creates a new multi band memory dataset with given parameters.
 
static gdal::dataset_unique_ptr createSingleBandMemoryDataset (GDALDataType dataType, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs)
 Creates a new single band memory dataset with given parameters.
 
static gdal::dataset_unique_ptr createSingleBandTiffDataset (const QString &filename, GDALDataType dataType, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs)
 Creates a new single band TIFF dataset with given parameters.
 
static GDALDataType gdalDataTypeFromQgisDataType (Qgis::DataType dataType)
 Returns the GDAL data type corresponding to the QGIS data type dataType.
 
static QString gdalDocumentationUrlForDriver (GDALDriverH hDriver)
 Returns the URL for the GDAL documentation for the specified driver.
 
static GDALResampleAlg gdalResamplingAlgorithm (QgsRasterDataProvider::ResamplingMethod method)
 Returns the GDAL resampling method corresponding to the QGIS resampling method.
 
static QString helpCreationOptionsFormat (const QString &format)
 Gets creation options metadata for a given format.
 
static gdal::dataset_unique_ptr imageToMemoryDataset (const QImage &image)
 Converts an image to a GDAL memory dataset by borrowing image data.
 
static bool isVsiArchiveFileExtension (const QString &extension)
 Returns true if a file extension is a supported archive style container (e.g.
 
static bool isVsiArchivePrefix (const QString &prefix)
 Returns true if prefix is a supported archive style container prefix (e.g.
 
static QStringList multiLayerFileExtensions ()
 Returns a list of file extensions which potentially contain multiple layers representing GDAL raster or vector layers.
 
static char ** papszFromStringList (const QStringList &list)
 Helper function.
 
static bool pathIsCheapToOpen (const QString &path, int smallFileSizeLimit=50000)
 Returns true if the dataset at the specified path is considered "cheap" to open.
 
static QImage resampleImage (const QImage &image, QSize outputSize, GDALRIOResampleAlg resampleAlg)
 Resamples a QImage image using GDAL resampler.
 
static bool resampleSingleBandRaster (GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg, const char *pszCoordinateOperation)
 Resamples a single band raster to the destination dataset with different resolution (and possibly with different CRS).
 
static bool resampleSingleBandRaster (GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg, const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs)
 Resamples a single band raster to the destination dataset with different resolution and different CRS.
 
static GDALDatasetH rpcAwareAutoCreateWarpedVrt (GDALDatasetH hSrcDS, const char *pszSrcWKT, const char *pszDstWKT, GDALResampleAlg eResampleAlg, double dfMaxError, const GDALWarpOptions *psOptionsIn)
 This is a copy of GDALAutoCreateWarpedVRT optimized for imagery using RPC georeferencing that also sets RPC_HEIGHT in GDALCreateGenImgProjTransformer2 based on HEIGHT_OFF.
 
static void * rpcAwareCreateTransformer (GDALDatasetH hSrcDS, GDALDatasetH hDstDS=nullptr, char **papszOptions=nullptr)
 This is a wrapper around GDALCreateGenImgProjTransformer2() that takes into account RPC georeferencing (it sets RPC_HEIGHT in GDALCreateGenImgProjTransformer2 based on HEIGHT_OFF).
 
static void setupProxy ()
 Sets the gdal proxy variables.
 
static bool supportsRasterCreate (GDALDriverH driver)
 Reads whether a driver supports GDALCreate() for raster purposes.
 
static QString validateCreationOptionsFormat (const QStringList &createOptions, const QString &format)
 Validates creation options for a given format, regardless of layer.
 
static bool vrtMatchesLayerType (const QString &vrtPath, Qgis::LayerType type)
 Returns true if the VRT file at the specified path is a VRT matching the given layer type.
 
static QStringList vsiArchiveFileExtensions ()
 Returns a list of file extensions which correspond to archive style containers supported by GDAL (e.g.
 
static QStringList vsiArchivePrefixes ()
 Returns a list of vsi prefixes which correspond to archive style containers (eg vsizip).
 
static Qgis::VsiHandlerType vsiHandlerType (const QString &prefix)
 Returns the VSI handler type for a given VSI prefix.
 
static QList< VsiNetworkFileSystemDetailsvsiNetworkFileSystems ()
 Returns a list of available GDAL VSI network file systems.
 
static QString vsiPrefixForPath (const QString &path)
 Returns a the vsi prefix which corresponds to a file path, or an empty string if the path is not associated with a vsi prefix.
 

Friends

class TestQgsGdalUtils
 

Detailed Description

Utilities for working with GDAL.

Note
not available in Python bindings
Since
QGIS 3.4

Definition at line 99 of file qgsgdalutils.h.

Member Function Documentation

◆ applyVsiCredentialOptions()

bool QgsGdalUtils::applyVsiCredentialOptions ( const QString &  prefix,
const QString &  path,
const QVariantMap &  options 
)
static

Attempts to apply VSI credential options.

This method uses GDAL's VSISetPathSpecificOption, which will overrwrite any existing options for the same VSI prefix and path.

Returns true if the options could be applied.

Since
QGIS 3.40

Definition at line 1058 of file qgsgdalutils.cpp.

◆ blockToSingleBandMemoryDataset() [1/3]

gdal::dataset_unique_ptr QgsGdalUtils::blockToSingleBandMemoryDataset ( const QgsRectangle extent,
QgsRasterBlock block 
)
static

Converts a raster block to a single band GDAL memory dataset.

Warning
The raster block must stay allocated for the lifetime of the returned gdal dataset.
Since
QGIS 3.30

Definition at line 314 of file qgsgdalutils.cpp.

◆ blockToSingleBandMemoryDataset() [2/3]

gdal::dataset_unique_ptr QgsGdalUtils::blockToSingleBandMemoryDataset ( double  rotation,
const QgsPointXY origin,
double  gridXSize,
double  gridYSize,
QgsRasterBlock block 
)
static

Converts a raster block to a single band GDAL memory dataset with rotation angle,side sizes of the grid, origin if the grid (top left if rotation == 0)

Warning
The raster block must stay allocated for the lifetime of the returned gdal dataset.
Since
QGIS 3.30

Definition at line 332 of file qgsgdalutils.cpp.

◆ blockToSingleBandMemoryDataset() [3/3]

gdal::dataset_unique_ptr QgsGdalUtils::blockToSingleBandMemoryDataset ( int  pixelWidth,
int  pixelHeight,
const QgsRectangle extent,
void *  block,
GDALDataType  dataType 
)
static

Converts a data block to a single band GDAL memory dataset.

Warning
The data block must stay allocated for the lifetime of the returned gdal dataset.
Since
QGIS 3.26

Definition at line 280 of file qgsgdalutils.cpp.

◆ createMultiBandMemoryDataset()

gdal::dataset_unique_ptr QgsGdalUtils::createMultiBandMemoryDataset ( GDALDataType  dataType,
int  bands,
const QgsRectangle extent,
int  width,
int  height,
const QgsCoordinateReferenceSystem crs 
)
static

Creates a new multi band memory dataset with given parameters.

Since
QGIS 3.12

Definition at line 180 of file qgsgdalutils.cpp.

◆ createSingleBandMemoryDataset()

gdal::dataset_unique_ptr QgsGdalUtils::createSingleBandMemoryDataset ( GDALDataType  dataType,
const QgsRectangle extent,
int  width,
int  height,
const QgsCoordinateReferenceSystem crs 
)
static

Creates a new single band memory dataset with given parameters.

Since
QGIS 3.8

Definition at line 175 of file qgsgdalutils.cpp.

◆ createSingleBandTiffDataset()

gdal::dataset_unique_ptr QgsGdalUtils::createSingleBandTiffDataset ( const QString &  filename,
GDALDataType  dataType,
const QgsRectangle extent,
int  width,
int  height,
const QgsCoordinateReferenceSystem crs 
)
static

Creates a new single band TIFF dataset with given parameters.

Since
QGIS 3.8

Definition at line 205 of file qgsgdalutils.cpp.

◆ gdalDataTypeFromQgisDataType()

GDALDataType QgsGdalUtils::gdalDataTypeFromQgisDataType ( Qgis::DataType  dataType)
static

Returns the GDAL data type corresponding to the QGIS data type dataType.

Since
QGIS 3.30

Definition at line 583 of file qgsgdalutils.cpp.

◆ gdalDocumentationUrlForDriver()

QString QgsGdalUtils::gdalDocumentationUrlForDriver ( GDALDriverH  hDriver)
static

Returns the URL for the GDAL documentation for the specified driver.

Since
QGIS 3.40

Definition at line 1047 of file qgsgdalutils.cpp.

◆ gdalResamplingAlgorithm()

GDALResampleAlg QgsGdalUtils::gdalResamplingAlgorithm ( QgsRasterDataProvider::ResamplingMethod  method)
static

Returns the GDAL resampling method corresponding to the QGIS resampling method.

Since
QGIS 3.30

Definition at line 639 of file qgsgdalutils.cpp.

◆ helpCreationOptionsFormat()

QString QgsGdalUtils::helpCreationOptionsFormat ( const QString &  format)
static

Gets creation options metadata for a given format.

Since
QGIS 3.10

Definition at line 490 of file qgsgdalutils.cpp.

◆ imageToMemoryDataset()

gdal::dataset_unique_ptr QgsGdalUtils::imageToMemoryDataset ( const QImage &  image)
static

Converts an image to a GDAL memory dataset by borrowing image data.

Warning
The image must exist unchanged for the lifetime of the returned gdal dataset!
Since
QGIS 3.12

Definition at line 236 of file qgsgdalutils.cpp.

◆ isVsiArchiveFileExtension()

bool QgsGdalUtils::isVsiArchiveFileExtension ( const QString &  extension)
static

Returns true if a file extension is a supported archive style container (e.g.

".zip").

Since
QGIS 3.32

Definition at line 965 of file qgsgdalutils.cpp.

◆ isVsiArchivePrefix()

bool QgsGdalUtils::isVsiArchivePrefix ( const QString &  prefix)
static

Returns true if prefix is a supported archive style container prefix (e.g.

"/vsizip/").

Since
QGIS 3.32

Definition at line 940 of file qgsgdalutils.cpp.

◆ multiLayerFileExtensions()

QStringList QgsGdalUtils::multiLayerFileExtensions ( )
static

Returns a list of file extensions which potentially contain multiple layers representing GDAL raster or vector layers.

Since
QGIS 3.22

Definition at line 753 of file qgsgdalutils.cpp.

◆ papszFromStringList()

char ** QgsGdalUtils::papszFromStringList ( const QStringList &  list)
static

Helper function.

Since
QGIS 3.10

Definition at line 521 of file qgsgdalutils.cpp.

◆ pathIsCheapToOpen()

bool QgsGdalUtils::pathIsCheapToOpen ( const QString &  path,
int  smallFileSizeLimit = 50000 
)
static

Returns true if the dataset at the specified path is considered "cheap" to open.

Datasets which are considered cheap to open may correspond to very small file sizes, or data types which only require some inexpensive header parsing to open.

One use case for this method is to test whether a remote dataset can be safely opened to resolve the geometry types and other metadata without causing undue network traffic.

The smallFileSizeLimit argument specifies the maximum file size (in bytes) which will be considered as small.

Since
QGIS 3.22

Definition at line 726 of file qgsgdalutils.cpp.

◆ resampleImage()

QImage QgsGdalUtils::resampleImage ( const QImage &  image,
QSize  outputSize,
GDALRIOResampleAlg  resampleAlg 
)
static

Resamples a QImage image using GDAL resampler.

Since
QGIS 3.12

Definition at line 439 of file qgsgdalutils.cpp.

◆ resampleSingleBandRaster() [1/2]

bool QgsGdalUtils::resampleSingleBandRaster ( GDALDatasetH  hSrcDS,
GDALDatasetH  hDstDS,
GDALResampleAlg  resampleAlg,
const char *  pszCoordinateOperation 
)
static

Resamples a single band raster to the destination dataset with different resolution (and possibly with different CRS).

Ideally the source dataset should cover the whole area or the destination dataset.

In case of different CRS, the parameter pszCoordinateOperation is the Proj coordinate operation string, that can be obtained with QgsCoordinateTransformContext::calculateCoordinateOperation()

Returns
true on success
Since
QGIS 3.8

Definition at line 412 of file qgsgdalutils.cpp.

◆ resampleSingleBandRaster() [2/2]

bool QgsGdalUtils::resampleSingleBandRaster ( GDALDatasetH  hSrcDS,
GDALDatasetH  hDstDS,
GDALResampleAlg  resampleAlg,
const QgsCoordinateReferenceSystem sourceCrs,
const QgsCoordinateReferenceSystem destinationCrs 
)
static

Resamples a single band raster to the destination dataset with different resolution and different CRS.

Ideally the source dataset should cover the whole area or the destination dataset.

Note
If possible, it is preferable to use the overload method with parameter pszCoordinateOperation. But if it is not possible or it fails to obtain the Proj coordinate operation string, this function is an alternative.
Returns
true on success
Since
QGIS 3.30

Definition at line 423 of file qgsgdalutils.cpp.

◆ rpcAwareAutoCreateWarpedVrt()

GDALDatasetH QgsGdalUtils::rpcAwareAutoCreateWarpedVrt ( GDALDatasetH  hSrcDS,
const char *  pszSrcWKT,
const char *  pszDstWKT,
GDALResampleAlg  eResampleAlg,
double  dfMaxError,
const GDALWarpOptions *  psOptionsIn 
)
static

This is a copy of GDALAutoCreateWarpedVRT optimized for imagery using RPC georeferencing that also sets RPC_HEIGHT in GDALCreateGenImgProjTransformer2 based on HEIGHT_OFF.

By default GDAL would assume that the imagery has zero elevation - if that is not the case, the image would not be shown in the correct location.

Since
QGIS 3.14

Definition at line 548 of file qgsgdalutils.cpp.

◆ rpcAwareCreateTransformer()

void * QgsGdalUtils::rpcAwareCreateTransformer ( GDALDatasetH  hSrcDS,
GDALDatasetH  hDstDS = nullptr,
char **  papszOptions = nullptr 
)
static

This is a wrapper around GDALCreateGenImgProjTransformer2() that takes into account RPC georeferencing (it sets RPC_HEIGHT in GDALCreateGenImgProjTransformer2 based on HEIGHT_OFF).

By default GDAL would assume that the imagery has zero elevation - if that is not the case, the image would not be shown in the correct location.

Since
QGIS 3.16

Definition at line 568 of file qgsgdalutils.cpp.

◆ setupProxy()

void QgsGdalUtils::setupProxy ( )
static

Sets the gdal proxy variables.

Definition at line 678 of file qgsgdalutils.cpp.

◆ supportsRasterCreate()

bool QgsGdalUtils::supportsRasterCreate ( GDALDriverH  driver)
static

Reads whether a driver supports GDALCreate() for raster purposes.

Parameters
driverGDAL driver
Returns
true if a driver supports GDALCreate() for raster purposes.

Definition at line 162 of file qgsgdalutils.cpp.

◆ validateCreationOptionsFormat()

QString QgsGdalUtils::validateCreationOptionsFormat ( const QStringList &  createOptions,
const QString &  format 
)
static

Validates creation options for a given format, regardless of layer.

Since
QGIS 3.10

Definition at line 532 of file qgsgdalutils.cpp.

◆ vrtMatchesLayerType()

bool QgsGdalUtils::vrtMatchesLayerType ( const QString &  vrtPath,
Qgis::LayerType  type 
)
static

Returns true if the VRT file at the specified path is a VRT matching the given layer type.

Since
QGIS 3.22

Definition at line 1017 of file qgsgdalutils.cpp.

◆ vsiArchiveFileExtensions()

QStringList QgsGdalUtils::vsiArchiveFileExtensions ( )
static

Returns a list of file extensions which correspond to archive style containers supported by GDAL (e.g.

"zip").

Since
QGIS 3.32

Definition at line 945 of file qgsgdalutils.cpp.

◆ vsiArchivePrefixes()

QStringList QgsGdalUtils::vsiArchivePrefixes ( )
static

Returns a list of vsi prefixes which correspond to archive style containers (eg vsizip).

Since
QGIS 3.32

Definition at line 881 of file qgsgdalutils.cpp.

◆ vsiHandlerType()

Qgis::VsiHandlerType QgsGdalUtils::vsiHandlerType ( const QString &  prefix)
static

Returns the VSI handler type for a given VSI prefix.

Since
QGIS 3.40

Definition at line 971 of file qgsgdalutils.cpp.

◆ vsiNetworkFileSystems()

QList< QgsGdalUtils::VsiNetworkFileSystemDetails > QgsGdalUtils::vsiNetworkFileSystems ( )
static

Returns a list of available GDAL VSI network file systems.

Since
QGIS 3.40

Definition at line 894 of file qgsgdalutils.cpp.

◆ vsiPrefixForPath()

QString QgsGdalUtils::vsiPrefixForPath ( const QString &  path)
static

Returns a the vsi prefix which corresponds to a file path, or an empty string if the path is not associated with a vsi prefix.

Since
QGIS 3.32

Definition at line 841 of file qgsgdalutils.cpp.

Friends And Related Symbol Documentation

◆ TestQgsGdalUtils

friend class TestQgsGdalUtils
friend

Definition at line 378 of file qgsgdalutils.h.


The documentation for this class was generated from the following files: