QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
qgsgdalutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgdalutils.h
3 --------------
4 begin : September 2018
5 copyright : (C) 2018 Even Rouault
6 email : even.rouault at spatialys.com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSGDALUTILS_H
17#define QGSGDALUTILS_H
18
19
20#include <gdal.h>
21
22#include "qgis_core.h"
23#include "qgsfeedback.h"
24#include "qgsogrutils.h"
25
26class QgsRasterBlock;
27
28#ifndef SIP_RUN
37class CORE_EXPORT QgsGdalOption
38{
39 public:
43 enum class Type
44 {
45 Invalid,
46 Select,
47 Boolean,
48 Text,
49 Int,
50 Double,
51 };
52
54 QString name;
55
58
60 QString description;
61
63 QStringList options;
64
66 QVariant defaultValue;
67
69 QVariant minimum;
70
72 QVariant maximum;
73
75 QString scope;
76
83 static QgsGdalOption fromXmlNode( const CPLXMLNode *node );
84
88 static QList< QgsGdalOption > optionsFromXml( const CPLXMLNode *node );
89};
90#endif
91
99class CORE_EXPORT QgsGdalUtils
100{
101 public:
107 SIP_SKIP static bool supportsRasterCreate( GDALDriverH driver );
108
113 SIP_SKIP static gdal::dataset_unique_ptr createSingleBandMemoryDataset( GDALDataType dataType, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs );
114
119 SIP_SKIP static gdal::dataset_unique_ptr createMultiBandMemoryDataset( GDALDataType dataType, int bands, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs );
120
126 const QString &filename, GDALDataType dataType, const QgsRectangle &extent, int width, int height, const QgsCoordinateReferenceSystem &crs
127 );
128
139 SIP_SKIP static bool resampleSingleBandRaster( GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg, const char *pszCoordinateOperation );
140
153 GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg, const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs
154 );
155
160 SIP_SKIP static QImage resampleImage( const QImage &image, QSize outputSize, GDALRIOResampleAlg resampleAlg );
161
166 SIP_SKIP static QString helpCreationOptionsFormat( const QString &format );
167
172 SIP_SKIP static QString validateCreationOptionsFormat( const QStringList &creationOptions, const QString &format );
173
178 SIP_SKIP static char **papszFromStringList( const QStringList &list );
179
187 SIP_SKIP static gdal::dataset_unique_ptr imageToMemoryDataset( const QImage &image );
188
196 SIP_SKIP static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset( int pixelWidth, int pixelHeight, const QgsRectangle &extent, void *block, GDALDataType dataType );
197
206
215 SIP_SKIP static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset( double rotation, const QgsPointXY &origin, double gridXSize, double gridYSize, QgsRasterBlock *block );
216
226 GDALDatasetH hSrcDS, const char *pszSrcWKT, const char *pszDstWKT, GDALResampleAlg eResampleAlg, double dfMaxError, const GDALWarpOptions *psOptionsIn
227 );
228
237 SIP_SKIP static void *rpcAwareCreateTransformer( GDALDatasetH hSrcDS, GDALDatasetH hDstDS = nullptr, char **papszOptions = nullptr );
238
244 SIP_SKIP static GDALDataType gdalDataTypeFromQgisDataType( Qgis::DataType dataType );
245
251 SIP_SKIP static GDALResampleAlg gdalResamplingAlgorithm( Qgis::RasterResamplingMethod method );
252
253#ifndef QT_NO_NETWORKPROXY
255 SIP_SKIP static void setupProxy();
256#endif
257
272 SIP_SKIP static bool pathIsCheapToOpen( const QString &path, int smallFileSizeLimit = 50000 );
273
280 SIP_SKIP static QStringList multiLayerFileExtensions();
281
288 SIP_SKIP static QString vsiPrefixForPath( const QString &path );
289
295 SIP_SKIP static QStringList vsiArchivePrefixes();
296
297#ifndef SIP_RUN
304 {
306 QString identifier;
307
309 QString name;
310 };
311#endif
312
318 SIP_SKIP static QList< VsiNetworkFileSystemDetails > vsiNetworkFileSystems();
319
325 SIP_SKIP static bool isVsiArchivePrefix( const QString &prefix );
326
332 SIP_SKIP static QStringList vsiArchiveFileExtensions();
333
339 SIP_SKIP static bool isVsiArchiveFileExtension( const QString &extension );
340
346 SIP_SKIP static Qgis::VsiHandlerType vsiHandlerType( const QString &prefix );
347
358 SIP_SKIP static bool applyVsiCredentialOptions( const QString &prefix, const QString &path, const QVariantMap &options );
359
366 SIP_SKIP static bool vrtMatchesLayerType( const QString &vrtPath, Qgis::LayerType type );
367
373 SIP_SKIP static QString gdalDocumentationUrlForDriver( GDALDriverH hDriver );
374
381 static bool supportsTiffLercCompression();
382
389 static bool supportsMrfLercCompression();
390
391 private:
392 friend class TestQgsGdalUtils;
393};
394
395#ifndef SIP_RUN
410class CORE_EXPORT QgsGdalProgressAdapter
411{
412 public:
419 explicit QgsGdalProgressAdapter( QgsFeedback *feedback, double startPercentage = 0.0, double endPercentage = 100.0 );
420
424 static int CPL_STDCALL progressCallback( double dfComplete, const char *pszMessage, void *pProgressArg );
425
426 private:
427 QgsFeedback *mFeedback = nullptr;
428 double mStartPercentage;
429 double mEndPercentage;
430};
431#endif
432#endif // QGSGDALUTILS_H
VsiHandlerType
GDAL VSI handler types.
Definition qgis.h:6256
RasterResamplingMethod
Resampling method for raster provider-level resampling.
Definition qgis.h:1603
DataType
Raster data types.
Definition qgis.h:393
LayerType
Types of layers that can be added to a map.
Definition qgis.h:206
Represents a coordinate reference system (CRS).
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Encapsulates the definition of a GDAL configuration option.
QVariant defaultValue
Default value.
QVariant maximum
Maximum acceptable value.
QString name
Option name.
QStringList options
Available choices, for Select options.
QVariant minimum
Minimum acceptable value.
Type
Option types.
@ Invalid
Invalid option.
QString scope
Option scope.
static QList< QgsGdalOption > optionsFromXml(const CPLXMLNode *node)
Returns a list of all GDAL options from an XML node.
static QgsGdalOption fromXmlNode(const CPLXMLNode *node)
Creates a QgsGdalOption from an XML node.
QString description
Option description.
Type type
Option type.
QgsGdalProgressAdapter(QgsFeedback *feedback, double startPercentage=0.0, double endPercentage=100.0)
Constructor from feedback (which may be NULL).
static int CPL_STDCALL progressCallback(double dfComplete, const char *pszMessage, void *pProgressArg)
GDAL progress callback.
Utilities for working with GDAL.
static Qgis::VsiHandlerType vsiHandlerType(const QString &prefix)
Returns the VSI handler type for a given VSI prefix.
static bool applyVsiCredentialOptions(const QString &prefix, const QString &path, const QVariantMap &options)
Attempts to apply VSI credential options.
static bool pathIsCheapToOpen(const QString &path, int smallFileSizeLimit=50000)
Returns true if the dataset at the specified path is considered "cheap" to open.
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 asso...
static QString helpCreationOptionsFormat(const QString &format)
Gets creation options metadata for a given format.
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 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 wit...
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 se...
static bool supportsTiffLercCompression()
Returns true if the GDAL library used by this QGIS install supports the LERC compression technique fo...
static bool supportsRasterCreate(GDALDriverH driver)
Reads whether a driver supports GDALCreate() for raster purposes.
static bool isVsiArchiveFileExtension(const QString &extension)
Returns true if a file extension is a supported archive style container (e.g.
static GDALResampleAlg gdalResamplingAlgorithm(Qgis::RasterResamplingMethod method)
Returns the GDAL resampling method corresponding to the QGIS resampling method.
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 bool isVsiArchivePrefix(const QString &prefix)
Returns true if prefix is a supported archive style container prefix (e.g.
static QString gdalDocumentationUrlForDriver(GDALDriverH hDriver)
Returns the URL for the GDAL documentation for the specified driver.
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 blockToSingleBandMemoryDataset(int pixelWidth, int pixelHeight, const QgsRectangle &extent, void *block, GDALDataType dataType)
Converts a data block to a single band GDAL memory dataset.
static QList< VsiNetworkFileSystemDetails > vsiNetworkFileSystems()
Returns a list of available GDAL VSI network file systems.
static QString validateCreationOptionsFormat(const QStringList &creationOptions, const QString &format)
Validates creation options for a given format, regardless of layer.
static bool supportsMrfLercCompression()
Returns true if the GDAL library used by this QGIS install supports the LERC compression technique fo...
static gdal::dataset_unique_ptr imageToMemoryDataset(const QImage &image)
Converts an image to a GDAL memory dataset by borrowing image data.
static void * rpcAwareCreateTransformer(GDALDatasetH hSrcDS, GDALDatasetH hDstDS=nullptr, char **papszOptions=nullptr)
This is a wrapper around GDALCreateGenImgProjTransformer2() that takes into account RPC georeferencin...
static void setupProxy()
Sets the gdal proxy variables.
friend class TestQgsGdalUtils
static QStringList vsiArchiveFileExtensions()
Returns a list of file extensions which correspond to archive style containers supported by GDAL (e....
static char ** papszFromStringList(const QStringList &list)
Helper function.
static QImage resampleImage(const QImage &image, QSize outputSize, GDALRIOResampleAlg resampleAlg)
Resamples a QImage image using GDAL resampler.
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 QStringList multiLayerFileExtensions()
Returns a list of file extensions which potentially contain multiple layers representing GDAL raster ...
static QStringList vsiArchivePrefixes()
Returns a list of vsi prefixes which correspond to archive style containers (eg vsizip).
Represents a 2D point.
Definition qgspointxy.h:62
Raster data container.
A rectangle specified with double values.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
#define SIP_SKIP
Definition qgis_sip.h:133
void * GDALDatasetH
Encapsulates details for a GDAL VSI network file system.
QString name
Translated, user-friendly name.
QString identifier
VSI handler identifier, eg "vsis3".