Class: QgsLayerMetadata

class qgis.core.QgsLayerMetadata

Bases: QgsAbstractMetadataBase

Constructor for QgsLayerMetadata.

QgsLayerMetadata(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.

Methods

addConstraint

Adds an individual constraint to the existing constraints.

clone

rtype

QgsLayerMetadata

constraints

Returns a list of constraints associated with using the resource.

crs

Returns the coordinate reference system described by the layer’s metadata.

encoding

Returns the character encoding of the data in the resource.

equals

Tests whether the common metadata fields in this object are equal to other.

extent

Returns the spatial and temporal extents associated with the resource.

fees

Returns any fees associated with using the resource.

licenses

Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/).

readFromLayer

Reads the metadata state from a layer’s custom properties (see QgsMapLayer.customProperty() ).

readMetadataXml

param metadataElement

rights

Returns a list of attribution or copyright strings associated with the resource.

saveToLayer

Saves the metadata to a layer’s custom properties (see QgsMapLayer.setCustomProperty() ).

setConstraints

Sets the list of constraints associated with using the resource.

setCrs

Sets the coordinate reference system for the layer’s metadata.

setEncoding

Sets the character encoding of the data in the resource.

setExtent

Sets the spatial and temporal extents associated with the resource.

setFees

Sets the fees associated with using the resource.

setLicenses

Sets a list of licenses associated with the resource.

setRights

Sets a list of rights (attribution or copyright strings) associated with the resource.

writeMetadataXml

param metadataElement

class Constraint(constraint: str = '', type: str = '')

Bases: sip.wrapper

Constructor for Constraint.

QgsLayerMetadata.Constraint(QgsLayerMetadata.Constraint)

Parameters
  • constraint (str = '') –

  • type (str = '') –

constraint
type
class Extent

Bases: sip.wrapper

QgsLayerMetadata.Extent(QgsLayerMetadata.Extent)

setSpatialExtents(self, extents: Iterable[QgsLayerMetadata.SpatialExtent])

Sets the spatial extents of the resource.

See also

spatialExtents()

Parameters

extents (Iterable[QgsLayerMetadata.SpatialExtent]) –

setTemporalExtents(self, extents: Iterable[QgsDateTimeRange])

Sets the temporal extents of the resource.

Parameters

extents (Iterable[QgsDateTimeRange]) –

spatialExtents(self) → List[QgsLayerMetadata.SpatialExtent]

Spatial extents of the resource.

Return type

List[QgsLayerMetadata.SpatialExtent]

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. If QgsDateTimeRange.isInfinite() returns True then the temporal extent is considered to be indeterminate and continuous.

Return type

List[QgsDateTimeRange]

class SpatialExtent

Bases: sip.wrapper

QgsLayerMetadata.SpatialExtent(QgsLayerMetadata.SpatialExtent)

bounds
extentCrs
addConstraint(self, constraint: QgsLayerMetadata.Constraint)

Adds an individual constraint to the existing constraints.

See also

constraints()

See also

setConstraints()

Parameters

constraint (QgsLayerMetadata.Constraint) –

clone(self)QgsLayerMetadata
Return type

QgsLayerMetadata

constraints(self) → List[QgsLayerMetadata.Constraint]

Returns a list of constraints associated with using the resource.

See also

setConstraints()

Return type

List[QgsLayerMetadata.Constraint]

crs(self)QgsCoordinateReferenceSystem

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

setCrs()

Return type

QgsCoordinateReferenceSystem

encoding(self) → str

Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.

See also

setEncoding()

Return type

str

equals(self, other: QgsAbstractMetadataBase) → bool

Tests whether the common metadata fields in this object are equal to other.

Subclasses should utilize this method from their equality operators to test equality of base class members.

New in version 3.2.

extent(self) → QgsLayerMetadata.Extent

Returns the spatial and temporal extents associated with the resource.

See also

setExtent()

Return type

QgsLayerMetadata.Extent

fees(self) → str

Returns any fees associated with using the resource. An empty string will be returned if no fees are set.

See also

setFees()

Return type

str

licenses(self) → List[str]

Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/).

See also

setLicenses()

Return type

List[str]

readFromLayer(self, layer: QgsMapLayer)

Reads the metadata state from a layer’s custom properties (see QgsMapLayer.customProperty() ).

See also

saveToLayer()

Parameters

layer (QgsMapLayer) –

readMetadataXml(self, metadataElement: QDomElement) → bool
Parameters

metadataElement (QDomElement) –

Return type

bool

rights(self) → List[str]

Returns a list of attribution or copyright strings associated with the resource.

See also

setRights()

Return type

List[str]

saveToLayer(self, layer: QgsMapLayer)

Saves the metadata to a layer’s custom properties (see QgsMapLayer.setCustomProperty() ).

See also

readFromLayer()

Parameters

layer (QgsMapLayer) –

setConstraints(self, constraints: Iterable[QgsLayerMetadata.Constraint])

Sets the list of constraints associated with using the resource.

See also

constraints()

Parameters

constraints (Iterable[QgsLayerMetadata.Constraint]) –

setCrs(self, crs: QgsCoordinateReferenceSystem)

Sets the coordinate reference system for the layer’s metadata.

Note that this has no link to QgsMapLayer.setCrs() Setting the layer’s CRS via QgsMapLayer.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

crs()

Parameters

crs (QgsCoordinateReferenceSystem) –

setEncoding(self, encoding: str)

Sets the character encoding of the data in the resource. Use an empty string if no encoding is set.

See also

encoding()

Parameters

encoding (str) –

setExtent(self, extent: QgsLayerMetadata.Extent)

Sets the spatial and temporal extents associated with the resource.

See also

setExtent()

Parameters

extent (QgsLayerMetadata.Extent) –

setFees(self, fees: str)

Sets the fees associated with using the resource. Use an empty string if no fees are set.

See also

fees()

Parameters

fees (str) –

setLicenses(self, licenses: Iterable[str])

Sets a list of licenses associated with the resource. (examples: http://opendefinition.org/licenses/).

See also

licenses()

Parameters

licenses (Iterable[str]) –

setRights(self, rights: Iterable[str])

Sets a list of rights (attribution or copyright strings) associated with the resource.

See also

rights()

Parameters

rights (Iterable[str]) –

writeMetadataXml(self, metadataElement: QDomElement, document: QDomDocument) → bool
Parameters
  • metadataElement (QDomElement) –

  • document (QDomDocument) –

Return type

bool