Class: QgsDataProvider¶
- class qgis.core.QgsDataProvider¶
Bases:
PyQt5.QtCore.QObject
Abstract base class for spatial data provider implementations.
QgsDataProvider(uri: str = ‘’, providerOptions: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions(), flags: Union[QgsDataProvider.ReadFlags, QgsDataProvider.ReadFlag] = QgsDataProvider.ReadFlags()) Create a new dataprovider with the specified in the
uri
.Additional creation options are specified within the
options
value and since QGIS 3.16 creation flags are specified within theflags
value.Methods
Add error message
Returns the coordinate system for the data source.
Returns a short comment for the data that this provider is providing access to (e.g.
Gets the data source specification.
Current time stamp of data source
Returns description
Enter update mode.
Gets current status error.
Returns the extent of the layer
Returns raster file filter string
Returns vector file filter string
Returns the generic data provider flags.
Invalidate connections corresponding to specified name
Returns
True
if this is a valid layer.Returns layer metadata collected from the provider's source.
Leave update mode.
Returns a provider name
Gets the current value of a certain provider property.
Reloads the data from the source for providers with data caches to synchronize, changes in the data source, feature counts and other specific actions.
Set the data source specification.
Sets error message
Reorder the list of layer names to be rendered by this provider (in order from bottom to top)
Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.
Allows setting arbitrary properties on the provider.
Set the visibility of the given sublayer name
Set the subset string used to create a subset of features in the layer.
Set the data source specification.
Returns the number of layers for the current data source
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top
Sub-layers handled by this provider, in order from bottom to top
String sequence used for separating components of sublayers strings.
Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set.
Returns
True
if the provider supports setting of subset strings.Returns the provider's temporal capabilities.
Time stamp of data source in the moment when data/metadata were loaded by provider
Update the extents of the layer.
Gets the data source specification.
Writes layer
metadata
to the underlying provider source.Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- CustomData = 3000¶
- class DataCapabilities¶
- class DataCapabilities(Union[QgsDataProvider.DataCapabilities, QgsDataProvider.DataCapability])
- class DataCapabilities(QgsDataProvider.DataCapabilities)
Bases:
sip.wrapper
- class DataCapability¶
Bases:
int
- Database = 4¶
- Dir = 2¶
- EvaluateDefaultValues = 0¶
- File = 1¶
- FlagLoadDefaultStyle = 4¶
- FlagTrustDataSource = 1¶
- ForceReadOnly = 32¶
- Net = 8¶
- NoDataCapabilities = 0¶
- class ProviderOptions¶
- class ProviderOptions(QgsDataProvider.ProviderOptions)
Bases:
sip.wrapper
- transformContext¶
- class ProviderProperty¶
Bases:
int
- class ReadFlag¶
Bases:
int
- class ReadFlags¶
- class ReadFlags(Union[QgsDataProvider.ReadFlags, QgsDataProvider.ReadFlag])
- class ReadFlags(QgsDataProvider.ReadFlags)
Bases:
sip.wrapper
- SUBLAYER_SEPARATOR = '!!::!!'¶
- SkipFeatureCount = 2¶
- SkipFullScan = 16¶
- SkipGetExtent = 8¶
- appendError(self, message: QgsErrorMessage)¶
Add error message
- Parameters:
message (QgsErrorMessage) –
- childEvent(self, QChildEvent)¶
- connectNotify(self, QMetaMethod)¶
- 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.- Return type:
- customEvent(self, QEvent)¶
- dataChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- dataComment(self) str ¶
Returns a short comment for the data that this provider is providing access to (e.g. the comment for postgres table).
Note
The default implementation returns an empty string.
New in version 3.14.
- Return type:
str
- dataSourceUri(self, expandAuthConfig: bool = False) str ¶
Gets the data source specification. This may be a path or database connection string
- Parameters:
expandAuthConfig (bool = False) – Whether to expand any assigned authentication configuration
- Return type:
str
- 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
- Return type:
QDateTime
- 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?
- Return type:
str
- disconnectNotify(self, QMetaMethod)¶
- 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 returnsTrue
.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 ifenterUpdateMode()
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 toenterUpdateMode()
will really turn update mode on.- Return type:
bool
- 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.- Return type:
- extent(self) QgsRectangle ¶
Returns the extent of the layer
- Return type:
- 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.
- Return type:
str
- 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.
- Return type:
str
- flags(self) Qgis.DataProviderFlags ¶
Returns the generic data provider flags.
New in version 3.26.
- Return type:
- fullExtentCalculated¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- invalidateConnections(self, connection: str)¶
Invalidate connections corresponding to specified name
New in version 2.16.
- Parameters:
connection (str) –
- isSignalConnected(self, QMetaMethod) bool ¶
- isValid(self) bool ¶
Returns
True
if this is a valid layer. It is up to individual providers to determine what constitutes a valid layer.- Return type:
bool
- layerMetadata(self) QgsLayerMetadata ¶
Returns layer metadata collected from the provider’s source.
Individual data providers must implement this method if they support collecting metadata.
See also
New in version 3.0.
- Return type:
- 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 toleaveUpdateMode()
will really turn update mode off.- Return type:
bool
- 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?
- Return type:
str
- notify¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_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.
- Parameters:
property (QgsDataProvider.ProviderProperty) –
defaultValue (Any = None) –
- Return type:
Any
- receivers(self, PYQT_SIGNAL) int ¶
- reloadData(self)¶
Reloads the data from the source for providers with data caches to synchronize, changes in the data source, feature counts and other specific actions. Emits the dataChanged signal
Note
only available for providers which implement the
reloadProviderData()
method.
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setDataSourceUri(self, uri: str)¶
Set the data source specification. This may be a path or database connection string
- Parameters:
uri (str) – source specification
- 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.
- Parameters:
layers (Iterable[str]) –
- 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
New in version 3.0.
- Parameters:
isListening (bool) –
- 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.
- Parameters:
property (QgsDataProvider.ProviderProperty) –
value (Any) –
- setSubLayerVisibility(self, name: str, vis: bool)¶
Set the visibility of the given sublayer name
- Parameters:
name (str) –
vis (bool) –
- 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.
- Parameters:
subset (str) –
updateFeatureCount (bool = True) –
- Return type:
bool
- setUri(self, uri: QgsDataSourceUri)¶
Set the data source specification.
New in version 3.0.
- Parameters:
uri (QgsDataSourceUri) –
- subLayerCount(self) int ¶
Returns the number of layers for the current data source
- Return type:
int
- 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.
- Return type:
List[str]
- 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
- Return type:
List[str]
- sublayerSeparator() str ¶
String sequence used for separating components of sublayers strings.
Note
Replaces the static const SUBLAYER_SEPARATOR
See also
New in version 3.12.
- Return type:
str
- 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.
- Return type:
str
- supportsSubsetString(self) bool ¶
Returns
True
if the provider supports setting of subset strings.- Return type:
bool
- temporalCapabilities(self) QgsDataProviderTemporalCapabilities ¶
Returns the provider’s temporal capabilities.
This may be
None
, depending on the data provider.New in version 3.14.
- Return type:
- timerEvent(self, QTimerEvent)¶
- timestamp(self) QDateTime ¶
Time stamp of data source in the moment when data/metadata were loaded by provider
- Return type:
QDateTime
- 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.
- Return type:
- 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
New in version 3.0.
- Parameters:
metadata (QgsLayerMetadata) –
- Return type:
bool