Class: QgsDataProvider

class qgis.core.QgsDataProvider(uri: str = '', options: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions())

Bases: PyQt5.QtCore.QObject

Create a new dataprovider with the specified in the uri.

Additional creation options are specified within the options value.

Abstract base class for spatial data provider implementations.

This object needs to inherit from QObject to enable event processing in the Postgres/PostGIS provider (QgsPostgresProvider). It is called here so that this vtable and the vtable for QgsPostgresProvider don’t get misaligned - the QgsVectorLayer class factory (which refers to generic QgsVectorDataProvider’s) depends on it.

Enums

Methods

appendError

Add error message

childEvent

connectNotify

crs

Returns the coordinate system for the data source.

customEvent

dataSourceUri

Gets the data source specification.

dataTimestamp

Current time stamp of data source

description

Returns description

disconnectNotify

enterUpdateMode

Enter update mode.

error

Gets current status error.

extent

Returns the extent of the layer

fileRasterFilters

Returns raster file filter string

fileVectorFilters

Returns vector file filter string

invalidateConnections

Invalidate connections corresponding to specified name

isSignalConnected

isValid

Returns true if this is a valid layer.

layerMetadata

Returns layer metadata collected from the provider’s source.

leaveUpdateMode

Leave update mode.

name

Returns a provider name

providerProperty

Gets the current value of a certain provider property.

receivers

reloadData

Reloads the data from the source.

sender

senderSignalIndex

setDataSourceUri

Set the data source specification.

setError

Sets error message

setLayerOrder

Reorder the list of layer names to be rendered by this provider (in order from bottom to top)

setListening

Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.

setProviderProperty

Allows setting arbitrary properties on the provider.

setSubLayerVisibility

Set the visibility of the given sublayer name

setSubsetString

Set the subset string used to create a subset of features in the layer.

setUri

Set the data source specification.

subLayerCount

Returns the number of layers for the current data source

subLayerStyles

Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top

subLayers

Sub-layers handled by this provider, in order from bottom to top

subsetString

Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set.

supportsSubsetString

Returns true if the provider supports setting of subset strings.

timerEvent

timestamp

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

updateExtents

Update the extents of the layer.

uri

Gets the data source specification.

writeLayerMetadata

Writes layer metadata to the underlying provider source.

Signals

dataChanged

This is emitted whenever an asynchronous operation has finished and the data should be redrawn

fullExtentCalculated

This is emitted whenever the worker thread has fully calculated the PostGIS extents for this layer, and its event has been received by this provider.

notify

Emitted when datasource issues a notification

Attributes

CustomData

Database

Dir

EvaluateDefaultValues

File

Net

NoDataCapabilities

SUBLAYER_SEPARATOR

CustomData = 3000
class DataCapability

Bases: int

baseClass

alias of QgsDataProvider

Database = 4
Dir = 2
EvaluateDefaultValues = 0
File = 1
Net = 8
NoDataCapabilities = 0
class ProviderOptions

Bases: sip.wrapper

QgsDataProvider.ProviderOptions(QgsDataProvider.ProviderOptions)

unused
class ProviderProperty

Bases: int

SUBLAYER_SEPARATOR = '!!::!!'
appendError(self, message: QgsErrorMessage)

Add error message

childEvent()
connectNotify()
crs(self) → QgsCoordinateReferenceSystem

Returns the coordinate system for the data source. If the provider isn’t capable of returning its projection then an invalid QgsCoordinateReferenceSystem will be returned.

customEvent()
dataChanged

This is emitted whenever an asynchronous operation has finished and the data should be redrawn

When emitted from a QgsVectorDataProvider, any cached information such as feature ids should be invalidated. [signal]

dataSourceUri(self, expandAuthConfig: bool = False) → str

Gets the data source specification. This may be a path or database connection string

Parameters

expandAuthConfig – Whether to expand any assigned authentication configuration

Returns

data source specification

Note

The default authentication configuration expansion is FALSE. This keeps credentials out of layer data source URIs and project files. Expansion should be specifically done only when needed within a provider

dataTimestamp(self) → QDateTime

Current time stamp of data source

description(self) → str

Returns description

Returns a terse string describing what the provider is.

note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

disconnectNotify()
enterUpdateMode(self) → bool

Enter update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. A call to this method shall be balanced with a call to leaveUpdateMode(), if this method returns true.

Most providers will have an empty implementation for that method.

For backward compatibility, providers that implement enterUpdateMode() should still make sure to allow editing operations to work even if enterUpdateMode() is not explicitly called.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the first call to enterUpdateMode() will really turn update mode on.

Returns

true in case of success (or no-op implementation), false in case of failure.

New in version 2.16.

error(self) → QgsError

Gets current status error. This error describes some principal problem for which provider cannot work and thus is not valid. It is not last error after accessing data by block(), identify() etc.

extent(self) → QgsRectangle

Returns the extent of the layer

Returns

QgsRectangle containing the extent of the layer

fileRasterFilters(self) → str

Returns raster file filter string

Returns a string suitable for a QFileDialog of raster file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note

It’d be nice to eventually be raster/vector neutral.

fileVectorFilters(self) → str

Returns vector file filter string

Returns a string suitable for a QFileDialog of vector file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note

It’d be nice to eventually be raster/vector neutral.

fullExtentCalculated

This is emitted whenever the worker thread has fully calculated the PostGIS extents for this layer, and its event has been received by this provider. [signal]

invalidateConnections(self, connection: str)

Invalidate connections corresponding to specified name

New in version 2.16.

isSignalConnected()
isValid(self) → bool

Returns true if this is a valid layer. It is up to individual providers to determine what constitutes a valid layer.

layerMetadata(self) → QgsLayerMetadata

Returns layer metadata collected from the provider’s source.

Individual data providers must implement this method if they support collecting metadata.

New in version 3.0.

leaveUpdateMode(self) → bool

Leave update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. This method shall be balanced with a successful call to enterUpdateMode().

Most providers will have an empty implementation for that method.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the last call to leaveUpdateMode() will really turn update mode off.

Returns

true in case of success (or no-op implementation), false in case of failure.

New in version 2.16.

name(self) → str

Returns a provider name

Essentially just returns the provider key. Should be used to build file dialogs so that providers can be shown with their supported types. Thus if more than one provider supports a given format, the user is able to select a specific provider to open that file.

note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

notify

Emitted when datasource issues a notification

See also

setListening()

New in version 3.0: [signal]

providerProperty(self, property: QgsDataProvider.ProviderProperty, defaultValue: Any = None) → Any

Gets the current value of a certain provider property. It depends on the provider which properties are supported.

New in version 2.16.

receivers()
reloadData(self)

Reloads the data from the source. Needs to be implemented by providers with data caches to synchronize with changes in the data source

sender()
senderSignalIndex()
setDataSourceUri(self, uri: str)

Set the data source specification. This may be a path or database connection string

Parameters

uri – source specification

setError(self, error: QgsError)

Sets error message

setLayerOrder(self, layers: Iterable[str])

Reorder the list of layer names to be rendered by this provider (in order from bottom to top)

Note

layers must have been previously added.

setListening(self, isListening: bool)

Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.

The default implementation does nothing.

See also

notify()

New in version 3.0.

setProviderProperty(self, property: QgsDataProvider.ProviderProperty, value: Any)

Allows setting arbitrary properties on the provider. It depends on the provider which properties are supported.

New in version 2.16.

setSubLayerVisibility(self, name: str, vis: bool)

Set the visibility of the given sublayer name

setSubsetString(self, subset: str, updateFeatureCount: bool = True) → bool

Set the subset string used to create a subset of features in the layer. This may be a sql where clause or any other string that can be used by the data provider to create a subset. Must be implemented in the dataprovider.

setUri(self, uri: QgsDataSourceUri)

Set the data source specification.

New in version 3.0.

subLayerCount(self) → int

Returns the number of layers for the current data source

subLayerStyles(self) → List[str]

Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top

Sub-layer styles are used to abstract the way the provider’s source can symbolise layers in some way at the server, before it serves them to the provider.

subLayers(self) → List[str]

Sub-layers handled by this provider, in order from bottom to top

Sub-layers are used when the provider’s source can combine layers it knows about in some way before it hands them off to the provider.

See also

SUBLAYER_SEPARATOR

subsetString(self) → str

Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set. Must be overridden in the dataprovider, otherwise returns a null QString.

supportsSubsetString(self) → bool

Returns true if the provider supports setting of subset strings.

timerEvent()
timestamp(self) → QDateTime

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

updateExtents(self)

Update the extents of the layer. Not implemented by default.

uri(self) → QgsDataSourceUri

Gets the data source specification.

New in version 3.0.

writeLayerMetadata(self, metadata: QgsLayerMetadata) → bool

Writes layer metadata to the underlying provider source. Support depends on individual provider capabilities.

Returns true if metadata was successfully written to the data provider.

See also

layerMetadata()

New in version 3.0.