Class: QgsAbstractMetadataBase

An abstract base class for metadata stores.

QgsAbstractMetadataBase is the base class for handling storage and management of the metadata for various map related assets. This class is an internal QGIS format with a common metadata structure. It is subclassed by layer and project specific metadata classes, such as QgsLayerMetadata and QgsProjectMetadata.

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 QgsAbstractMetadataBase may result in a loss of information.

This class is designed to follow the specifications detailed in the schema definition available at resources/qgis-base-metadata.xsd within the QGIS source code.

Metadata can be validated through the use of QgsAbstractMetadataBaseValidator subclasses. E.g. validating against the native QGIS metadata schema can be performed using QgsNativeMetadataValidator.

Added in version 3.2.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractMetadataBase

Subclasses

QgsLayerMetadata

A structured metadata store for a map layer.

QgsProjectMetadata

A structured metadata store for a project.

Abstract Methods

clone

Clones the metadata object.

Methods

abstract

Returns a free-form description of the resource.

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.

contacts

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

dateTime

Returns the date for the specified date type.

equals

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

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.

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.

removeKeywords

Remove a vocabulary from the list.

setAbstract

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

setCategories

Sets categories of the resource.

setContacts

Sets the list of contacts or entities associated with the resource.

setDateTime

Sets a date value for the specified date type.

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.

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.

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.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractMetadataBase. See the FAQ for more details.

combine

Combines the metadata from this object with the metadata from an other object.

readMetadataXml

Sets state from DOM document.

writeMetadataXml

Stores state in a DOM node.

class qgis.core.QgsAbstractMetadataBase[source]

Bases: object

__init__()

Constructor for QgsAbstractMetadataBase.

QgsAbstractMetadataBase cannot be instantiated directly, it must be subclassed.

__init__(a0: QgsAbstractMetadataBase)
Parameters:

a0 (QgsAbstractMetadataBase)

class Address

Bases: object

Metadata address structure.

Added in version 3.2.

address: str

Free-form physical address component, e.g. ‘221B Baker St’ or ‘P.O. Box 196’.

administrativeArea: str

Administrative area (state, province/territory, etc.).

city: str

City or locality name.

country: str

Free-form country string.

postalCode: str

Postal (or ZIP) code.

type: str

Type of address, e.g. ‘postal’.

class Contact

Bases: object

Metadata contact structure.

Added in version 3.2.

addresses: List[QgsAbstractMetadataBase.Address]

List of addresses associated with this contact.

email: str

Electronic mail address.

Note

Do not include mailto: protocol as part of the email address.

fax: str

Facsimile telephone.

name: str

Name of contact.

organization: str

Organization contact belongs to/represents.

position: str

Position/title of contact.

role: str

Role of contact. Acceptable values are those from the ISO 19115 CI_RoleCode specifications (see http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml). E.g. ‘custodian’, ‘owner’, ‘distributor’, etc.

voice: str

Voice telephone.

Bases: object

Metadata link structure.

Added in version 3.2.

description: str

Abstract text about link.

format: str

Format specification of online resource. It is strongly suggested to use GDAL/OGR format values.

mimeType: str

MIME type representative of the online resource response (image/png, application/json, etc.)

name: str

Short link name. E.g. WMS layer name.

size: str

Estimated size (in bytes) of the online resource response.

type: str

Link type. It is strongly suggested to use values from the ‘identifier’ column in https://github.com/OSGeo/Cat-Interop/blob/master/LinkPropertyLookupTable.csv

url: str

Link url. If the URL is an OWS server, specify the base URL only without parameters like service=xxx….

abstract(self) str[source]

Returns a free-form description of the resource.

See also

setAbstract()

Return type:

str

addContact(self, contact: QgsAbstractMetadataBase.Contact)[source]

Adds an individual contact to the existing contacts.

See also

contacts()

See also

setContacts()

Parameters:

contact (QgsAbstractMetadataBase.Contact)

addHistoryItem(self, text: str | None)[source]

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

See also

history()

See also

setHistory()

Parameters:

text (Optional[str])

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

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

Parameters:
  • vocabulary (Optional[str])

  • keywords (Iterable[Optional[str]])

Adds an individual link to the existing links.

See also

links()

See also

setLinks()

Parameters:

link (QgsAbstractMetadataBase.Link)

categories(self) List[str][source]

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

See also

keywords()

Return type:

List[str]

abstract clone(self) QgsAbstractMetadataBase | None[source]

Clones the metadata object.

Added in version 3.2.

Return type:

Optional[QgsAbstractMetadataBase]

virtual combine(self, other: QgsAbstractMetadataBase | None)[source]

Combines the metadata from this object with the metadata from an other object.

Any existing values in this object will be overwritten by non-empty values from other.

Added in version 3.20.

Parameters:

other (Optional[QgsAbstractMetadataBase])

contacts(self) List[QgsAbstractMetadataBase.Contact][source]

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

See also

setContacts()

Return type:

List[QgsAbstractMetadataBase.Contact]

dateTime(self, type: Qgis.MetadataDateType) QDateTime[source]

Returns the date for the specified date type.

See also

setDateTime()

Added in version 3.30.

Parameters:

type (Qgis.MetadataDateType)

Return type:

QDateTime

equals(self, other: QgsAbstractMetadataBase) bool[source]

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.

Added in version 3.2.

Parameters:

other (QgsAbstractMetadataBase)

Return type:

bool

history(self) List[str][source]

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

See also

setHistory()

Return type:

List[str]

identifier(self) str[source]

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

See also

setIdentifier()

Return type:

str

keywordVocabularies(self) List[str][source]

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

Return type:

List[str]

keywords(self) Dict[str, List[str]][source]

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

Return type:

Dict[str, List[str]]

keywords(self, vocabulary: str | None) List[str][source]

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.

Parameters:

vocabulary (Optional[str])

Return type:

List[str]

language(self) str[source]

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

Return type:

str

Returns a list of online resources associated with the resource.

See also

setLinks()

Return type:

List[QgsAbstractMetadataBase.Link]

parentIdentifier(self) str[source]

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.

Return type:

str

virtual readMetadataXml(self, metadataElement: QDomElement) bool[source]

Sets state from DOM document.

Parameters:

metadataElement (QDomElement) – The DOM element corresponding to resourceMetadata tag

Return type:

bool

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.

removeKeywords(self, vocabulary: str | None) bool[source]

Remove a vocabulary from the list.

See also

setKeywords()

See also

addKeywords()

Parameters:

vocabulary (Optional[str])

Return type:

bool

setAbstract(self, abstract: str | None)[source]

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

See also

abstract()

Parameters:

abstract (Optional[str])

setCategories(self, categories: Iterable[str | None])[source]

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

See also

keywords()

Parameters:

categories (Iterable[Optional[str]])

setContacts(self, contacts: Iterable[QgsAbstractMetadataBase.Contact])[source]

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

See also

contacts()

See also

addContact()

Parameters:

contacts (Iterable[QgsAbstractMetadataBase.Contact])

setDateTime(self, type: Qgis.MetadataDateType, date: QDateTime | datetime.datetime)[source]

Sets a date value for the specified date type.

See also

dateTime()

Added in version 3.30.

Parameters:
setHistory(self, history: Iterable[str | None])[source]

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

Parameters:

history (Iterable[Optional[str]])

setIdentifier(self, identifier: str | None)[source]

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

See also

identifier()

Parameters:

identifier (Optional[str])

setKeywords(self, keywords: Dict[str | None, Iterable[str | None]])[source]

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

Parameters:

keywords (Dict[Optional[str], Iterable[Optional[str]]])

setLanguage(self, language: str | None)[source]

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

Parameters:

language (Optional[str])

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

See also

links()

See also

addLink()

Parameters:

links (Iterable[QgsAbstractMetadataBase.Link])

setParentIdentifier(self, parentIdentifier: str | None)[source]

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.

Parameters:

parentIdentifier (Optional[str])

setTitle(self, title: str | None)[source]

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

See also

title()

Parameters:

title (Optional[str])

setType(self, type: str | None)[source]

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

Parameters:

type (Optional[str])

title(self) str[source]

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

See also

setTitle()

Return type:

str

type(self) str[source]

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

Return type:

str

virtual writeMetadataXml(self, metadataElement: QDomElement, document: QDomDocument) bool[source]

Stores state in a DOM node.

Parameters:
  • metadataElement (QDomElement) – is a DOM element corresponding to resourceMetadata tag

  • document (QDomDocument) – is a the DOM document being written

Return type:

bool

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.