Class: QgsRasterDataProvider¶
-
class
qgis.core.
QgsRasterDataProvider
¶ Bases:
QgsDataProvider
,QgsRasterInterface
QgsRasterDataProvider(uri: str, providerOptions: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions()) Constructor for QgsRasterDataProvider.
The
uri
argument gives a provider-specific uri indicating the underlying data source and it’s parameters.The
options
argument specifies generic provider options.Base class for raster data providers.
Methods
Add error message
Read band offset for raster value
Read band scale for raster value
Read block of data using given extent and size.
Returns the raster layers pyramid list.
Create pyramid overviews
- rtype
QgsRasterInterface
Returns data type for the band specified by number
- param bandNo
- param colorInterpretation
- param bandNo
Copy member variables from other raster data provider.
Creates a new dataset with mDataSourceURI
Current time stamp of data source
Returns data type for the band specified by number
Returns the dpi of the output device.
- rtype
QgsRectangle
Returns a new image downloader for the raster legend.
Returns
True
if raster has at least one populated histogram.Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties “Metadata” tab.
Identify raster value(s) found on the point position.
- param formatName
- param format
- param format
- param format
Returns true if the extents reported by the data provider are not reliable and it’s possible that there is renderable content outside of these extents.
Fill in histogram defaults if not specified
Fill in statistics defaults if not specified
Checks whether the provider is in editing mode, i.e.
Returns the verbose error text for the last error in this provider
Returns the format of the error text for the last error in this provider
Returns the caption error text for the last error in this provider
Returns a list of native resolutions if available, i.e.
Returns flags containing the supported capabilities of the data provider.
Returns a list of pyramid resampling method name and label pairs for given provider
Reload data (data could change)
Remove dataset
Samples a raster value from the specified
band
found at thepoint
position.Sets the output device resolution.
Turns on/off editing mode of the provider.
Sets error message
It makes no sense to set input on provider */
Set no data value on created dataset
Sets the source nodata value usage
- param bandNo
Returns source data type for the band specified by number, source data type may be shorter than dataType
Returns
True
if source band has no data valueValue representing no data value.
Step height for raster iterations.
Step width for raster iterations.
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS
Returns whether the provider supplies a legend graphic
Time stamp of data source in the moment when data/metadata were loaded by provider
Returns the source nodata value usage
Returns a list of user no data value ranges.
Returns
True
if user no data contains valueValidates creation options for a specific dataset and destination format.
Validates pyramid creation options for a specific dataset and destination format
- param data
Writes pixel data from a raster block into the provider data source.
Signals
Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
Attributes
-
NoProviderCapabilities
= 0¶
-
class
ProviderCapabilities
¶ Bases:
sip.wrapper
QgsRasterDataProvider.ProviderCapabilities(Union[QgsRasterDataProvider.ProviderCapabilities, QgsRasterDataProvider.ProviderCapability]) QgsRasterDataProvider.ProviderCapabilities(QgsRasterDataProvider.ProviderCapabilities)
-
class
ProviderCapability
¶ Bases:
int
-
ProviderHintBenefitsFromResampling
= 8¶
-
ReadLayerMetadata
= 2¶
-
WriteLayerMetadata
= 4¶
-
appendError
(self, message: QgsErrorMessage)¶ Add error message
-
bandOffset
(self, bandNo: int) → float¶ Read band offset for raster value
New in version 2.3.
- Parameters
bandNo (int) –
- Return type
float
-
bandScale
(self, bandNo: int) → float¶ Read band scale for raster value
New in version 2.3.
- Parameters
bandNo (int) –
- Return type
float
-
block
(self, bandNo: int, boundingBox: QgsRectangle, width: int, height: int, feedback: QgsRasterBlockFeedback = None) → QgsRasterBlock¶ Read block of data using given extent and size.
- Parameters
bandNo (int) –
boundingBox (QgsRectangle) –
width (int) –
height (int) –
feedback (
QgsRasterBlockFeedback
= None) –
- Return type
-
buildPyramidList
(self, overviewList: Iterable[int] = []) → List[QgsRasterPyramid]¶ Returns the raster layers pyramid list.
- Parameters
overviewList (Iterable[int] = []) – used to construct the pyramid list (optional), when empty the list is defined by the provider. A pyramid list defines the POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers ACTUALLY exists you need to look at the existsFlag member in each struct stored in the list.
- Return type
List[QgsRasterPyramid]
-
buildPyramids
(self, pyramidList: Iterable[QgsRasterPyramid], resamplingMethod: str = '', format: QgsRaster.RasterPyramidsFormat = QgsRaster.PyramidsGTiff, configOptions: Iterable[str] = [], feedback: QgsRasterBlockFeedback = None) → str¶ Create pyramid overviews
- Parameters
pyramidList (Iterable[QgsRasterPyramid]) –
resamplingMethod (str = '') –
format (QgsRaster.RasterPyramidsFormat = QgsRaster.PyramidsGTiff) –
configOptions (Iterable[str] = []) –
feedback (
QgsRasterBlockFeedback
= None) –
- Return type
str
-
childEvent
(self, QChildEvent)¶
-
clone
(self) → QgsRasterInterface¶ - Return type
-
colorInterpretation
(self, bandNo: int) → int¶ Returns data type for the band specified by number
- Parameters
bandNo (int) –
- Return type
int
-
colorInterpretationName
(self, bandNo: int) → str¶ - Parameters
bandNo (int) –
- Return type
str
-
colorName
(self, colorInterpretation: int) → str¶ - Parameters
colorInterpretation (int) –
- Return type
str
-
colorTable
(self, bandNo: int) → List[QgsColorRampShader.ColorRampItem]¶ - Parameters
bandNo (int) –
- Return type
-
connectNotify
(self, QMetaMethod)¶
-
copyBaseSettings
(self, other: QgsRasterDataProvider)¶ Copy member variables from other raster data provider. Useful for implementation of clone() method in subclasses
- Parameters
other (QgsRasterDataProvider) –
-
create
(providerKey: str, uri: str, format: str, nBands: int, type: Qgis.DataType, width: int, height: int, crs: QgsCoordinateReferenceSystem, createOptions: Iterable[str] = []) → Tuple[QgsRasterDataProvider, float]¶ Creates a new dataset with mDataSourceURI
- Parameters
providerKey (str) –
uri (str) –
format (str) –
nBands (int) –
type (Qgis.DataType) –
width (int) –
height (int) –
crs (QgsCoordinateReferenceSystem) –
createOptions (Iterable[str] = []) –
- Return type
Tuple[
QgsRasterDataProvider
, float]
-
customEvent
(self, QEvent)¶
-
dataTimestamp
(self) → QDateTime¶ Current time stamp of data source
- Return type
QDateTime
-
dataType
(self, bandNo: int) → Qgis.DataType¶ Returns data type for the band specified by number
- Parameters
bandNo (int) –
- Return type
-
disconnectNotify
(self, QMetaMethod)¶
-
dpi
(self) → int¶ Returns the dpi of the output device.
- Return type
int
-
extent
(self) → QgsRectangle¶ - Return type
-
getLegendGraphicFetcher
(self, mapSettings: QgsMapSettings) → QgsImageFetcher¶ Returns a new image downloader for the raster legend.
- Parameters
mapSettings (QgsMapSettings) – map settings for legend providers supporting contextual legends.
- Return type
- Returns
a download handler or
None
if the provider does not support legend at all. Ownership of the returned object is transferred to caller.
New in version 2.8.
-
hasPyramids
(self) → bool¶ Returns
True
if raster has at least one populated histogram.- Return type
bool
-
htmlMetadata
(self) → str¶ Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties “Metadata” tab.
- Return type
str
-
identify
(self, point: QgsPointXY, format: QgsRaster.IdentifyFormat, boundingBox: QgsRectangle = QgsRectangle(), width: int = 0, height: int = 0, dpi: int = 96) → QgsRasterIdentifyResult¶ Identify raster value(s) found on the point position. The context parameters extent, width and height are important to identify on the same zoom level as a displayed map and to do effective caching (WCS). If context params are not specified the highest resolution is used. capabilities() may be used to test if format is supported by provider. Values are set to ‘no data’ or empty string if point is outside data source extent.
- Parameters
point (QgsPointXY) – coordinates in data source CRS
format (QgsRaster.IdentifyFormat) – result format
boundingBox (
QgsRectangle
= QgsRectangle()) – context bounding boxwidth (int = 0) – context width
height (int = 0) – context height
dpi (int = 96) – context dpi
- Return type
- Returns
QgsRaster.IdentifyFormatValue: map of values for each band, keys are band numbers (from 1). QgsRaster.IdentifyFormatFeature: map of
QgsRasterFeatureList
for each sublayer (WMS) - TODO: it is not consistent with QgsRaster.IdentifyFormatValue. QgsRaster.IdentifyFormatHtml: map of HTML strings for each sublayer (WMS). Empty if failed or there are no results (TODO: better error reporting).
Note
The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
See also
-
identifyFormatFromName
(formatName: str) → QgsRaster.IdentifyFormat¶ - Parameters
formatName (str) –
- Return type
-
identifyFormatLabel
(format: QgsRaster.IdentifyFormat) → str¶ - Parameters
format (QgsRaster.IdentifyFormat) –
- Return type
str
-
identifyFormatName
(format: QgsRaster.IdentifyFormat) → str¶ - Parameters
format (QgsRaster.IdentifyFormat) –
- Return type
str
-
identifyFormatToCapability
(format: QgsRaster.IdentifyFormat) → QgsRasterInterface.Capability¶ - Parameters
format (QgsRaster.IdentifyFormat) –
- Return type
-
ignoreExtents
(self) → bool¶ Returns true if the extents reported by the data provider are not reliable and it’s possible that there is renderable content outside of these extents.
New in version 3.10.0.
- Return type
bool
-
initHistogram
(self, histogram: QgsRasterHistogram, bandNo: int, binCount: int, minimum: object = Py_None, maximum: object = Py_None, boundingBox: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False)¶ Fill in histogram defaults if not specified
Note
the parameters are the same as in
histogram()
-
initStatistics
(self, statistics: QgsRasterBandStats, bandNo: int, stats: int = QgsRasterBandStats.All, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0)¶ Fill in statistics defaults if not specified
-
isEditable
(self) → bool¶ Checks whether the provider is in editing mode, i.e. raster write operations will be accepted. By default providers are not editable. Use setEditable() method to enable/disable editing.
See also
New in version 3.0.
- Return type
bool
-
isSignalConnected
(self, QMetaMethod) → bool¶
-
lastError
(self) → str¶ Returns the verbose error text for the last error in this provider
If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure. Interactive users of this provider can then, for example, call a QMessageBox to display the contents.
- Return type
str
-
lastErrorFormat
(self) → str¶ Returns the format of the error text for the last error in this provider
- Return type
str
-
lastErrorTitle
(self) → str¶ Returns the caption error text for the last error in this provider
If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure. Interactive users of this provider can then, for example, call a QMessageBox to display the contents.
- Return type
str
-
nativeResolutions
(self) → List[float]¶ Returns a list of native resolutions if available, i.e. map units per pixel at which the raster source was originally created.
Resolutions are calculated in the provider’s crs().
New in version 3.8.0.
- Return type
List[float]
-
providerCapabilities
(self) → QgsRasterDataProvider.ProviderCapabilities¶ Returns flags containing the supported capabilities of the data provider.
New in version 3.0.
- Return type
-
pyramidResamplingMethods
(providerKey: str) → List[Tuple[str, str]]¶ Returns a list of pyramid resampling method name and label pairs for given provider
- Parameters
providerKey (str) –
- Return type
List[Tuple[str, str]]
-
receivers
(self, PYQT_SIGNAL) → int¶
-
reload
(self) → bool¶ Reload data (data could change)
- Return type
bool
-
remove
(self) → bool¶ Remove dataset
- Return type
bool
-
sample
(self, point: QgsPointXY, band: int, boundingBox: QgsRectangle = QgsRectangle(), width: int = 0, height: int = 0, dpi: int = 96) → Tuple[float, bool]¶ Samples a raster value from the specified
band
found at thepoint
position. The context parametersboundingBox
,width
andheight
are important to identify on the same zoom level as a displayed map and to do effective caching (WCS). If context params are not specified the highest resolution is used.If
ok
is specified and the point is outside data source extent, or an invalid band number was specified, thenok
will be set toFalse
. In this case the function will return a NaN value.See also
New in version 3.4.
- Parameters
point (QgsPointXY) –
band (int) –
boundingBox (
QgsRectangle
= QgsRectangle()) –width (int = 0) –
height (int = 0) –
dpi (int = 96) –
- Return type
Tuple[float, bool]
-
sender
(self) → QObject¶
-
senderSignalIndex
(self) → int¶
-
setDpi
(self, dpi: int)¶ Sets the output device resolution.
- Parameters
dpi (int) –
-
setEditable
(self, enabled: bool) → bool¶ Turns on/off editing mode of the provider. When in editing mode, it is possible to overwrite data of the provider using writeBlock() calls.
- Return type
bool
- Returns
True
if the switch to/from editing mode was successful
Note
Only some providers support editing mode and even those may fail to turn the underlying data source into editing mode, so it is necessary to check the return value whether the operation was successful.
See also
New in version 3.0.
- Parameters
enabled (bool) –
-
setInput
(self, input: QgsRasterInterface) → bool¶ It makes no sense to set input on provider */
- Parameters
input (QgsRasterInterface) –
- Return type
bool
-
setNoDataValue
(self, bandNo: int, noDataValue: float) → bool¶ Set no data value on created dataset
- Parameters
bandNo (int) – band number
noDataValue (float) – no data value
- Return type
bool
-
setUseSourceNoDataValue
(self, bandNo: int, use: bool)¶ Sets the source nodata value usage
- Parameters
bandNo (int) –
use (bool) –
-
setUserNoDataValue
(self, bandNo: int, noData: Iterable[QgsRasterRange])¶ - Parameters
bandNo (int) –
noData (Iterable[QgsRasterRange]) –
-
sourceDataType
(self, bandNo: int) → Qgis.DataType¶ Returns source data type for the band specified by number, source data type may be shorter than dataType
- Parameters
bandNo (int) –
- Return type
-
sourceHasNoDataValue
(self, bandNo: int) → bool¶ Returns
True
if source band has no data value- Parameters
bandNo (int) –
- Return type
bool
-
sourceNoDataValue
(self, bandNo: int) → float¶ Value representing no data value.
- Parameters
bandNo (int) –
- Return type
float
-
statusChanged
¶ Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
New in version 2.14: [signal]
-
stepHeight
(self) → int¶ Step height for raster iterations.
See also
New in version 3.0.
- Return type
int
-
stepWidth
(self) → int¶ Step width for raster iterations.
See also
New in version 3.0.
- Return type
int
-
subLayers
(self) → List[str]¶ Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS
- Return type
List[str]
-
supportsLegendGraphic
(self) → bool¶ Returns whether the provider supplies a legend graphic
- Return type
bool
-
timerEvent
(self, QTimerEvent)¶
-
timestamp
(self) → QDateTime¶ Time stamp of data source in the moment when data/metadata were loaded by provider
- Return type
QDateTime
-
useSourceNoDataValue
(self, bandNo: int) → bool¶ Returns the source nodata value usage
- Parameters
bandNo (int) –
- Return type
bool
-
userNoDataValues
(self, bandNo: int) → List[QgsRasterRange]¶ Returns a list of user no data value ranges.
- Parameters
bandNo (int) –
- Return type
List[QgsRasterRange]
-
userNoDataValuesContains
(self, bandNo: int, value: float) → bool¶ Returns
True
if user no data contains value- Parameters
bandNo (int) –
value (float) –
- Return type
bool
-
validateCreationOptions
(self, createOptions: Iterable[str], format: str) → str¶ Validates creation options for a specific dataset and destination format.
Note
used by GDAL provider only
Note
see also validateCreationOptionsFormat() in gdal provider for validating options based on format only
- Parameters
createOptions (Iterable[str]) –
format (str) –
- Return type
str
-
validatePyramidsConfigOptions
(self, pyramidsFormat: QgsRaster.RasterPyramidsFormat, configOptions: Iterable[str], fileFormat: str) → str¶ Validates pyramid creation options for a specific dataset and destination format
Note
used by GDAL provider only
- Parameters
pyramidsFormat (QgsRaster.RasterPyramidsFormat) –
configOptions (Iterable[str]) –
fileFormat (str) –
- Return type
str
-
write
(self, data: sip.voidptr, band: int, width: int, height: int, xOffset: int, yOffset: int) → bool¶ - Parameters
data (sip.voidptr) –
band (int) –
width (int) –
height (int) –
xOffset (int) –
yOffset (int) –
- Return type
bool
-
writeBlock
(self, block: QgsRasterBlock, band: int, xOffset: int = 0, yOffset: int = 0) → bool¶ Writes pixel data from a raster block into the provider data source.
This will override previously stored pixel values. It is assumed that cells in the passed raster block are aligned with the cells of the data source. If raster block does not cover the whole area of the data source, only a subset of pixels covered by the raster block will be overwritten. By default, writing of raster data starts from the first cell of the raster - it is possible to set offset in pixels by specifying non-zero xOffset and yOffset values.
Writing is supported only by some data providers. Provider has to be in editing mode in order to allow write operations.
See also
- Return type
bool
- Returns
True
on success
New in version 3.0.
- Parameters
block (QgsRasterBlock) –
band (int) –
xOffset (int = 0) –
yOffset (int = 0) –