QGIS API Documentation  3.0.2-Girona (307d082)
Classes | Public Types | Public Slots | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
QgsRasterLayer Class Reference

This class provides qgis with the ability to render raster datasets onto the mapcanvas. More...

#include <qgsrasterlayer.h>

Inheritance diagram for QgsRasterLayer:
Inheritance graph
[legend]

Classes

struct  LayerOptions
 Setting options for loading raster layers. More...
 

Public Types

enum  ColorShadingAlgorithm {
  UndefinedShader, PseudoColorShader, FreakOutShader, ColorRampShader,
  UserDefinedShader
}
 This enumerator describes the types of shading that can be used. More...
 
enum  LayerType { GrayOrUndefined, Palette, Multiband, ColorLayer }
 This enumerator describes the type of raster layer. More...
 
- Public Types inherited from QgsMapLayer
enum  LayerType { VectorLayer, RasterLayer, PluginLayer }
 Types of layers that can be added to a map. More...
 
enum  PropertyType { Style = 0, Metadata }
 Maplayer has a style and a metadata property. More...
 

Public Slots

void showStatusMessage (const QString &message)
 
- Public Slots inherited from QgsMapLayer
void emitStyleChanged ()
 Triggers an emission of the styleChanged() signal. More...
 
virtual bool setDependencies (const QSet< QgsMapLayerDependency > &layers)
 Sets the list of dependencies. More...
 
void setMaximumScale (double scale)
 Sets the maximum map scale (i.e. More...
 
void setMinimumScale (double scale)
 Sets the minimum map scale (i.e. More...
 
void setRefreshOnNofifyMessage (const QString &message)
 Set the notification message that triggers repaine If refresh on notification is enabled, the notification will triggerRepaint only if the notification message is equal to. More...
 
void setRefreshOnNotifyEnabled (bool enabled)
 Set whether provider notification is connected to triggerRepaint. More...
 
void setScaleBasedVisibility (const bool enabled)
 Sets whether scale based visibility is enabled for the layer. More...
 
void triggerRepaint (bool deferredUpdate=false)
 Will advise the map canvas (and any other interested party) that this layer requires to be repainted. More...
 

Public Member Functions

 QgsRasterLayer ()
 Constructor. Provider is not set. More...
 
 QgsRasterLayer (const QString &uri, const QString &baseName=QString(), const QString &providerKey="gdal", const QgsRasterLayer::LayerOptions &options=QgsRasterLayer::LayerOptions())
 This is the constructor for the RasterLayer class. More...
 
 ~QgsRasterLayer () override
 
int bandCount () const
 Get the number of bands in this layer. More...
 
QString bandName (int bandNoInt) const
 Get the name of a band given its number. More...
 
QgsBrightnessContrastFilterbrightnessFilter () const
 
QgsRasterLayerclone () const override
 Returns a new instance equivalent to this one. More...
 
QgsMapLayerRenderercreateMapRenderer (QgsRenderContext &rendererContext) override
 Return new instance of QgsMapLayerRenderer that will be used for rendering of given context. More...
 
QgsRasterDataProviderdataProvider () override
 
const QgsRasterDataProviderdataProvider () const override
 Returns the data provider in a const-correct manner. More...
 
bool defaultContrastEnhancementSettings (QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
 Return default contrast enhancemnt settings for that type of raster. More...
 
void draw (QPainter *theQPainter, QgsRasterViewPort *myRasterViewPort, const QgsMapToPixel *qgsMapToPixel=nullptr)
 This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap. More...
 
int height () const
 Accessor that returns the height of the (unclipped) raster. More...
 
QString htmlMetadata () const override
 Obtain a formatted HTML string containing assorted metadata for this layer. More...
 
QgsHueSaturationFilterhueSaturationFilter () const
 
bool isSpatial () const override
 Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated with it. More...
 
QgsLegendColorList legendSymbologyItems () const
 Returns a list with classification items (Text and color) More...
 
QPixmap paletteAsPixmap (int bandNumber=1)
 Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned. More...
 
QgsRasterPipepipe ()
 Get raster pipe. More...
 
QImage previewAsImage (QSize size, const QColor &bgColor=Qt::white, QImage::Format format=QImage::Format_ARGB32_Premultiplied)
 Draws a preview of the rasterlayer into a QImage. More...
 
QString providerType () const
 [ data provider interface ] Which provider is being used for this Raster Layer? More...
 
LayerType rasterType ()
 Accessor for raster layer type (which is a read only property) More...
 
double rasterUnitsPerPixelX () const
 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) More...
 
double rasterUnitsPerPixelY () const
 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) More...
 
void refreshContrastEnhancement (const QgsRectangle &extent)
 Refresh contrast enhancement with new extent. More...
 
void refreshRendererIfNeeded (QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
 Refresh renderer with new extent, if needed. More...
 
void reload () override
 Synchronises with changes in the datasource. More...
 
QgsRasterRendererrenderer () const
 
QgsRasterResampleFilterresampleFilter () const
 Set raster resample filter. Takes ownership of the resample filter object. More...
 
void setContrastEnhancement (QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits=QgsRasterMinMaxOrigin::MinMax, const QgsRectangle &extent=QgsRectangle(), int sampleSize=QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag=true)
 Set contrast enhancement algorithm. More...
 
void setDataProvider (const QString &provider)
 [ data provider interface ] Set the data provider More...
 
void setDefaultContrastEnhancement ()
 Set default contrast enhancement. More...
 
void setLayerOrder (const QStringList &layers) override
 Reorders the previously selected sublayers of this layer from bottom to top. More...
 
void setRenderer (QgsRasterRenderer *renderer)
 Set raster renderer. Takes ownership of the renderer object. More...
 
void setSubLayerVisibility (const QString &name, bool vis) override
 Set the visibility of the given sublayer name. More...
 
QStringList subLayers () const override
 Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS. More...
 
QDateTime timestamp () const override
 Time stamp of data source in the moment when data/metadata were loaded by provider. More...
 
int width () const
 Accessor that returns the width of the (unclipped) raster. More...
 
- Public Member Functions inherited from QgsMapLayer
 QgsMapLayer (QgsMapLayer::LayerType type=VectorLayer, const QString &name=QString(), const QString &source=QString())
 Constructor for QgsMapLayer. More...
 
 QgsMapLayer (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied. More...
 
 ~QgsMapLayer () override
 
QString abstract () const
 Returns the abstract of the layer used by QGIS Server in GetCapabilities request. More...
 
QString attribution () const
 Returns the attribution of the layer used by QGIS Server in GetCapabilities request. More...
 
QString attributionUrl () const
 Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request. More...
 
int autoRefreshInterval () const
 Returns the auto refresh interval (in milliseconds). More...
 
QPainter::CompositionMode blendMode () const
 Returns the current blending mode for a layer. More...
 
QgsCoordinateReferenceSystem crs () const
 Returns the layer's spatial reference system. More...
 
QVariant customProperty (const QString &value, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer. More...
 
QStringList customPropertyKeys () const
 Returns list of all keys within custom properties. More...
 
QString dataUrl () const
 Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request. More...
 
QString dataUrlFormat () const
 Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request. More...
 
virtual QSet< QgsMapLayerDependencydependencies () const
 Gets the list of dependencies. More...
 
virtual QgsError error () const
 Get current status error. More...
 
void exportNamedMetadata (QDomDocument &doc, QString &errorMsg) const
 Export the current metadata of this layer as named metadata in a QDomDocument. More...
 
virtual void exportNamedStyle (QDomDocument &doc, QString &errorMsg) const
 Export the properties of this layer as named style in a QDomDocument. More...
 
virtual void exportSldStyle (QDomDocument &doc, QString &errorMsg) const
 Export the properties of this layer as SLD style in a QDomDocument. More...
 
virtual QgsRectangle extent () const
 Returns the extent of the layer. More...
 
bool hasAutoRefreshEnabled () const
 Returns true if auto refresh is enabled for the layer. More...
 
bool hasScaleBasedVisibility () const
 Returns whether scale based visibility is enabled for the layer. More...
 
QString id () const
 Returns the layer's unique ID, which is used to access this layer from QgsProject. More...
 
bool importNamedMetadata (QDomDocument &document, QString &errorMessage)
 Import the metadata of this layer from a QDomDocument. More...
 
virtual bool importNamedStyle (QDomDocument &doc, QString &errorMsg)
 Import the properties of this layer from a QDomDocument. More...
 
virtual bool isEditable () const
 Returns true if the layer can be edited. More...
 
bool isInScaleRange (double scale) const
 Tests whether the layer should be visible at the specified scale. More...
 
bool isRefreshOnNotifyEnabled () const
 Returns true if the refresh on provider nofification is enabled. More...
 
bool isValid () const
 Return the status of the layer. More...
 
QString keywordList () const
 Returns the keyword list of the layer used by QGIS Server in GetCapabilities request. More...
 
QgsMapLayerLegendlegend () const
 Can be null. More...
 
QString legendUrl () const
 Returns the URL for the layer's legend. More...
 
QString legendUrlFormat () const
 Returns the format for a URL based layer legend. More...
 
QString loadDefaultMetadata (bool &resultFlag)
 Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users metadata table in their personal qgis.db) More...
 
virtual QString loadDefaultStyle (bool &resultFlag)
 Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db) More...
 
virtual QString loadNamedMetadata (const QString &uri, bool &resultFlag)
 Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db) More...
 
bool loadNamedMetadataFromDatabase (const QString &db, const QString &uri, QString &qmd)
 Retrieve a named metadata for this layer from a sqlite database. More...
 
virtual QString loadNamedStyle (const QString &uri, bool &resultFlag)
 Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db) More...
 
virtual bool loadNamedStyleFromDatabase (const QString &db, const QString &uri, QString &qml)
 Retrieve a named style for this layer from a sqlite database. More...
 
virtual QString loadSldStyle (const QString &uri, bool &resultFlag)
 Attempts to style the layer using the formatting from an SLD type file. More...
 
double maximumScale () const
 Returns the maximum map scale (i.e. More...
 
virtual const QgsLayerMetadatametadata () const
 Returns a reference to the layer's metadata store. More...
 
virtual QString metadataUri () const
 Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db) More...
 
QString metadataUrl () const
 Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request. More...
 
QString metadataUrlFormat () const
 Returns the metadata format of the layer used by QGIS Server in GetCapabilities request. More...
 
QString metadataUrlType () const
 Returns the metadata type of the layer used by QGIS Server in GetCapabilities request. More...
 
double minimumScale () const
 Returns the minimum map scale (i.e. More...
 
QString name () const
 Returns the display name of the layer. More...
 
QgsMapLayeroperator= (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied. More...
 
QString publicSource () const
 Gets a version of the internal layer definition that has sensitive bits removed (for example, the password). More...
 
bool readLayerXml (const QDomElement &layerElement, const QgsReadWriteContext &context)
 Sets state from Dom document. More...
 
bool readOnly () const
 Returns if this layer is read only. More...
 
virtual bool readSld (const QDomNode &node, QString &errorMessage)
 
QString refreshOnNotifyMessage () const
 Returns the message that should be notified by the provider to triggerRepaint. More...
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer. More...
 
QgsAbstract3DRendererrenderer3D () const
 Returns 3D renderer associated with the layer. More...
 
virtual void resolveReferences (QgsProject *project)
 Resolve references to other layers (kept as layer IDs after reading XML) into layer objects. More...
 
virtual QString saveDefaultMetadata (bool &resultFlag)
 Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db) More...
 
virtual QString saveDefaultStyle (bool &resultFlag)
 Save the properties of this layer as the default style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db) More...
 
QString saveNamedMetadata (const QString &uri, bool &resultFlag)
 Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db) More...
 
virtual QString saveNamedStyle (const QString &uri, bool &resultFlag)
 Save the properties of this layer as a named style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db) More...
 
virtual QString saveSldStyle (const QString &uri, bool &resultFlag) const
 Saves the properties of this layer to an SLD format file. More...
 
void setAbstract (const QString &abstract)
 Sets the abstract of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAttribution (const QString &attrib)
 Sets the attribution of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAttributionUrl (const QString &attribUrl)
 Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAutoRefreshEnabled (bool enabled)
 Sets whether auto refresh is enabled for the layer. More...
 
void setAutoRefreshInterval (int interval)
 Sets the auto refresh interval (in milliseconds) for the layer. More...
 
void setBlendMode (QPainter::CompositionMode blendMode)
 Set the blending mode used for rendering a layer. More...
 
void setCrs (const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
 Sets layer's spatial reference system. More...
 
void setCustomProperties (const QgsObjectCustomProperties &properties)
 Set custom properties for layer. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for layer. More...
 
void setDataUrl (const QString &dataUrl)
 Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request. More...
 
void setDataUrlFormat (const QString &dataUrlFormat)
 Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request. More...
 
void setKeywordList (const QString &keywords)
 Sets the keyword list of the layer used by QGIS Server in GetCapabilities request. More...
 
void setLegend (QgsMapLayerLegend *legend)
 Assign a legend controller to the map layer. More...
 
void setLegendUrl (const QString &legendUrl)
 Sets the URL for the layer's legend. More...
 
void setLegendUrlFormat (const QString &legendUrlFormat)
 Sets the format for a URL based layer legend. More...
 
virtual void setMetadata (const QgsLayerMetadata &metadata)
 Sets the layer's metadata store. More...
 
void setMetadataUrl (const QString &metaUrl)
 Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request. More...
 
void setMetadataUrlFormat (const QString &metaUrlFormat)
 Sets the metadata format of the layer used by QGIS Server in GetCapabilities request. More...
 
void setMetadataUrlType (const QString &metaUrlType)
 Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies. More...
 
void setName (const QString &name)
 Set the display name of the layer. More...
 
void setRenderer3D (QgsAbstract3DRenderer *renderer)
 Sets 3D renderer for the layer. More...
 
void setShortName (const QString &shortName)
 Sets the short name of the layer used by QGIS Server to identify the layer. More...
 
void setTitle (const QString &title)
 Sets the title of the layer used by QGIS Server in GetCapabilities request. More...
 
QString shortName () const
 Returns the short name of the layer used by QGIS Server to identify the layer. More...
 
QString source () const
 Returns the source for the layer. More...
 
QgsMapLayerStyleManagerstyleManager () const
 Get access to the layer's style manager. More...
 
virtual QString styleURI () const
 Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users style table in their personal qgis.db) More...
 
QString title () const
 Returns the title of the layer used by QGIS Server in GetCapabilities request. More...
 
QgsMapLayer::LayerType type () const
 Returns the type of the layer. More...
 
QUndoStack * undoStack ()
 Return pointer to layer's undo stack. More...
 
QUndoStack * undoStackStyles ()
 Return pointer to layer's style undo stack. More...
 
bool writeLayerXml (QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
 Stores state in Dom node. More...
 

Static Public Member Functions

static bool isValidRasterFileName (const QString &fileNameQString, QString &retError)
 This helper checks to see whether the file name appears to be a valid raster file name. More...
 
static bool isValidRasterFileName (const QString &fileNameQString)
 
static QDateTime lastModified (const QString &name)
 Return time stamp for given file name. More...
 
- Static Public Member Functions inherited from QgsMapLayer
static QString extensionPropertyType (PropertyType type)
 Returns the extension of a Property. More...
 
static QString formatLayerName (const QString &name)
 A convenience function to capitalize and format a layer name. More...
 

Static Public Attributes

static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::StretchToMinimumMaximum
 Default enhancement algorithm for multiple band raster of type different from Byte. More...
 
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::CumulativeCut
 Default enhancement limits for multiple band raster of type different from Byte. More...
 
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::NoEnhancement
 Default enhancement algorithm for multiple band raster of type Byte. More...
 
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax
 Default enhancement limits for multiple band raster of type Byte. More...
 
static const double SAMPLE_SIZE = 250000
 Default sample size (number of pixels) for estimated statistics/histogram calculation. More...
 
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::StretchToMinimumMaximum
 Default enhancement algorithm for single band raster. More...
 
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax
 Default enhancement limits for single band raster. More...
 

Protected Member Functions

bool readStyle (const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context) override
 Read the style information for the current layer from the Dom node supplied. More...
 
bool readSymbology (const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context) override
 Read the symbology for the current layer from the Dom node supplied. More...
 
bool readXml (const QDomNode &layer_node, const QgsReadWriteContext &context) override
 Reads layer specific state from project file Dom node. More...
 
bool writeStyle (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
 Write the style for the layer into the docment provided. More...
 
bool writeSymbology (QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
 Write the symbology for the layer into the docment provided. More...
 
bool writeXml (QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
 Write layer specific state to project file Dom node. More...
 
- Protected Member Functions inherited from QgsMapLayer
void appendError (const QgsErrorMessage &error)
 Add error message. More...
 
void clone (QgsMapLayer *layer) const
 Copies attributes like name, short name, ... More...
 
bool hasDependencyCycle (const QSet< QgsMapLayerDependency > &layers) const
 Checks whether a new set of dependencies will introduce a cycle. More...
 
void readCommonStyle (const QDomElement &layerElement, const QgsReadWriteContext &context)
 Read style data common to all layer types. More...
 
void readCustomProperties (const QDomNode &layerNode, const QString &keyStartsWith=QString())
 Read custom properties from project file. More...
 
void readStyleManager (const QDomNode &layerNode)
 Read style manager's configuration (if any). To be called by subclasses. More...
 
void setError (const QgsError &error)
 Set error message. More...
 
virtual void setExtent (const QgsRectangle &rect)
 Set the extent. More...
 
void setValid (bool valid)
 Set whether layer is valid or not - should be used in constructor. More...
 
void writeCommonStyle (QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
 Write style data common to all layer types. More...
 
void writeCustomProperties (QDomNode &layerNode, QDomDocument &doc) const
 Write custom properties to project file. More...
 
void writeStyleManager (QDomNode &layerNode, QDomDocument &doc) const
 Write style manager's configuration (if exists). To be called by subclasses. More...
 

Additional Inherited Members

- Signals inherited from QgsMapLayer
void autoRefreshIntervalChanged (int interval)
 Emitted when the auto refresh interval changes. More...
 
void blendModeChanged (QPainter::CompositionMode blendMode)
 Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode() More...
 
void configChanged ()
 Emitted whenever the configuration is changed. More...
 
void crsChanged ()
 Emit a signal that layer's CRS has been reset. More...
 
void dataChanged ()
 Data of layer changed. More...
 
void dependenciesChanged ()
 Emitted when dependencies are changed. More...
 
void legendChanged ()
 Signal emitted when legend of the layer has changed. More...
 
void metadataChanged ()
 Emitted when the layer's metadata is changed. More...
 
void nameChanged ()
 Emitted when the name has been changed. More...
 
void recalculateExtents () const
 This is used to send a request that any mapcanvas using this layer update its extents. More...
 
void renderer3DChanged ()
 Signal emitted when 3D renderer associated with the layer has changed. More...
 
void rendererChanged ()
 Signal emitted when renderer is changed. More...
 
void repaintRequested (bool deferredUpdate=false)
 By emitting this signal the layer tells that either appearance or content have been changed and any view showing the rendered layer should refresh itself. More...
 
void statusChanged (const QString &status)
 Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) More...
 
void styleChanged ()
 Signal emitted whenever a change affects the layer's style. More...
 
void willBeDeleted ()
 Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid state: the last chance for other pieces of code for some cleanup if they use the layer. More...
 
- Protected Attributes inherited from QgsMapLayer
QString mAbstract
 Description of the layer. More...
 
QString mAttribution
 Attribution of the layer. More...
 
QString mAttributionUrl
 
QString mDataSource
 Data source description string, varies by layer type. More...
 
QString mDataUrl
 DataUrl of the layer. More...
 
QString mDataUrlFormat
 
QSet< QgsMapLayerDependencymDependencies
 List of layers that may modify this layer on modification. More...
 
QgsError mError
 Error. More...
 
QgsRectangle mExtent
 Extent of the layer. More...
 
bool mIsRefreshOnNofifyEnabled = false
 
QString mKeywordList
 
QString mLayerName
 Name of the layer - used for display. More...
 
QString mLegendUrl
 WMS legend. More...
 
QString mLegendUrlFormat
 
QString mMetadataUrl
 MetadataUrl of the layer. More...
 
QString mMetadataUrlFormat
 
QString mMetadataUrlType
 
QString mRefreshOnNofifyMessage
 
QString mShortName
 
QString mTitle
 
bool mValid = false
 Indicates if the layer is valid and can be drawn. More...
 
- Properties inherited from QgsMapLayer
int autoRefreshInterval
 
QgsLayerMetadata metadata
 
QString name
 

Detailed Description

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:

QString myFileNameQString = "/path/to/file";
QFileInfo myFileInfo(myFileNameQString);
QString myBaseNameQString = myFileInfo.baseName();
QgsRasterLayer *myRasterLayer = new QgsRasterLayer(myFileNameQString, myBaseNameQString);

In order to automate redrawing of a raster layer, you should like it to a map canvas like this :

QObject::connect( myRasterLayer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) );

Once a layer has been created you can find out what type of layer it is (GrayOrUndefined, Palette or Multiband):

if (rasterLayer->rasterType()==QgsRasterLayer::Multiband)
{
//do something
}
else if (rasterLayer->rasterType()==QgsRasterLayer::Palette)
{
//do something
}
else // QgsRasterLayer::GrayOrUndefined
{
//do something.
}

Raster layers can also have an arbitrary level of transparency defined, and have their color palettes inverted using the setTransparency and setInvertHistogram methods.

Pseudocolor images can have their output adjusted to a given number of standard deviations using the setStandardDeviations method.

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.

Definition at line 139 of file qgsrasterlayer.h.

Member Enumeration Documentation

◆ ColorShadingAlgorithm

This enumerator describes the types of shading that can be used.

Enumerator
UndefinedShader 
PseudoColorShader 
FreakOutShader 
ColorRampShader 
UserDefinedShader 

Definition at line 219 of file qgsrasterlayer.h.

◆ LayerType

This enumerator describes the type of raster layer.

Enumerator
GrayOrUndefined 
Palette 
Multiband 
ColorLayer 

Definition at line 229 of file qgsrasterlayer.h.

Constructor & Destructor Documentation

◆ QgsRasterLayer() [1/2]

QgsRasterLayer::QgsRasterLayer ( )

Constructor. Provider is not set.

Definition at line 98 of file qgsrasterlayer.cpp.

◆ QgsRasterLayer() [2/2]

QgsRasterLayer::QgsRasterLayer ( const QString &  uri,
const QString &  baseName = QString(),
const QString &  providerKey = "gdal",
const QgsRasterLayer::LayerOptions options = QgsRasterLayer::LayerOptions() 
)
explicit

This is the constructor for the RasterLayer class.

The main tasks carried out by the constructor are:

-Load the rasters default style (.qml) file if it exists

-Populate the RasterStatsVector with initial values for each band.

-Calculate the layer extents

-Determine whether the layer is gray, paletted or multiband.

-Assign sensible defaults for the red, green, blue and gray bands.

Definition at line 108 of file qgsrasterlayer.cpp.

◆ ~QgsRasterLayer()

QgsRasterLayer::~QgsRasterLayer ( )
override

Definition at line 139 of file qgsrasterlayer.cpp.

Member Function Documentation

◆ bandCount()

int QgsRasterLayer::bandCount ( ) const

Get the number of bands in this layer.

Definition at line 217 of file qgsrasterlayer.cpp.

◆ bandName()

QString QgsRasterLayer::bandName ( int  bandNoInt) const

Get the name of a band given its number.

Definition at line 223 of file qgsrasterlayer.cpp.

◆ brightnessFilter()

QgsBrightnessContrastFilter* QgsRasterLayer::brightnessFilter ( ) const
inline

Definition at line 262 of file qgsrasterlayer.h.

◆ clone()

QgsRasterLayer * QgsRasterLayer::clone ( ) const
overridevirtual

Returns a new instance equivalent to this one.

A new provider is created for the same data source and renderer is cloned too.

Returns
a new layer instance
Since
QGIS 3.0

Implements QgsMapLayer.

Definition at line 147 of file qgsrasterlayer.cpp.

◆ createMapRenderer()

QgsMapLayerRenderer * QgsRasterLayer::createMapRenderer ( QgsRenderContext rendererContext)
overridevirtual

Return new instance of QgsMapLayerRenderer that will be used for rendering of given context.

Since
QGIS 2.4

Implements QgsMapLayer.

Definition at line 257 of file qgsrasterlayer.cpp.

◆ dataProvider() [1/2]

QgsRasterDataProvider * QgsRasterLayer::dataProvider ( )
overridevirtual
Returns
0 if not using the data provider model (i.e. directly using GDAL)

Reimplemented from QgsMapLayer.

Definition at line 236 of file qgsrasterlayer.cpp.

◆ dataProvider() [2/2]

const QgsRasterDataProvider * QgsRasterLayer::dataProvider ( ) const
overridevirtual

Returns the data provider in a const-correct manner.

Note
available in Python bindings as constDataProvider()
Returns
0 if not using the data provider model (i.e. directly using GDAL)

Reimplemented from QgsMapLayer.

Definition at line 244 of file qgsrasterlayer.cpp.

◆ defaultContrastEnhancementSettings()

bool QgsRasterLayer::defaultContrastEnhancementSettings ( QgsContrastEnhancement::ContrastEnhancementAlgorithm myAlgorithm,
QgsRasterMinMaxOrigin::Limits myLimits 
) const

Return default contrast enhancemnt settings for that type of raster.

Note
not available in Python bindings

Definition at line 1120 of file qgsrasterlayer.cpp.

◆ draw()

void QgsRasterLayer::draw ( QPainter *  theQPainter,
QgsRasterViewPort myRasterViewPort,
const QgsMapToPixel qgsMapToPixel = nullptr 
)

This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap.

Definition at line 263 of file qgsrasterlayer.cpp.

◆ height()

int QgsRasterLayer::height ( ) const

Accessor that returns the height of the (unclipped) raster.

Definition at line 1653 of file qgsrasterlayer.cpp.

◆ htmlMetadata()

QString QgsRasterLayer::htmlMetadata ( ) const
overridevirtual

Obtain a formatted HTML string containing assorted metadata for this layer.

Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 305 of file qgsrasterlayer.cpp.

◆ hueSaturationFilter()

QgsHueSaturationFilter* QgsRasterLayer::hueSaturationFilter ( ) const
inline

Definition at line 263 of file qgsrasterlayer.h.

◆ isSpatial()

bool QgsRasterLayer::isSpatial ( ) const
inlineoverridevirtual

Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated with it.

Since
QGIS 2.16

Reimplemented from QgsMapLayer.

Definition at line 305 of file qgsrasterlayer.h.

◆ isValidRasterFileName() [1/2]

bool QgsRasterLayer::isValidRasterFileName ( const QString &  fileNameQString,
QString &  retError 
)
static

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 returned in retError.

Definition at line 171 of file qgsrasterlayer.cpp.

◆ isValidRasterFileName() [2/2]

bool QgsRasterLayer::isValidRasterFileName ( const QString &  fileNameQString)
static

Definition at line 184 of file qgsrasterlayer.cpp.

◆ lastModified()

QDateTime QgsRasterLayer::lastModified ( const QString &  name)
static

Return time stamp for given file name.

Definition at line 190 of file qgsrasterlayer.cpp.

◆ legendSymbologyItems()

QgsLegendColorList QgsRasterLayer::legendSymbologyItems ( ) const

Returns a list with classification items (Text and color)

Definition at line 294 of file qgsrasterlayer.cpp.

◆ paletteAsPixmap()

QPixmap QgsRasterLayer::paletteAsPixmap ( int  bandNumber = 1)

Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned.

Parameters
bandNumberthe number of the band to use for generating a pixmap of the associated palette
Returns
a 100x100 pixel QPixmap of the bands palette

Definition at line 490 of file qgsrasterlayer.cpp.

◆ pipe()

QgsRasterPipe* QgsRasterLayer::pipe ( )
inline

Get raster pipe.

Definition at line 266 of file qgsrasterlayer.h.

◆ previewAsImage()

QImage QgsRasterLayer::previewAsImage ( QSize  size,
const QColor &  bgColor = Qt::white,
QImage::Format  format = QImage::Format_ARGB32_Premultiplied 
)

Draws a preview of the rasterlayer into a QImage.

Since
QGIS 2.4

Definition at line 1248 of file qgsrasterlayer.cpp.

◆ providerType()

QString QgsRasterLayer::providerType ( ) const

[ data provider interface ] Which provider is being used for this Raster Layer?

Definition at line 544 of file qgsrasterlayer.cpp.

◆ rasterType()

LayerType QgsRasterLayer::rasterType ( )
inline

Accessor for raster layer type (which is a read only property)

Definition at line 253 of file qgsrasterlayer.h.

◆ rasterUnitsPerPixelX()

double QgsRasterLayer::rasterUnitsPerPixelX ( ) const

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)

Returns
the horizontal units per pixel as reported in the GDAL geotramsform[1]

Definition at line 552 of file qgsrasterlayer.cpp.

◆ rasterUnitsPerPixelY()

double QgsRasterLayer::rasterUnitsPerPixelY ( ) const

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)

Definition at line 567 of file qgsrasterlayer.cpp.

◆ readStyle()

bool QgsRasterLayer::readStyle ( const QDomNode &  node,
QString &  errorMessage,
const QgsReadWriteContext context 
)
overrideprotectedvirtual

Read the style information for the current layer from the Dom node supplied.

Reimplemented from QgsMapLayer.

Definition at line 1400 of file qgsrasterlayer.cpp.

◆ readSymbology()

bool QgsRasterLayer::readSymbology ( const QDomNode &  node,
QString &  errorMessage,
const QgsReadWriteContext context 
)
overrideprotectedvirtual

Read the symbology for the current layer from the Dom node supplied.

Implements QgsMapLayer.

Definition at line 1308 of file qgsrasterlayer.cpp.

◆ readXml()

bool QgsRasterLayer::readXml ( const QDomNode &  layer_node,
const QgsReadWriteContext context 
)
overrideprotectedvirtual

Reads layer specific state from project file Dom node.

Raster layer project file XML of form:

Note
Called by QgsMapLayer::readXml().

Reimplemented from QgsMapLayer.

Definition at line 1411 of file qgsrasterlayer.cpp.

◆ refreshContrastEnhancement()

void QgsRasterLayer::refreshContrastEnhancement ( const QgsRectangle extent)

Refresh contrast enhancement with new extent.

Note
not available in Python bindings

Definition at line 982 of file qgsrasterlayer.cpp.

◆ refreshRendererIfNeeded()

void QgsRasterLayer::refreshRendererIfNeeded ( QgsRasterRenderer rasterRenderer,
const QgsRectangle extent 
)

Refresh renderer with new extent, if needed.

Note
not available in Python bindings

Definition at line 1023 of file qgsrasterlayer.cpp.

◆ reload()

void QgsRasterLayer::reload ( )
overridevirtual

Synchronises with changes in the datasource.

Reimplemented from QgsMapLayer.

Definition at line 249 of file qgsrasterlayer.cpp.

◆ renderer()

QgsRasterRenderer* QgsRasterLayer::renderer ( ) const
inline

Definition at line 257 of file qgsrasterlayer.h.

◆ resampleFilter()

QgsRasterResampleFilter* QgsRasterLayer::resampleFilter ( ) const
inline

Set raster resample filter. Takes ownership of the resample filter object.

Definition at line 260 of file qgsrasterlayer.h.

◆ setContrastEnhancement()

void QgsRasterLayer::setContrastEnhancement ( QgsContrastEnhancement::ContrastEnhancementAlgorithm  algorithm,
QgsRasterMinMaxOrigin::Limits  limits = QgsRasterMinMaxOrigin::MinMax,
const QgsRectangle extent = QgsRectangle(),
int  sampleSize = QgsRasterLayer::SAMPLE_SIZE,
bool  generateLookupTableFlag = true 
)

Set contrast enhancement algorithm.

Parameters
algorithmContrast enhancement algorithm
limitsLimits
extentExtent used to calculate limits, if empty, use full layer extent
sampleSizeSize of data sample to calculate limits, if 0, use full resolution
generateLookupTableFlagGenerate lookup table.

Definition at line 842 of file qgsrasterlayer.cpp.

◆ setDataProvider()

void QgsRasterLayer::setDataProvider ( const QString &  provider)

[ data provider interface ] Set the data provider

Definition at line 589 of file qgsrasterlayer.cpp.

◆ setDefaultContrastEnhancement()

void QgsRasterLayer::setDefaultContrastEnhancement ( )

Set default contrast enhancement.

Definition at line 1180 of file qgsrasterlayer.cpp.

◆ setLayerOrder()

void QgsRasterLayer::setLayerOrder ( const QStringList &  layers)
overridevirtual

Reorders the previously selected sublayers of this layer from bottom to top.

(Useful for providers that manage their own layers, such as WMS)

Reimplemented from QgsMapLayer.

Definition at line 1191 of file qgsrasterlayer.cpp.

◆ setRenderer()

void QgsRasterLayer::setRenderer ( QgsRasterRenderer renderer)

Set raster renderer. Takes ownership of the renderer object.

Definition at line 1219 of file qgsrasterlayer.cpp.

◆ setSubLayerVisibility()

void QgsRasterLayer::setSubLayerVisibility ( const QString &  name,
bool  vis 
)
overridevirtual

Set the visibility of the given sublayer name.

Reimplemented from QgsMapLayer.

Definition at line 1203 of file qgsrasterlayer.cpp.

◆ showStatusMessage

void QgsRasterLayer::showStatusMessage ( const QString &  message)
slot

Definition at line 1232 of file qgsrasterlayer.cpp.

◆ subLayers()

QStringList QgsRasterLayer::subLayers ( ) const
overridevirtual

Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.

Reimplemented from QgsMapLayer.

Definition at line 1241 of file qgsrasterlayer.cpp.

◆ timestamp()

QDateTime QgsRasterLayer::timestamp ( ) const
overridevirtual

Time stamp of data source in the moment when data/metadata were loaded by provider.

Reimplemented from QgsMapLayer.

Definition at line 1214 of file qgsrasterlayer.cpp.

◆ width()

int QgsRasterLayer::width ( ) const

Accessor that returns the width of the (unclipped) raster.

Definition at line 1647 of file qgsrasterlayer.cpp.

◆ writeStyle()

bool QgsRasterLayer::writeStyle ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context 
) const
overrideprotectedvirtual

Write the style for the layer into the docment provided.

Reimplemented from QgsMapLayer.

Definition at line 1581 of file qgsrasterlayer.cpp.

◆ writeSymbology()

bool QgsRasterLayer::writeSymbology ( QDomNode &  layer_node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context 
) const
overrideprotectedvirtual

Write the symbology for the layer into the docment provided.

Implements QgsMapLayer.

Definition at line 1552 of file qgsrasterlayer.cpp.

◆ writeXml()

bool QgsRasterLayer::writeXml ( QDomNode &  layer_node,
QDomDocument &  doc,
const QgsReadWriteContext context 
) const
overrideprotectedvirtual

Write layer specific state to project file Dom node.

Reimplemented from QgsMapLayer.

Definition at line 1591 of file qgsrasterlayer.cpp.

Member Data Documentation

◆ MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM

const QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::StretchToMinimumMaximum
static

Default enhancement algorithm for multiple band raster of type different from Byte.

Definition at line 154 of file qgsrasterlayer.h.

◆ MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS

const QgsRasterMinMaxOrigin::Limits QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::CumulativeCut
static

Default enhancement limits for multiple band raster of type different from Byte.

Definition at line 163 of file qgsrasterlayer.h.

◆ MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM

const QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::NoEnhancement
static

Default enhancement algorithm for multiple band raster of type Byte.

Definition at line 151 of file qgsrasterlayer.h.

◆ MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS

const QgsRasterMinMaxOrigin::Limits QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax
static

Default enhancement limits for multiple band raster of type Byte.

Definition at line 160 of file qgsrasterlayer.h.

◆ SAMPLE_SIZE

const double QgsRasterLayer::SAMPLE_SIZE = 250000
static

Default sample size (number of pixels) for estimated statistics/histogram calculation.

Definition at line 145 of file qgsrasterlayer.h.

◆ SINGLE_BAND_ENHANCEMENT_ALGORITHM

const QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsRasterLayer::SINGLE_BAND_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::StretchToMinimumMaximum
static

Default enhancement algorithm for single band raster.

Definition at line 148 of file qgsrasterlayer.h.

◆ SINGLE_BAND_MIN_MAX_LIMITS

const QgsRasterMinMaxOrigin::Limits QgsRasterLayer::SINGLE_BAND_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax
static

Default enhancement limits for single band raster.

Definition at line 157 of file qgsrasterlayer.h.


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