Subgroup: Virtual
Class: QgsVirtualLayerDefinition¶
-
class
qgis.core.
QgsVirtualLayerDefinition
(filePath: str = '')¶ Bases:
sip.wrapper
Constructor with an optional file path
QgsVirtualLayerDefinition(QgsVirtualLayerDefinition)
Class to manipulate the definition of a virtual layer
It is used to extract parameters from an initial virtual layer definition as well as to store the complete, expanded definition once types have been detected.
Methods
addSource
Add a live layer source layer fields
Get field definitions filePath
Get the file path. fromUrl
Constructor to build a definition from a QUrl The path part of the URL is extracted as well as the following optional keys: layer_ref=layer_id[:name] represents a live layer referenced by its ID. geometryField
Get the name of the geometry field. geometrySrid
Get the SRID of the geometry geometryWkbType
Get the type of the geometry QgsWkbTypes. hasDefinedGeometry
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown) hasReferencedLayers
Convenience method to test whether the definition has referenced (live) layers hasSourceLayer
Convenience method to test if a given source layer is part of the definition query
Get the SQL query setFields
Set field definitions setFilePath
Set the file path setGeometryField
Set the name of the geometry field setGeometrySrid
Set the SRID of the geometry setGeometryWkbType
Set the type of the geometry setQuery
Set the SQL query setUid
Set the name of the field with unique identifiers sourceLayers
Get access to the source layers toString
Convert into a QString that can be read by the virtual layer provider toUrl
Convert the definition into a QUrl uid
Get the name of the field with unique identifiers Signals
Attributes
-
class
SourceLayer
(name: str, ref: str)¶ Bases:
sip.wrapper
Constructor variant to build a live layer reference
QgsVirtualLayerDefinition.SourceLayer(name: str, source: str, provider: str, encoding: str) Constructor variant to build a layer with a provider and a source
QgsVirtualLayerDefinition.SourceLayer(QgsVirtualLayerDefinition.SourceLayer)
A SourceLayer is either a reference to a live layer in the registry or all the parameters needed to load it (provider key, source, etc.)
-
encoding
(self) → str¶ Optional encoding for the provider
-
isReferenced
(self) → bool¶ Is it a live layer or not ?
-
name
(self) → str¶ Name of the layer
-
provider
(self) → str¶ Provider key
-
reference
(self) → str¶ The reference (id) of the live layer
-
source
(self) → str¶ The source url used by the provider to build the layer
-
-
addSource
(self, name: str, ref: str)¶ Add a live layer source layer
addSource(self, name: str, source: str, provider: str, encoding: str = ‘’) Add a layer with a source, a provider and an encoding
-
fields
(self) → QgsFields¶ Get field definitions
-
filePath
(self) → str¶ Get the file path. May be empty
-
fromUrl
(url: QUrl) → QgsVirtualLayerDefinition¶ Constructor to build a definition from a QUrl The path part of the URL is extracted as well as the following optional keys: layer_ref=layer_id[:name] represents a live layer referenced by its ID. An optional name can be given layer=provider:source[:name[:encoding]] represents a layer given by its provider key, its source url (URL-encoded). An optional name and encoding can be given geometry=column_name[:type:srid] gives the definition of the geometry column. Type can be either a WKB type code or a string (point, linestring, etc.) srid is an integer uid=column_name is the name of a column with unique integer values. nogeometry is a flag to force the layer to be a non-geometry layer query=sql represents the SQL query. Must be URL-encoded field=column_name:[int|real|text] represents a field with its name and its type
-
geometryField
(self) → str¶ Get the name of the geometry field. Empty if no geometry field
-
geometrySrid
(self) → int¶ Get the SRID of the geometry
-
geometryWkbType
(self) → QgsWkbTypes.Type¶ Get the type of the geometry QgsWkbTypes.NoGeometry to hide any geometry QgsWkbTypes.Unknown for unknown types
-
hasDefinedGeometry
(self) → bool¶ Convenient method to test if the geometry is defined (not NoGeometry and not Unknown)
-
hasReferencedLayers
(self) → bool¶ Convenience method to test whether the definition has referenced (live) layers
-
hasSourceLayer
(self, name: str) → bool¶ Convenience method to test if a given source layer is part of the definition
-
query
(self) → str¶ Get the SQL query
-
setFields
(self, fields: QgsFields)¶ Set field definitions
-
setFilePath
(self, filePath: str)¶ Set the file path
-
setGeometryField
(self, geometryField: str)¶ Set the name of the geometry field
-
setGeometrySrid
(self, srid: int)¶ Set the SRID of the geometry
-
setGeometryWkbType
(self, t: QgsWkbTypes.Type)¶ Set the type of the geometry
-
setQuery
(self, query: str)¶ Set the SQL query
-
setUid
(self, uid: str)¶ Set the name of the field with unique identifiers
-
sourceLayers
(self) → object¶ Get access to the source layers
-
toString
(self) → str¶ Convert into a QString that can be read by the virtual layer provider
-
toUrl
(self) → QUrl¶ Convert the definition into a QUrl
-
uid
(self) → str¶ Get the name of the field with unique identifiers
-
class