Class: QgsVectorLayerJoinBuffer¶
- class qgis.core.QgsVectorLayerJoinBuffer¶
Bases:
PyQt5.QtCore.QObject
,QgsFeatureSink
Manages joined fields for a vector layer.
Methods
Adds a list of features in joined layers.
Joins another vector layer to this layer
Changes attribute value in joined layers.
Changes attributes’ values in joined layers.
Create a copy of the join buffer
Quick way to test if there is any join at all
Calls
cacheJoinLayer()
for all vector joinsDeletes a feature from joined layers.
Deletes a list of features from joined layers.
Returns
True
if the join information is about auxiliary layer,False
otherwiseFinds the vector join for a layer field index.
Returns a vector of indices for use in join based on field names from the layer
Returns the joined feature corresponding to the feature.
Find out what is the first index of the join within fields.
Returns joins where the field of a target layer is considered as an id.
Reads joins from project file.
Removes a vector layer join
Resolves layer IDs of joined layers using given project’s available layers
Returns the targeted feature corresponding to the joined feature.
Updates field map with joined attributes
- rtype
List[QgsVectorLayerJoinInfo]
Saves mVectorJoins to xml under the layer node
Signals
Emitted whenever the list of joined fields changes (e.g.
- addFeatures(self, features: Iterable[QgsFeature], flags: Union[QgsFeatureSink.Flags, QgsFeatureSink.Flag] = QgsFeatureSink.Flags()) → bool¶
Adds a list of features in joined layers. Features given in parameter are those added in target layer. If a corresponding joined feature yet exists in a joined layer, then this feature is just updated. Note that if a corresponding joined feature has only empty fields, then it’s not created nor added.
- Parameters
features (Iterable[QgsFeature]) – The list of features added in the target layer
flags (Union[QgsFeatureSink.Flags) – Unused parameter
- Return type
bool
- Returns
False
if an error happened,True
otherwise
New in version 3.0.
- addJoin(self, joinInfo: QgsVectorLayerJoinInfo) → bool¶
Joins another vector layer to this layer
- Parameters
joinInfo (QgsVectorLayerJoinInfo) – join object containing join layer id, target and source field
- Return type
bool
- Returns
(since 2.6) whether the join was successfully added
- changeAttributeValue(self, fid: int, field: int, newValue: Any, oldValue: Any = None) → bool¶
Changes attribute value in joined layers. The feature id given in parameter is the one added in target layer. If the corresponding joined feature does not exist in a joined layer, then it’s automatically created if its fields are not empty.
- Parameters
fid (int) – The feature id
field (int) – The field to update
newValue (Any) – The new value of the attribute
oldValue (Any = None) – The old value of the attribute
- Return type
bool
- Returns
False
if an error happened,True
otherwise
New in version 3.0.
- changeAttributeValues(self, fid: int, newValues: Dict[int, Any], oldValues: Dict[int, Any] = {}) → bool¶
Changes attributes’ values in joined layers. The feature id given in parameter is the one added in target layer. If the corresponding joined feature does not exist in a joined layer, then it’s automatically created if its fields are not empty.
- Parameters
fid (int) – The feature id
newValues (Dict[int) – The new values for attributes
oldValues (Dict[int) – The old values for attributes
- Return type
bool
- Returns
False
if an error happened,True
otherwise
New in version 3.0.
- childEvent(self, QChildEvent)¶
- clone(self) → QgsVectorLayerJoinBuffer¶
Create a copy of the join buffer
New in version 2.6.
- Return type
- connectNotify(self, QMetaMethod)¶
- containsJoins(self) → bool¶
Quick way to test if there is any join at all
- Return type
bool
- createJoinCaches(self)¶
Calls
cacheJoinLayer()
for all vector joins
- customEvent(self, QEvent)¶
- deleteFeature(self, fid: int, context: QgsVectorLayer.DeleteContext = None) → bool¶
Deletes a feature from joined layers. The feature id given in parameter is the one coming from the target layer.
- Parameters
fid (int) – The feature id from the target layer to delete
context (QgsVectorLayer.DeleteContext = None) – The chain of features which will be deleted for feedback and to avoid infinite recursions. Can be
None
.
- Return type
bool
- Returns
False
if an error happened,True
otherwise
New in version 3.0.
- deleteFeatures(self, fids: object, context: QgsVectorLayer.DeleteContext = None) → bool¶
Deletes a list of features from joined layers. Feature ids given in a parameter are those coming from the target layer.
- Parameters
fids (object) – Feature ids from the target layer to delete
context (QgsVectorLayer.DeleteContext = None) – The chain of features who will be deleted for feedback and to avoid infinite recursions. Can be
None
.
- Return type
bool
- Returns
False
if an error happened,True
otherwise
New in version 3.0.
- disconnectNotify(self, QMetaMethod)¶
- isAuxiliaryJoin(self, info: QgsVectorLayerJoinInfo) → bool¶
Returns
True
if the join information is about auxiliary layer,False
otherwise- Parameters
info (QgsVectorLayerJoinInfo) – The join information
- Return type
bool
- Returns
True
if the join information is about auxiliary layer,False
otherwise
New in version 3.0.
- isSignalConnected(self, QMetaMethod) → bool¶
- joinForFieldIndex(self, index: int, fields: QgsFields) → Tuple[QgsVectorLayerJoinInfo, int]¶
Finds the vector join for a layer field index.
- Parameters
index (int) – this layers attribute index
fields (QgsFields) – fields of the vector layer (including joined fields)
- Return type
Tuple[
QgsVectorLayerJoinInfo
, int]- Returns
the vector layer join info
sourceFieldIndex: Output: field’s index in source layer
- joinSubsetIndices(joinLayer: QgsVectorLayer, joinFieldsSubset: Iterable[str]) → List[int]¶
Returns a vector of indices for use in join based on field names from the layer
New in version 2.6.
- Parameters
joinLayer (QgsVectorLayer) –
joinFieldsSubset (Iterable[str]) –
- Return type
List[int]
- joinedFeatureOf(self, info: QgsVectorLayerJoinInfo, feature: QgsFeature) → QgsFeature¶
Returns the joined feature corresponding to the feature.
- Parameters
info (QgsVectorLayerJoinInfo) – the vector join information
feature (QgsFeature) – the feature of the target layer
New in version 3.0.
- Return type
- joinedFieldsChanged¶
Emitted whenever the list of joined fields changes (e.g. added join or joined layer’s fields change)
New in version 2.6: [signal]
- joinedFieldsOffset(self, info: QgsVectorLayerJoinInfo, fields: QgsFields) → int¶
Find out what is the first index of the join within fields. Returns -1 if join is not present
New in version 2.6.
- Parameters
info (QgsVectorLayerJoinInfo) –
fields (QgsFields) –
- Return type
int
- joinsWhereFieldIsId(self, field: QgsField) → List[QgsVectorLayerJoinInfo]¶
Returns joins where the field of a target layer is considered as an id.
- Parameters
field (QgsField) – the field of a target layer
- Return type
List[QgsVectorLayerJoinInfo]
- Returns
a list of vector joins
New in version 3.0.
- readXml(self, layer_node: QDomNode)¶
Reads joins from project file. Does not resolve layer IDs to layers - call
resolveReferences()
afterwards- Parameters
layer_node (QDomNode) –
- receivers(self, PYQT_SIGNAL) → int¶
- removeJoin(self, joinLayerId: str) → bool¶
Removes a vector layer join
- Return type
bool
- Returns
True
if join was found and successfully removed- Parameters
joinLayerId (str) –
- resolveReferences(self, project: QgsProject)¶
Resolves layer IDs of joined layers using given project’s available layers
New in version 3.0.
- Parameters
project (QgsProject) –
- sender(self) → QObject¶
- senderSignalIndex(self) → int¶
- targetedFeatureOf(self, info: QgsVectorLayerJoinInfo, feature: QgsFeature) → QgsFeature¶
Returns the targeted feature corresponding to the joined feature.
- Parameters
info (QgsVectorLayerJoinInfo) – the vector join information
feature (QgsFeature) – the feature of the joined layer
New in version 3.0.
- Return type
- timerEvent(self, QTimerEvent)¶
- updateFields(self, fields: QgsFields)¶
Updates field map with joined attributes
- Parameters
fields (QgsFields) – map to append joined attributes
- vectorJoins(self) → List[QgsVectorLayerJoinInfo]¶
- Return type
List[QgsVectorLayerJoinInfo]
- writeXml(self, layer_node: QDomNode, document: QDomDocument)¶
Saves mVectorJoins to xml under the layer node
- Parameters
layer_node (QDomNode) –
document (QDomDocument) –