Class: QgsLayerMetadata¶
A structured metadata store for a map layer.
QgsLayerMetadata handles storage and management of the
metadata for a QgsMapLayer. This class is an internal QGIS
format with a common metadata structure, which allows for code to access
the metadata properties for layers in a uniform way.
The metadata store is designed to be compatible with the Dublin Core
metadata specifications, and will be expanded to allow compatibility
with ISO specifications in future releases. However, the QGIS internal
schema does not represent a superset of all existing metadata schemas
and accordingly conversion from specific metadata formats to
QgsLayerMetadata may result in a loss of information.
This class is designed to follow the specifications detailed in the schema definition available at resources/qgis-resource-metadata.xsd within the QGIS source code.
Metadata can be validated through the use of
QgsLayerMetadataValidator subclasses. E.g. validating
against the native QGIS metadata schema can be performed using
QgsNativeMetadataValidator.
Class Hierarchy¶
Base classes¶
An abstract base class for metadata stores. |
Subclasses¶
Result record of layer metadata provider search. |
- class qgis.core.QgsLayerMetadata[source]¶
Bases:
QgsAbstractMetadataBase- class Extent¶
Bases:
objectMetadata extent structure.
- setSpatialExtents(self, extents: Iterable[QgsLayerMetadata.SpatialExtent])¶
Sets the spatial
extentsof the resource.See also
- Parameters:
extents (Iterable[QgsLayerMetadata.SpatialExtent])
- setTemporalExtents(self, extents: Iterable[QgsDateTimeRange])¶
Sets the temporal
extentsof the resource.See also
- Parameters:
extents (Iterable[QgsDateTimeRange])
- spatialExtents(self) List[QgsLayerMetadata.SpatialExtent]¶
Spatial extents of the resource.
See also
- Return type:
- temporalExtents(self) List[QgsDateTimeRange]¶
Temporal extents of the resource. Use
QgsDateTimeRange.isInstant()to determine whether the temporal extent is a range or a single point in time. IfQgsDateTimeRange.isInfinite()returnsTruethen the temporal extent is considered to be indeterminate and continuous.See also
- Return type:
- class SpatialExtent¶
Bases:
objectMetadata spatial extent structure.
- extentCrs: QgsCoordinateReferenceSystem¶
- addConstraint(self, constraint: QgsLayerMetadata.Constraint)[source]¶
Adds an individual constraint to the existing constraints.
See also
See also
- Parameters:
constraint (QgsLayerMetadata.Constraint)
- constraints(self) List[QgsLayerMetadata.Constraint][source]¶
Returns a list of constraints associated with using the resource.
See also
- Return type:
- contains(self, searchString: str | None) bool[source]¶
Returns
Trueif the metadata identifier, title, abstract, keywords or categories containsearchStringusing case-insensitive search.If
searchStringis empty this method returnsFalse.Added in version 3.28.
- Parameters:
searchString (Optional[str])
- Return type:
bool
- crs(self) QgsCoordinateReferenceSystem[source]¶
Returns the coordinate reference system described by the layer’s metadata.
Note that this has no link to
QgsMapLayer.crs(). While in most cases these two systems are likely to be identical, it is possible to have a layer with a different CRS described by it’s accompanying metadata versus the CRS which is actually used to display and manipulate the layer within QGIS. This may be the case when a layer has an incorrect CRS within its metadata and a user has manually overridden the layer’s CRS within QGIS.The CRS described here should either match the CRS from the layer
QgsMapLayer.crs()or the CRS from the data provider.This property should also match the CRS property used in the spatial extent.
See also
- Return type:
- encoding(self) str[source]¶
Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.
See also
- Return type:
str
- extent(self) QgsLayerMetadata.Extent¶
Returns the spatial and temporal extents associated with the resource.
See also
- Return type:
- fees(self) str[source]¶
Returns any fees associated with using the resource. An empty string will be returned if no fees are set.
See also
- Return type:
str
- licenses(self) List[str][source]¶
Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/).
See also
- Return type:
List[str]
- matches(self, searchReList: Iterable[QRegularExpression]) bool[source]¶
Returns
Trueif the metadata identifier, title, abstract, keywords or categories matches any regular expression fromsearchReList.Added in version 3.28.
- Parameters:
searchReList (Iterable[QRegularExpression])
- Return type:
bool
- readFromLayer(self, layer: QgsMapLayer | None)[source]¶
Reads the metadata state from a
layer’s custom properties (seeQgsMapLayer.customProperty()).See also
- Parameters:
layer (Optional[QgsMapLayer])
- rights(self) List[str][source]¶
Returns a list of attribution or copyright strings associated with the resource.
See also
- Return type:
List[str]
- saveToLayer(self, layer: QgsMapLayer | None)[source]¶
Saves the metadata to a
layer’s custom properties (seeQgsMapLayer.setCustomProperty()).See also
- Parameters:
layer (Optional[QgsMapLayer])
- setConstraints(self, constraints: Iterable[QgsLayerMetadata.Constraint])[source]¶
Sets the list of
constraintsassociated with using the resource.See also
- Parameters:
constraints (Iterable[QgsLayerMetadata.Constraint])
- setCrs(self, crs: QgsCoordinateReferenceSystem)[source]¶
Sets the coordinate reference system for the layer’s metadata.
Note that this has no link to
QgsMapLayer.setCrs(). Setting the layer’s CRS viaQgsMapLayer.setCrs()does not affect the layer’s metadata CRS, and changing the CRS from the metadata will not change the layer’s CRS or how it is projected within QGIS.While ideally these two systems are likely to be identical, it is possible to have a layer with a different CRS described by it’s accompanying metadata versus the CRS which is actually used to display and manipulate the layer within QGIS. This may be the case when a layer has an incorrect CRS within its metadata and a user has manually overridden the layer’s CRS within QGIS.
The CRS described here should either match the CRS from the layer
QgsMapLayer.crs()or the CRS from the data provider.This property should also match the CRS property used in the spatial extent.
See also
- Parameters:
- setEncoding(self, encoding: str | None)[source]¶
Sets the character
encodingof the data in the resource. Use an empty string if no encoding is set.See also
- Parameters:
encoding (Optional[str])
- setExtent(self, extent: QgsLayerMetadata.Extent)[source]¶
Sets the spatial and temporal extents associated with the resource.
See also
- Parameters:
extent (QgsLayerMetadata.Extent)
- setFees(self, fees: str | None)[source]¶
Sets the
feesassociated with using the resource. Use an empty string if no fees are set.See also
- Parameters:
fees (Optional[str])
- setLicenses(self, licenses: Iterable[str | None])[source]¶
Sets a list of
licensesassociated with the resource. (examples: http://opendefinition.org/licenses/).See also
- Parameters:
licenses (Iterable[Optional[str]])