Class: QgsWeakRelation¶
- class qgis.core.QgsWeakRelation¶
Bases:
sip.wrapper
The
QgsWeakRelation
class represent aQgsRelation
with possibly unresolved layers or unmatched fields.This class is used to store relation information attached to a layer style, a method to attempt relation resolution is also implemented and can be used to create a
QgsRelation
after the dependent layers are loaded and available.In contrast to
QgsRelation
,QgsWeakRelation
can be used to encapsulate information about a relationship which does not currently exist in a QGIS project. E.g. it can be used to represent a relationship which exists in a database backend (but not within a QGIS project). Accordingly, some properties available inQgsWeakRelation
are included for informational purposes only, and cannot be translated toQgsRelations
or respected in QGIS relationships.New in version 3.12.
QgsWeakRelation() Default constructor for an invalid relation.
QgsWeakRelation(relationId: str, relationName: str, strength: Qgis.RelationshipStrength, referencingLayerId: str, referencingLayerName: str, referencingLayerSource: str, referencingLayerProviderKey: str, referencedLayerId: str, referencedLayerName: str, referencedLayerSource: str, referencedLayerProviderKey: str) Creates a QgsWeakRelation.
New in version 3.30.
QgsWeakRelation(
QgsWeakRelation
)Methods
Returns the label of the backward path for the relationship.
Returns the relationship's cardinality.
Returns the label of the forward path for the relationship.
Returns the relationship's ID.
Returns the list of fields from the
mappingTable()
involved in the relationship.Returns the list of fields from the
mappingTable()
involved in the relationship.Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.
Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.
Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.
Returns the relationship's name.
Returns a weak relation for the given layer.
Returns the list of fields from the
referencedLayer()
involved in the relationship.Returns the layer name of the referenced (or "parent" / "left") layer.
Returns the provider ID for the referenced (or "parent" / "left") layer.
Returns the source URI for the referenced (or "parent" / "left") layer.
Returns the list of fields from the
referencingLayer()
involved in the relationship.Returns the layer name of the referencing (or "child" / "right") layer.
Returns the provider ID for the referencing (or "child" / "right") layer.
Returns the source URI for the referencing (or "child" / "right") layer.
Returns the type string of the related table.
Resolves a weak relation in the given
project
returning a list of possibly invalidQgsRelations
and without performing any kind of validity check.Sets the
label
of the backward path for the relationship.Sets the relationship's
cardinality
.Sets the
label
of the forward path for the relationship.Sets the list of
fields
from themappingTable()
involved in the relationship.Sets the list of
fields
from themappingTable()
involved in the relationship.Sets the list of
fields
from thereferencedLayer()
involved in the relationship.Sets the list of
fields
from thereferencingLayer()
involved in the relationship.Sets the
type
string of the related table.Returns the strength of the relation.
Writes a weak relation infoto an XML structure.
Attributes
- Referenced = 1¶
- Referencing = 0¶
- class WeakRelationType¶
Bases:
int
- backwardPathLabel(self) str ¶
Returns the label of the backward path for the relationship.
The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.
E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.
See also
See also
New in version 3.28.
- Return type:
str
- cardinality(self) Qgis.RelationshipCardinality ¶
Returns the relationship’s cardinality.
See also
New in version 3.28.
- Return type:
- forwardPathLabel(self) str ¶
Returns the label of the forward path for the relationship.
The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.
E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.
See also
See also
New in version 3.28.
- Return type:
str
- id(self) str ¶
Returns the relationship’s ID.
New in version 3.28.
- Return type:
str
- mappingReferencedLayerFields(self) List[str] ¶
Returns the list of fields from the
mappingTable()
involved in the relationship.These fields will be matched to the
referencedLayerFields()
in many-to-many joins.New in version 3.28.
- Return type:
List[str]
- mappingReferencingLayerFields(self) List[str] ¶
Returns the list of fields from the
mappingTable()
involved in the relationship.These fields will be matched to the
referencingLayerFields()
in many-to-many joins.New in version 3.28.
- Return type:
List[str]
- mappingTableName(self) str ¶
Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.
Note
the layer name refers to the layer name used in the datasource, not in any associated
QgsVectorLayer
.New in version 3.28.
- Return type:
str
- mappingTableProvider(self) str ¶
Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.
New in version 3.28.
- Return type:
str
- mappingTableSource(self) str ¶
Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.
New in version 3.28.
- Return type:
str
- name(self) str ¶
Returns the relationship’s name.
New in version 3.28.
- Return type:
str
- readXml(layer: QgsVectorLayer, type: QgsWeakRelation.WeakRelationType, node: QDomNode, resolver: QgsPathResolver) QgsWeakRelation ¶
Returns a weak relation for the given layer.
- Parameters:
layer (QgsVectorLayer) – the layer of the weak relation
type (QgsWeakRelation.WeakRelationType) – determines if the layer is referencing or referenced
node (QDomNode) – the QDomNode
resolver (QgsPathResolver) – the path resolver
New in version 3.16.
- Return type:
- referencedLayerFields(self) List[str] ¶
Returns the list of fields from the
referencedLayer()
involved in the relationship.New in version 3.28.
- Return type:
List[str]
- referencedLayerName(self) str ¶
Returns the layer name of the referenced (or “parent” / “left”) layer.
Note
the layer name refers to the layer name used in the datasource, not in any associated
QgsVectorLayer
.New in version 3.28.
- Return type:
str
- referencedLayerProvider(self) str ¶
Returns the provider ID for the referenced (or “parent” / “left”) layer.
New in version 3.28.
- Return type:
str
- referencedLayerSource(self) str ¶
Returns the source URI for the referenced (or “parent” / “left”) layer.
New in version 3.28.
- Return type:
str
- referencingLayerFields(self) List[str] ¶
Returns the list of fields from the
referencingLayer()
involved in the relationship.New in version 3.28.
- Return type:
List[str]
- referencingLayerName(self) str ¶
Returns the layer name of the referencing (or “child” / “right”) layer.
Note
the layer name refers to the layer name used in the datasource, not in any associated
QgsVectorLayer
.New in version 3.28.
- Return type:
str
- referencingLayerProvider(self) str ¶
Returns the provider ID for the referencing (or “child” / “right”) layer.
New in version 3.28.
- Return type:
str
- referencingLayerSource(self) str ¶
Returns the source URI for the referencing (or “child” / “right”) layer.
New in version 3.28.
- Return type:
str
Returns the type string of the related table.
This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. “media”, “simple attributes”, “features”, “attributes” and “tiles”).
See also
New in version 3.28.
- Return type:
str
- resolvedRelations(self, project: QgsProject) List[QgsRelation] ¶
Resolves a weak relation in the given
project
returning a list of possibly invalidQgsRelations
and without performing any kind of validity check.Note
Client code should never assume that the returned relations are valid and the layer components are not NULL.
- Parameters:
project (QgsProject) –
- Return type:
List[QgsRelation]
- setBackwardPathLabel(self, label: str)¶
Sets the
label
of the backward path for the relationship.The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.
E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.
See also
See also
New in version 3.28.
- Parameters:
label (str) –
- setCardinality(self, cardinality: Qgis.RelationshipCardinality)¶
Sets the relationship’s
cardinality
.See also
New in version 3.28.
- Parameters:
cardinality (Qgis.RelationshipCardinality) –
- setForwardPathLabel(self, label: str)¶
Sets the
label
of the forward path for the relationship.The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.
E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.
See also
See also
New in version 3.28.
- Parameters:
label (str) –
- setMappingReferencedLayerFields(self, fields: Iterable[str])¶
Sets the list of
fields
from themappingTable()
involved in the relationship.These fields will be matched to the
referencedLayerFields()
in many-to-many joins.New in version 3.28.
- Parameters:
fields (Iterable[str]) –
- setMappingReferencingLayerFields(self, fields: Iterable[str])¶
Sets the list of
fields
from themappingTable()
involved in the relationship.These fields will be matched to the
referencingLayerFields()
in many-to-many joins.New in version 3.28.
- Parameters:
fields (Iterable[str]) –
- setReferencedLayerFields(self, fields: Iterable[str])¶
Sets the list of
fields
from thereferencedLayer()
involved in the relationship.New in version 3.28.
- Parameters:
fields (Iterable[str]) –
- setReferencingLayerFields(self, fields: Iterable[str])¶
Sets the list of
fields
from thereferencingLayer()
involved in the relationship.New in version 3.28.
- Parameters:
fields (Iterable[str]) –
- setRelatedTableType(self, type: str)¶
Sets the
type
string of the related table.This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. “media”, “simple attributes”, “features”, “attributes” and “tiles”).
See also
New in version 3.28.
- Parameters:
type (str) –
- strength(self) Qgis.RelationshipStrength ¶
Returns the strength of the relation.
- Return type:
- writeXml(layer: QgsVectorLayer, type: QgsWeakRelation.WeakRelationType, relation: QgsRelation, node: QDomNode, doc: QDomDocument)¶
Writes a weak relation infoto an XML structure. Used for saving .qgs projects
- Parameters:
layer (QgsVectorLayer) – the layer which we save the weak relation for
type (QgsWeakRelation.WeakRelationType) – determines if the layer is referencing or referenced
relation (QgsRelation) – the relation to save as a weak relation
node (QDomNode) – The parent node in which the relation will be created
doc (QDomDocument) – The document in which the relation will be saved
New in version 3.16.