Subgroup: Layer

Class: QgsLayerMetadata

class qgis.core.QgsLayerMetadata

Bases: sip.wrapper

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.

New in version 3.0: Methods

abstract Returns a free-form description of the resource.
addConstraint Adds an individual constraint to the existing constraints.
addContact Adds an individual contact to the existing contacts.
addHistoryItem Adds a single history text to the end of the existing history list.
addKeywords Adds a list of descriptive keywords for a specified vocabulary.
addLink Adds an individual link to the existing links.
categories Returns categories of the resource.
constraints Returns a list of constraints associated with using the resource.
contacts Returns a list of contact persons or entities associated with 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.
extent Returns the spatial and temporal extents associated with the resource.
fees Returns any fees associated with using the resource.
history Returns a freeform description of the history or lineage of the resource.
identifier A reference, URI, URL or some other mechanism to identify the resource.
keywordVocabularies Returns a list of keyword vocabularies contained in the metadata.
keywords Returns the keywords map, which is a set of descriptive keywords associated with the resource.
language Returns the human language associated with the resource.
licenses Returns a list of licenses associated with the resource (examples: http://opendefinition.
links Returns a list of online resources associated with the resource.
parentIdentifier A reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of.
readFromLayer Reads the metadata state from a layer’s custom properties (see QgsMapLayer.
readMetadataXml Sets state from Dom document
removeKeywords Remove a vocabulary from the list.
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.
setAbstract Sets a free-form abstract (description) of the resource.
setCategories Sets categories of the resource.
setConstraints Sets the list of constraints associated with using the resource.
setContacts Sets the list of contacts or entities associated with 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.
setHistory Sets the freeform description of the history or lineage of the resource.
setIdentifier Sets the reference, URI, URL or some other mechanism to identify the resource.
setKeywords Sets the keywords map, which is a set of descriptive keywords associated with the resource.
setLanguage Sets the human language associated with the resource.
setLicenses Sets a list of licenses associated with the resource.
setLinks Sets the list of online resources associated with the resource.
setParentIdentifier Sets a reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of.
setRights Sets a list of rights (attribution or copyright strings) associated with the resource.
setTitle Sets the human readable title (name) of the resource, typically displayed in search results.
setType Sets the type (nature) of the resource.
title Returns the human readable name of the resource, typically displayed in search results.
type Returns the nature of the resource.
writeMetadataXml Stores state in Dom node

Signals

Attributes

class Address(type: str = '', address: str = '', city: str = '', administrativeArea: str = '', postalCode: str = '', country: str = '')

Bases: sip.wrapper

Constructor for Address.

QgsLayerMetadata.Address(QgsLayerMetadata.Address)

address
administrativeArea
city
country
postalCode
type
class Constraint(constraint: str = '', type: str = '')

Bases: sip.wrapper

Constructor for Constraint.

QgsLayerMetadata.Constraint(QgsLayerMetadata.Constraint)

constraint
type
class Contact(name: str = '')

Bases: sip.wrapper

Constructor for Contact.

QgsLayerMetadata.Contact(QgsLayerMetadata.Contact)

addresses
email
fax
name
organization
position
role
voice
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()

setTemporalExtents(self, extents: Iterable[QgsDateTimeRange])

Sets the temporal extents of the resource.

spatialExtents(self) → object

Spatial extents of the resource.

temporalExtents(self) → object

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.

Bases: sip.wrapper

Constructor for Link.

QgsLayerMetadata.Link(QgsLayerMetadata.Link)

description
format
mimeType
name
size
type
url
class SpatialExtent

Bases: sip.wrapper

QgsLayerMetadata.SpatialExtent(QgsLayerMetadata.SpatialExtent)

bounds
extentCrs
abstract(self) → str

Returns a free-form description of the resource.

See also

setAbstract()

addConstraint(self, constraint: QgsLayerMetadata.Constraint)

Adds an individual constraint to the existing constraints.

See also

constraints()

See also

setConstraints()

addContact(self, contact: QgsLayerMetadata.Contact)

Adds an individual contact to the existing contacts.

See also

contacts()

See also

setContacts()

addHistoryItem(self, text: str)

Adds a single history text to the end of the existing history list.

See also

history()

See also

setHistory()

addKeywords(self, vocabulary: str, keywords: Iterable[str])

Adds a list of descriptive keywords for a specified vocabulary. Any existing keywords for the same vocabulary will be replaced. Other vocabularies will not be affected.

The vocabulary string is a reference (URI/URL preferred) to a codelist or vocabulary associated with keyword list.

See also

setKeywords()

Adds an individual link to the existing links.

See also

links()

See also

setLinks()

categories(self) → List[str]

Returns categories of the resource. Categories are stored using a special vocabulary ‘gmd:topicCategory’ in keywords.

See also

keywords()

constraints(self) → object

Returns a list of constraints associated with using the resource.

See also

setConstraints()

contacts(self) → object

Returns a list of contact persons or entities associated with the resource.

See also

setContacts()

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()

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()

extent(self) → QgsLayerMetadata.Extent

Returns the spatial and temporal extents associated with the resource.

See also

setExtent()

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()

history(self) → List[str]

Returns a freeform description of the history or lineage of the resource.

See also

setHistory()

identifier(self) → str

A reference, URI, URL or some other mechanism to identify the resource.

See also

setIdentifier()

keywordVocabularies(self) → List[str]

Returns a list of keyword vocabularies contained in the metadata.

The vocabulary string is a reference (URI/URL preferred) to a codelist or vocabulary associated with keyword list.

See also

keywords()

keywords(self) → object

Returns the keywords map, which is a set of descriptive keywords associated with the resource.

The map key is the vocabulary string and map value is a list of keywords for that vocabulary.

The vocabulary string is a reference (URI/URL preferred) to a codelist or vocabulary associated with keyword list.

See also

setKeywords()

keywords(self, vocabulary: str) -> List[str] Returns a list of keywords for the specified vocabulary. If the vocabulary is not contained in the metadata, an empty list will be returned.

The vocabulary string is a reference (URI/URL preferred) to a codelist or vocabulary associated with keyword list.

language(self) → str

Returns the human language associated with the resource. Usually the returned string will follow either the ISO 639.2 or ISO 3166 specifications, e.g. ‘ENG’ or ‘SPA’, however this is not a hard requirement and the caller must account for non compliant values.

See also

setLanguage()

licenses(self) → List[str]

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

See also

setLicenses()

Returns a list of online resources associated with the resource.

See also

setLinks()

parentIdentifier(self) → str

A reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of. Returns an empty string if no parent identifier is set.

readFromLayer(self, layer: QgsMapLayer)

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

See also

saveToLayer()

readMetadataXml(self, metadataElement: QDomElement) → bool

Sets state from Dom document

Parameters:metadataElement – The Dom element corresponding to ``resourceMetadata’’ tag
Returns:true if successful
removeKeywords(self, vocabulary: str) → bool

Remove a vocabulary from the list.

See also

setKeywords()

See also

addKeywords()

rights(self) → List[str]

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

See also

setRights()

saveToLayer(self, layer: QgsMapLayer)

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

See also

readFromLayer()

setAbstract(self, abstract: str)

Sets a free-form abstract (description) of the resource.

See also

abstract()

setCategories(self, categories: Iterable[str])

Sets categories of the resource. Categories are stored using a special vocabulary ‘gmd:topicCategory’ in keywords.

See also

keywords()

setConstraints(self, constraints: object)

Sets the list of constraints associated with using the resource.

See also

constraints()

setContacts(self, contacts: object)

Sets the list of contacts or entities associated with the resource. Any existing contacts will be replaced.

See also

contacts()

See also

addContact()

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()

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()

setExtent(self, extent: QgsLayerMetadata.Extent)

Sets the spatial and temporal extents associated with the resource.

See also

setExtent()

setFees(self, fees: str)

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

See also

fees()

setHistory(self, history: Iterable[str])

Sets the freeform description of the history or lineage of the resource. Any existing history items will be overwritten.

See also

addHistoryItem()

See also

history()

setIdentifier(self, identifier: str)

Sets the reference, URI, URL or some other mechanism to identify the resource.

See also

identifier()

setKeywords(self, keywords: object)

Sets the keywords map, which is a set of descriptive keywords associated with the resource.

The map key is the vocabulary string and map value is a list of keywords for that vocabulary. Calling this replaces any existing keyword vocabularies.

The vocabulary string is a reference (URI/URL preferred) to a codelist or vocabulary associated with keyword list.

See also

keywords()

See also

addKeywords()

setLanguage(self, language: str)

Sets the human language associated with the resource. While a formal vocabulary is not imposed, ideally values should be taken from the ISO 639.2 or ISO 3166 specifications, e.g. ‘ENG’ or ‘SPA’ (ISO 639.2) or ‘EN-AU’ (ISO 3166).

See also

language()

setLicenses(self, licenses: Iterable[str])

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

See also

licenses()

Sets the list of online resources associated with the resource. Any existing links will be replaced.

See also

links()

See also

addLink()

setParentIdentifier(self, parentIdentifier: str)

Sets a reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of. Set an empty string if no parent identifier is required.

setRights(self, rights: Iterable[str])

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

See also

rights()

setTitle(self, title: str)

Sets the human readable title (name) of the resource, typically displayed in search results.

See also

title()

setType(self, type: str)

Sets the type (nature) of the resource. While a formal vocabulary is not imposed, it is advised to use the ISO 19115 MD_ScopeCode values. E.g. ‘dataset’ or ‘series’.

See also

type()

title(self) → str

Returns the human readable name of the resource, typically displayed in search results.

See also

setTitle()

type(self) → str

Returns the nature of the resource. While a formal vocabulary is not imposed, it is advised to use the ISO 19115 MD_ScopeCode values. E.g. ‘dataset’ or ‘series’.

See also

setType()

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

Stores state in Dom node

Parameters:
  • metadataElement – is a Dom element corresponding to ``resourceMetadata’’ tag
  • document – is a the dom document being written
Returns:

true if successful