2017-06-01 15:39:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/raster/qgsrasterlayer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
typedef QList < QPair< QString, QColor > > QgsLegendColorList;
2007-01-09 02:39:15 +00:00
class QgsRasterLayer : QgsMapLayer
{
2017-06-01 15:39:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
This class provides qgis with the ability to render raster datasets
onto the mapcanvas.
The qgsrasterlayer class makes use of gdal for data io, and thus supports
any gdal supported format. The constructor attempts to infer what type of
file (LayerType) is being opened - not in terms of the file format (tif, ascii grid etc.)
but rather in terms of whether the image is a GRAYSCALE, PaletteD or Multiband,
Within the three allowable raster layer types, there are 8 permutations of
how a layer can actually be rendered. These are defined in the DrawingStyle enum
and consist of:
SingleBandGray -> a GRAYSCALE layer drawn as a range of gray colors (0-255)
SingleBandPseudoColor -> a GRAYSCALE layer drawn using a pseudocolor algorithm
PalettedSingleBandGray -> a PaletteD layer drawn in gray scale (using only one of the color components)
PalettedSingleBandPseudoColor -> a PaletteD layer having only one of its color components rendered as pseudo color
PalettedMultiBandColor -> a PaletteD image where the bands contains 24bit color info and 8 bits is pulled out per color
MultiBandSingleBandGray -> a layer containing 2 or more bands, but using only one band to produce a grayscale image
MultiBandSingleBandPseudoColor -> a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
MultiBandColor -> a layer containing 2 or more bands, mapped to the three RGBcolors. In the case of a multiband with only two bands, one band will have to be mapped to more than one color
Each of the above mentioned drawing styles is implemented in its own draw* function.
Some of the drawing styles listed above require statistics about the layer such
as the min / max / mean / stddev etc. statistics for a band can be gathered using the
bandStatistics function. Note that statistics gathering is a slow process and
every effort should be made to call this function as few times as possible. For this
reason, qgsraster has a vector class member to store stats for each band. The
constructor initializes this vector on startup, but only populates the band name and
number fields.
Note that where bands are of gdal 'undefined' type, their values may exceed the
renderable range of 0-255. Because of this a linear scaling histogram enhanceContrast is
applied to undefined layers to normalise the data into the 0-255 range.
A qgsrasterlayer band can be referred to either by name or by number (base=1). It
should be noted that band names as stored in datafiles may not be unique, and
so the rasterlayer class appends the band number in brackets behind each band name.
Sample usage of the QgsRasterLayer class:
2019-02-26 12:56:14 +00:00
In order to automate redrawing of a raster layer, you should link it to a map canvas like this :
2017-12-15 10:36:55 -04:00
Once a layer has been created you can find out what type of layer it is (GrayOrUndefined, Palette or Multiband):
2017-12-19 16:36:51 -04:00
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
Raster layers can also have an arbitrary level of transparency defined, and have their
color palettes inverted using the setTransparency and setInvertHistogram methods.
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
Pseudocolor images can have their output adjusted to a given number of standard
deviations using the setStandardDeviations method.
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
The final area of functionality you may be interested in is band mapping. Band mapping
allows you to choose arbitrary band -> color mappings and is applicable only to Palette
and Multiband rasters, There are four mappings that can be made: red, green, blue and gray.
Mappings are non-exclusive. That is a given band can be assigned to no, some or all
color mappings. The constructor sets sensible defaults for band mappings but these can be
overridden at run time using the setRedBandName, setGreenBandName, setBlueBandName and setGrayBandName
methods.
2007-01-09 02:39:15 +00:00
%End
2017-06-01 15:39:31 +02:00
%TypeHeaderCode
#include "qgsrasterlayer.h"
%End
2012-09-24 02:28:15 +02:00
public:
static const double SAMPLE_SIZE;
2017-06-01 15:39:31 +02:00
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM;
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM;
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM;
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS;
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS;
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS;
2012-09-24 02:28:15 +02:00
QgsRasterLayer();
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
Constructor. Provider is not set.
2017-06-01 15:39:31 +02:00
%End
2012-09-24 02:28:15 +02:00
2017-11-04 07:54:31 +10:00
struct LayerOptions
{
2019-03-27 16:00:02 +01:00
explicit LayerOptions( bool loadDefaultStyle = true,
const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() );
2017-11-04 07:54:31 +10:00
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for LayerOptions.
2017-11-04 07:54:31 +10:00
%End
bool loadDefaultStyle;
2019-03-22 11:55:16 +01:00
2019-03-22 16:55:30 +01:00
QgsCoordinateTransformContext transformContext;
2019-03-22 11:55:16 +01:00
2017-11-04 07:54:31 +10:00
};
explicit QgsRasterLayer( const QString &uri,
const QString &baseName = QString(),
2018-10-30 13:40:18 +01:00
const QString &providerType = "gdal",
2017-11-04 07:54:31 +10:00
const QgsRasterLayer::LayerOptions &options = QgsRasterLayer::LayerOptions() );
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
This is the constructor for the RasterLayer class.
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
The main tasks carried out by the constructor are:
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
-Load the rasters default style (.qml) file if it exists
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
-Populate the RasterStatsVector with initial values for each band.
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
-Calculate the layer extents
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
-Determine whether the layer is gray, paletted or multiband.
2017-06-01 15:39:31 +02:00
2017-12-15 10:36:55 -04:00
-Assign sensible defaults for the red, green, blue and gray bands.
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2007-01-09 02:39:15 +00:00
~QgsRasterLayer();
2017-05-17 08:53:52 +02:00
virtual QgsRasterLayer *clone() const /Factory/;
2017-12-15 08:57:22 +10:00
2017-06-01 15:39:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns a new instance equivalent to this one. A new provider is
created for the same data source and renderer is cloned too.
:return: a new layer instance
2017-06-01 15:39:31 +02:00
.. versionadded:: 3.0
%End
2017-05-16 13:34:18 +02:00
2008-11-05 22:44:50 +00:00
enum ColorShadingAlgorithm
{
2008-11-06 15:16:08 +00:00
UndefinedShader,
PseudoColorShader,
FreakOutShader,
ColorRampShader,
UserDefinedShader
2008-11-05 22:44:50 +00:00
};
enum LayerType
{
GrayOrUndefined,
Palette,
2012-09-24 02:28:15 +02:00
Multiband,
ColorLayer
};
2008-11-05 22:44:50 +00:00
2017-05-03 07:45:22 +02:00
static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
2017-06-01 15:39:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
This helper checks to see whether the file name appears to be a valid
raster file name. If the file name looks like it could be valid,
but some sort of error occurs in processing the file, the error is
2018-04-03 09:49:00 +10:00
returned in ``retError``.
2017-06-01 15:39:31 +02:00
%End
2018-04-03 09:49:00 +10:00
2017-05-03 07:45:22 +02:00
static bool isValidRasterFileName( const QString &fileNameQString );
2007-01-09 02:39:15 +00:00
2017-06-01 15:39:31 +02:00
static QDateTime lastModified( const QString &name );
%Docstring
2018-05-25 13:54:27 +10:00
Returns time stamp for given file name
2017-06-01 15:39:31 +02:00
%End
2008-01-11 06:38:10 +00:00
2018-05-21 11:10:34 +10:00
void setDataProvider( const QString &provider ) /Deprecated/;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-21 11:10:34 +10:00
Set the data provider.
.. deprecated:: Use the version with ProviderOptions instead.
%End
void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
%Docstring
Set the data provider.
:param provider: provider key string, must match a valid QgsRasterDataProvider key. E.g. "gdal", "wms", etc.
:param options: provider options
.. versionadded:: 3.2
2018-10-30 13:40:18 +01:00
%End
virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.
:param dataSource: new layer data source
:param baseName: base name of the layer
:param provider: provider string
:param options: provider options
2019-02-26 19:54:09 +10:00
:param loadDefaultStyleFlag: set to ``True`` to reset the layer's style to the default for the
2018-10-30 13:40:18 +01:00
data source
.. seealso:: :py:func:`dataSourceChanged`
.. versionadded:: 3.6
2017-06-01 15:39:31 +02:00
%End
2012-09-24 02:28:15 +02:00
2008-11-05 22:44:50 +00:00
LayerType rasterType();
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the raster layer type (which is a read only property).
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2017-05-01 18:13:15 +02:00
void setRenderer( QgsRasterRenderer *renderer /Transfer/ );
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-25 13:54:27 +10:00
Sets raster renderer. Takes ownership of the renderer object
2017-06-01 15:39:31 +02:00
%End
2017-05-01 18:13:15 +02:00
QgsRasterRenderer *renderer() const;
2012-05-01 23:09:29 +02:00
2017-05-03 07:45:22 +02:00
QgsRasterResampleFilter *resampleFilter() const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-25 13:54:27 +10:00
Sets raster resample filter. Takes ownership of the resample filter object
2017-06-01 15:39:31 +02:00
%End
2012-09-24 02:28:15 +02:00
2017-05-03 07:45:22 +02:00
QgsBrightnessContrastFilter *brightnessFilter() const;
QgsHueSaturationFilter *hueSaturationFilter() const;
2013-09-09 09:47:05 +02:00
2017-05-03 07:45:22 +02:00
QgsRasterPipe *pipe();
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the raster pipe.
2017-06-01 15:39:31 +02:00
%End
2012-09-13 15:08:23 +02:00
2014-01-27 09:22:24 +01:00
int width() const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the width of the (unclipped) raster.
.. seealso:: :py:func:`height`
2017-06-01 15:39:31 +02:00
%End
2014-01-27 09:22:24 +01:00
int height() const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the height of the (unclipped) raster.
.. seealso:: :py:func:`width`
2017-06-01 15:39:31 +02:00
%End
2014-01-27 09:22:24 +01:00
int bandCount() const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the number of bands in this layer.
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2017-02-21 18:14:58 +01:00
QString bandName( int bandNoInt ) const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 17:01:58 +10:00
Returns the name of a band given its number.
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2017-05-01 18:13:15 +02:00
virtual QgsRasterDataProvider *dataProvider();
2008-11-05 22:44:50 +00:00
2017-06-01 15:39:31 +02:00
2017-05-01 18:13:15 +02:00
virtual const QgsRasterDataProvider *dataProvider() const /PyName=constDataProvider/;
2008-11-05 22:44:50 +00:00
2017-06-01 15:39:31 +02:00
2010-09-20 11:27:12 +00:00
virtual void reload();
2017-12-15 08:57:22 +10:00
2017-05-01 18:13:15 +02:00
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;
2017-12-15 08:57:22 +10:00
2013-12-05 18:27:45 +07:00
2017-06-01 15:39:31 +02:00
void draw( QPainter *theQPainter,
QgsRasterViewPort *myRasterViewPort,
2017-05-01 18:13:15 +02:00
const QgsMapToPixel *qgsMapToPixel = 0 );
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2017-06-01 15:39:31 +02:00
QgsLegendColorList legendSymbologyItems() const;
%Docstring
Returns a list with classification items (Text and color)
%End
2012-09-24 02:28:15 +02:00
2016-03-16 12:35:45 +11:00
virtual bool isSpatial() const;
2017-06-01 15:39:31 +02:00
virtual QString htmlMetadata() const;
2008-11-05 22:44:50 +00:00
2017-02-21 18:14:58 +01:00
QPixmap paletteAsPixmap( int bandNumber = 1 );
2017-06-01 15:39:31 +02:00
%Docstring
2018-04-03 09:49:00 +10:00
Returns a 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned
:param bandNumber: the number of the band to use for generating a pixmap of the associated palette
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2011-09-15 11:47:10 +02:00
QString providerType() const;
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
[ data provider interface ] Which provider is being used for this Raster Layer?
2017-06-01 15:39:31 +02:00
%End
2011-09-15 11:47:10 +02:00
2017-06-01 15:39:31 +02:00
double rasterUnitsPerPixelX() const;
%Docstring
2018-04-03 09:49:00 +10:00
Returns the number of raster units per each raster pixel in X axis.
In a world file, this is normally the first row (without the sign). (E.g.
the value reported by the GDAL geotransform[1]).
.. seealso:: :py:func:`rasterUnitsPerPixelY`
2017-06-01 15:39:31 +02:00
%End
2018-04-03 09:49:00 +10:00
2017-06-01 15:39:31 +02:00
double rasterUnitsPerPixelY() const;
%Docstring
2018-04-03 09:49:00 +10:00
Returns the number of raster units per each raster pixel in Y axis.
In a world file, this is normally the first row (without the sign).
.. seealso:: :py:func:`rasterUnitsPerPixelX`
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2012-09-24 02:28:15 +02:00
2008-11-05 22:44:50 +00:00
2017-02-21 18:14:58 +01:00
void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax,
2017-06-01 15:39:31 +02:00
const QgsRectangle &extent = QgsRectangle(),
2017-02-21 18:14:58 +01:00
int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
bool generateLookupTableFlag = true );
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
Set contrast enhancement algorithm
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param algorithm: Contrast enhancement algorithm
:param limits: Limits
:param extent: Extent used to calculate limits, if empty, use full layer extent
:param sampleSize: Size of data sample to calculate limits, if 0, use full resolution
:param generateLookupTableFlag: Generate lookup table. *
2017-06-01 15:39:31 +02:00
%End
2008-11-05 22:44:50 +00:00
2012-09-24 02:28:15 +02:00
void setDefaultContrastEnhancement();
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-25 13:54:27 +10:00
Sets the default contrast enhancement
2017-06-01 15:39:31 +02:00
%End
2012-09-24 02:28:15 +02:00
virtual QStringList subLayers() const;
2017-12-15 08:57:22 +10:00
2008-11-05 22:44:50 +00:00
2017-06-01 15:39:31 +02:00
QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
2014-02-24 12:20:17 -03:00
QImage::Format format = QImage::Format_ARGB32_Premultiplied );
2017-06-01 15:39:31 +02:00
%Docstring
2018-05-26 14:10:30 +10:00
Draws a preview of the rasterlayer into a QImage
2017-12-15 10:36:55 -04:00
2017-06-01 15:39:31 +02:00
.. versionadded:: 2.4
%End
2014-02-24 12:20:17 -03:00
2012-09-24 02:28:15 +02:00
virtual void setLayerOrder( const QStringList &layers );
2017-12-15 08:57:22 +10:00
2017-05-01 18:13:15 +02:00
virtual void setSubLayerVisibility( const QString &name, bool vis );
2017-12-15 08:57:22 +10:00
2012-09-24 02:28:15 +02:00
virtual QDateTime timestamp() const;
2017-12-15 08:57:22 +10:00
2019-07-03 14:57:40 +10:00
virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
2007-01-09 02:39:15 +00:00
2019-02-01 18:13:05 +01:00
bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const;
2018-12-18 19:03:02 +01:00
%Docstring
Writes the symbology of the layer into the document provided in SLD 1.0.0 format
:param node: the node that will have the style element added to it.
:param doc: the document that will have the QDomNode added.
:param errorMessage: reference to string that will be updated with any error messages
:param props: a open ended set of properties that can drive/inform the SLD encoding
2019-02-26 19:54:09 +10:00
:return: ``True`` in case of success
2018-12-18 19:03:02 +01:00
.. versionadded:: 3.6
%End
2008-11-05 22:44:50 +00:00
public slots:
2017-05-03 07:45:22 +02:00
void showStatusMessage( const QString &message );
2008-01-11 06:38:10 +00:00
2019-03-22 16:55:30 +01:00
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
2019-03-22 11:55:16 +01:00
%Docstring
2019-04-08 16:40:35 +02:00
Sets the coordinate transform context to ``transformContext``
2019-03-22 11:55:16 +01:00
2019-04-08 16:40:35 +02:00
.. versionadded:: 3.8
2019-03-22 11:55:16 +01:00
%End
2017-06-01 15:39:31 +02:00
protected:
2018-09-13 14:11:31 -04:00
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
2007-01-09 02:39:15 +00:00
2018-09-13 14:11:31 -04:00
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
2007-01-09 02:39:15 +00:00
2018-02-06 13:37:28 -04:00
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2017-06-01 15:39:31 +02:00
2018-09-07 14:32:59 -04:00
virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
2018-09-13 14:11:31 -04:00
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
2018-09-07 14:32:59 -04:00
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
2018-09-13 14:11:31 -04:00
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
2017-06-01 15:39:31 +02:00
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
2018-05-03 12:10:54 +02:00
virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const;
2016-05-10 10:32:30 +10:00
2007-01-09 02:39:15 +00:00
};
2017-09-25 14:20:39 +10:00
2017-06-01 15:39:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/raster/qgsrasterlayer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/