QgsLayerMetadata class

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.

Base classes

class QgsAbstractMetadataBase
An abstract base class for metadata stores.

Public types

struct Constraint
Metadata constraint structure.
struct Extent
Metadata extent structure.
struct SpatialExtent
Metadata spatial extent structure.
using ConstraintList = QList<QgsLayerMetadata::Constraint>
A list of constraints.

Constructors, destructors, conversion operators

QgsLayerMetadata() defaulted
Constructor for QgsLayerMetadata.

Public functions

void addConstraint(const QgsLayerMetadata::Constraint& constraint)
Adds an individual constraint to the existing constraints.
auto clone() const -> QgsLayerMetadata* override
Clones the metadata object.
auto constraints() const -> QgsLayerMetadata::ConstraintList
Returns a list of constraints associated with using the resource.
auto crs() const -> QgsCoordinateReferenceSystem
Returns the coordinate reference system described by the layer's metadata.
auto encoding() const -> QString
Returns the character encoding of the data in the resource.
auto extent() const -> const QgsLayerMetadata::Extent&
Returns the spatial and temporal extents associated with the resource.
auto extent() -> QgsLayerMetadata::Extent&
Returns the spatial and temporal extents associated with the resource.
auto fees() const -> QString
Returns any fees associated with using the resource.
auto licenses() const -> QStringList
Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/).
void readFromLayer(const QgsMapLayer* layer)
Reads the metadata state from a layer's custom properties (see QgsMapLayer::customProperty() ).
auto readMetadataXml(const QDomElement& metadataElement) -> bool override
Sets state from DOM document.
auto rights() const -> QStringList
Returns a list of attribution or copyright strings associated with the resource.
void saveToLayer(QgsMapLayer* layer) const
Saves the metadata to a layer's custom properties (see QgsMapLayer::setCustomProperty() ).
void setConstraints(const QgsLayerMetadata::ConstraintList& constraints)
Sets the list of constraints associated with using the resource.
void setCrs(const QgsCoordinateReferenceSystem& crs)
Sets the coordinate reference system for the layer's metadata.
void setEncoding(const QString& encoding)
Sets the character encoding of the data in the resource.
void setExtent(const QgsLayerMetadata::Extent& extent)
Sets the spatial and temporal extents associated with the resource.
void setFees(const QString& fees)
Sets the fees associated with using the resource.
void setLicenses(const QStringList& licenses)
Sets a list of licenses associated with the resource.
void setRights(const QStringList& rights)
Sets a list of rights (attribution or copyright strings) associated with the resource.
auto writeMetadataXml(QDomElement& metadataElement, QDomDocument& document) const -> bool override
Stores state in a DOM node.

Function documentation

void QgsLayerMetadata::addConstraint(const QgsLayerMetadata::Constraint& constraint)

Adds an individual constraint to the existing constraints.

QgsLayerMetadata* QgsLayerMetadata::clone() const override

Clones the metadata object.

QgsLayerMetadata::ConstraintList QgsLayerMetadata::constraints() const

Returns a list of constraints associated with using the resource.

QgsCoordinateReferenceSystem QgsLayerMetadata::crs() const

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.

QString QgsLayerMetadata::encoding() const

Returns the character encoding of the data in the resource.

An empty string will be returned if no encoding is set.

const QgsLayerMetadata::Extent& QgsLayerMetadata::extent() const

Returns the spatial and temporal extents associated with the resource.

QgsLayerMetadata::Extent& QgsLayerMetadata::extent()

Returns the spatial and temporal extents associated with the resource.

QString QgsLayerMetadata::fees() const

Returns any fees associated with using the resource.

An empty string will be returned if no fees are set.

QStringList QgsLayerMetadata::licenses() const

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

void QgsLayerMetadata::readFromLayer(const QgsMapLayer* layer)

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

bool QgsLayerMetadata::readMetadataXml(const QDomElement& metadataElement) override

Sets state from DOM document.

Parameters
metadataElement The DOM element corresponding to ``resourceMetadata'' tag
Returns true if successful

Subclasses which override this method should take care to also call the base class method in order to read common metadata properties.

QStringList QgsLayerMetadata::rights() const

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

void QgsLayerMetadata::saveToLayer(QgsMapLayer* layer) const

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

void QgsLayerMetadata::setConstraints(const QgsLayerMetadata::ConstraintList& constraints)

Sets the list of constraints associated with using the resource.

void QgsLayerMetadata::setCrs(const QgsCoordinateReferenceSystem& crs)

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.

void QgsLayerMetadata::setEncoding(const QString& encoding)

Sets the character encoding of the data in the resource.

Use an empty string if no encoding is set.

void QgsLayerMetadata::setExtent(const QgsLayerMetadata::Extent& extent)

Sets the spatial and temporal extents associated with the resource.

void QgsLayerMetadata::setFees(const QString& fees)

Sets the fees associated with using the resource.

Use an empty string if no fees are set.

void QgsLayerMetadata::setLicenses(const QStringList& licenses)

Sets a list of licenses associated with the resource.

(examples: http://opendefinition.org/licenses/).

void QgsLayerMetadata::setRights(const QStringList& rights)

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

bool QgsLayerMetadata::writeMetadataXml(QDomElement& metadataElement, QDomDocument& document) const override

Stores state in a DOM node.

Parameters
metadataElement is a DOM element corresponding to ``resourceMetadata'' tag
document is a the DOM document being written
Returns true if successful

Subclasses which override this method should take care to also call the base class method in order to write common metadata properties.