QGIS API Documentation  3.0.2-Girona (307d082)
Classes | Public Types | Public Member Functions | List of all members
QgsLayerMetadata Class Reference

A structured metadata store for a map layer. More...

#include <qgslayermetadata.h>

Classes

struct  Address
 Metadata address structure. More...
 
struct  Constraint
 Metadata constraint structure. More...
 
struct  Contact
 Metadata contact structure. More...
 
struct  Extent
 Metadata extent structure. More...
 
struct  Link
 Metadata link structure. More...
 
struct  SpatialExtent
 Metadata spatial extent structure. More...
 

Public Types

typedef QList< QgsLayerMetadata::ConstraintConstraintList
 A list of constraints. More...
 
typedef QList< QgsLayerMetadata::ContactContactList
 A list of contacts. More...
 
typedef QMap< QString, QStringList > KeywordMap
 Map of vocabulary string to keyword list. More...
 
typedef QList< QgsLayerMetadata::LinkLinkList
 A list of links. More...
 

Public Member Functions

 QgsLayerMetadata ()=default
 Constructor for QgsLayerMetadata. More...
 
virtual ~QgsLayerMetadata ()=default
 
QString abstract () const
 Returns a free-form description of the resource. More...
 
void addConstraint (const QgsLayerMetadata::Constraint &constraint)
 Adds an individual constraint to the existing constraints. More...
 
void addContact (const QgsLayerMetadata::Contact &contact)
 Adds an individual contact to the existing contacts. More...
 
void addHistoryItem (const QString &text)
 Adds a single history text to the end of the existing history list. More...
 
void addKeywords (const QString &vocabulary, const QStringList &keywords)
 Adds a list of descriptive keywords for a specified vocabulary. More...
 
void addLink (const QgsLayerMetadata::Link &link)
 Adds an individual link to the existing links. More...
 
QStringList categories () const
 Returns categories of the resource. More...
 
QgsLayerMetadata::ConstraintList constraints () const
 Returns a list of constraints associated with using the resource. More...
 
QgsLayerMetadata::ContactList contacts () const
 Returns a list of contact persons or entities associated with the resource. More...
 
QgsCoordinateReferenceSystem crs () const
 Returns the coordinate reference system described by the layer's metadata. More...
 
QString encoding () const
 Returns the character encoding of the data in the resource. More...
 
const QgsLayerMetadata::Extentextent () const
 Returns the spatial and temporal extents associated with the resource. More...
 
QgsLayerMetadata::Extentextent ()
 Returns the spatial and temporal extents associated with the resource. More...
 
QString fees () const
 Returns any fees associated with using the resource. More...
 
QStringList history () const
 Returns a freeform description of the history or lineage of the resource. More...
 
QString identifier () const
 A reference, URI, URL or some other mechanism to identify the resource. More...
 
KeywordMap keywords () const
 Returns the keywords map, which is a set of descriptive keywords associated with the resource. More...
 
QStringList keywords (const QString &vocabulary) const
 Returns a list of keywords for the specified vocabulary. More...
 
QStringList keywordVocabularies () const
 Returns a list of keyword vocabularies contained in the metadata. More...
 
QString language () const
 Returns the human language associated with the resource. More...
 
QStringList licenses () const
 Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/). More...
 
QgsLayerMetadata::LinkList links () const
 Returns a list of online resources associated with the resource. More...
 
bool operator== (const QgsLayerMetadata &metadataOther) const
 
QString parentIdentifier () const
 A reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of. More...
 
void readFromLayer (const QgsMapLayer *layer)
 Reads the metadata state from a layer's custom properties (see QgsMapLayer::customProperty() ). More...
 
bool readMetadataXml (const QDomElement &metadataElement)
 Sets state from Dom document. More...
 
bool removeKeywords (const QString &vocabulary)
 Remove a vocabulary from the list. More...
 
QStringList rights () const
 Returns a list of attribution or copyright strings associated with the resource. More...
 
void saveToLayer (QgsMapLayer *layer) const
 Saves the metadata to a layer's custom properties (see QgsMapLayer::setCustomProperty() ). More...
 
void setAbstract (const QString &abstract)
 Sets a free-form abstract (description) of the resource. More...
 
void setCategories (const QStringList &categories)
 Sets categories of the resource. More...
 
void setConstraints (const QgsLayerMetadata::ConstraintList &constraints)
 Sets the list of constraints associated with using the resource. More...
 
void setContacts (const QgsLayerMetadata::ContactList &contacts)
 Sets the list of contacts or entities associated with the resource. More...
 
void setCrs (const QgsCoordinateReferenceSystem &crs)
 Sets the coordinate reference system for the layer's metadata. More...
 
void setEncoding (const QString &encoding)
 Sets the character encoding of the data in the resource. More...
 
void setExtent (const QgsLayerMetadata::Extent &extent)
 Sets the spatial and temporal extents associated with the resource. More...
 
void setFees (const QString &fees)
 Sets the fees associated with using the resource. More...
 
void setHistory (const QStringList &history)
 Sets the freeform description of the history or lineage of the resource. More...
 
void setIdentifier (const QString &identifier)
 Sets the reference, URI, URL or some other mechanism to identify the resource. More...
 
void setKeywords (const KeywordMap &keywords)
 Sets the keywords map, which is a set of descriptive keywords associated with the resource. More...
 
void setLanguage (const QString &language)
 Sets the human language associated with the resource. More...
 
void setLicenses (const QStringList &licenses)
 Sets a list of licenses associated with the resource. More...
 
void setLinks (const QgsLayerMetadata::LinkList &links)
 Sets the list of online resources associated with the resource. More...
 
void setParentIdentifier (const QString &parentIdentifier)
 Sets a reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of. More...
 
void setRights (const QStringList &rights)
 Sets a list of rights (attribution or copyright strings) associated with the resource. More...
 
void setTitle (const QString &title)
 Sets the human readable title (name) of the resource, typically displayed in search results. More...
 
void setType (const QString &type)
 Sets the type (nature) of the resource. More...
 
QString title () const
 Returns the human readable name of the resource, typically displayed in search results. More...
 
QString type () const
 Returns the nature of the resource. More...
 
bool writeMetadataXml (QDomElement &metadataElement, QDomDocument &document) const
 Stores state in Dom node. More...
 

Detailed Description

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.

Since
QGIS 3.0

Definition at line 55 of file qgslayermetadata.h.

Member Typedef Documentation

◆ ConstraintList

A list of constraints.

Definition at line 169 of file qgslayermetadata.h.

◆ ContactList

A list of contacts.

Definition at line 285 of file qgslayermetadata.h.

◆ KeywordMap

typedef QMap< QString, QStringList > QgsLayerMetadata::KeywordMap

Map of vocabulary string to keyword list.

Definition at line 62 of file qgslayermetadata.h.

◆ LinkList

A list of links.

Definition at line 345 of file qgslayermetadata.h.

Constructor & Destructor Documentation

◆ QgsLayerMetadata()

QgsLayerMetadata::QgsLayerMetadata ( )
default

Constructor for QgsLayerMetadata.

◆ ~QgsLayerMetadata()

virtual QgsLayerMetadata::~QgsLayerMetadata ( )
virtualdefault

Member Function Documentation

◆ abstract()

QString QgsLayerMetadata::abstract ( ) const

Returns a free-form description of the resource.

See also
setAbstract()

Definition at line 61 of file qgslayermetadata.cpp.

◆ addConstraint()

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

Adds an individual constraint to the existing constraints.

See also
constraints()
setConstraints()

Definition at line 81 of file qgslayermetadata.cpp.

◆ addContact()

void QgsLayerMetadata::addContact ( const QgsLayerMetadata::Contact contact)

Adds an individual contact to the existing contacts.

See also
contacts()
setContacts()

Definition at line 208 of file qgslayermetadata.cpp.

◆ addHistoryItem()

void QgsLayerMetadata::addHistoryItem ( const QString &  text)

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

See also
history()
setHistory()

Definition at line 126 of file qgslayermetadata.cpp.

◆ addKeywords()

void QgsLayerMetadata::addKeywords ( const QString &  vocabulary,
const QStringList &  keywords 
)

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

Definition at line 161 of file qgslayermetadata.cpp.

◆ addLink()

void QgsLayerMetadata::addLink ( const QgsLayerMetadata::Link link)

Adds an individual link to the existing links.

See also
links()
setLinks()

Definition at line 223 of file qgslayermetadata.cpp.

◆ categories()

QStringList QgsLayerMetadata::categories ( ) const

Returns categories of the resource.

Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.

See also
keywords()

Definition at line 181 of file qgslayermetadata.cpp.

◆ constraints()

QList< QgsLayerMetadata::Constraint > QgsLayerMetadata::constraints ( ) const

Returns a list of constraints associated with using the resource.

See also
setConstraints()

Definition at line 86 of file qgslayermetadata.cpp.

◆ contacts()

QList< QgsLayerMetadata::Contact > QgsLayerMetadata::contacts ( ) const

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

See also
setContacts()

Definition at line 198 of file qgslayermetadata.cpp.

◆ crs()

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.

See also
setCrs()

Definition at line 141 of file qgslayermetadata.cpp.

◆ encoding()

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.

See also
setEncoding()

Definition at line 131 of file qgslayermetadata.cpp.

◆ extent() [1/2]

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

Returns the spatial and temporal extents associated with the resource.

See also
setExtent()

Definition at line 736 of file qgslayermetadata.cpp.

◆ extent() [2/2]

QgsLayerMetadata::Extent & QgsLayerMetadata::extent ( )

Returns the spatial and temporal extents associated with the resource.

See also
setExtent()

Definition at line 741 of file qgslayermetadata.cpp.

◆ fees()

QString QgsLayerMetadata::fees ( ) const

Returns any fees associated with using the resource.

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

See also
setFees()

Definition at line 71 of file qgslayermetadata.cpp.

◆ history()

QStringList QgsLayerMetadata::history ( ) const

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

See also
setHistory()

Definition at line 116 of file qgslayermetadata.cpp.

◆ identifier()

QString QgsLayerMetadata::identifier ( ) const

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

See also
setIdentifier()

Definition at line 21 of file qgslayermetadata.cpp.

◆ keywords() [1/2]

QMap< QString, QStringList > QgsLayerMetadata::keywords ( ) const

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

Definition at line 151 of file qgslayermetadata.cpp.

◆ keywords() [2/2]

QStringList QgsLayerMetadata::keywords ( const QString &  vocabulary) const

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.

See also
keywordVocabularies()

Definition at line 176 of file qgslayermetadata.cpp.

◆ keywordVocabularies()

QStringList QgsLayerMetadata::keywordVocabularies ( ) const

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

Definition at line 171 of file qgslayermetadata.cpp.

◆ language()

QString QgsLayerMetadata::language ( ) const

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

Definition at line 228 of file qgslayermetadata.cpp.

◆ licenses()

QStringList QgsLayerMetadata::licenses ( ) const

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

See also
setLicenses()

Definition at line 106 of file qgslayermetadata.cpp.

◆ links()

QList< QgsLayerMetadata::Link > QgsLayerMetadata::links ( ) const

Returns a list of online resources associated with the resource.

See also
setLinks()

Definition at line 213 of file qgslayermetadata.cpp.

◆ operator==()

bool QgsLayerMetadata::operator== ( const QgsLayerMetadata metadataOther) const

Definition at line 776 of file qgslayermetadata.cpp.

◆ parentIdentifier()

QString QgsLayerMetadata::parentIdentifier ( ) const

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.

See also
setParentIdentifier()

Definition at line 31 of file qgslayermetadata.cpp.

◆ readFromLayer()

void QgsLayerMetadata::readFromLayer ( const QgsMapLayer layer)

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

See also
saveToLayer()

Definition at line 259 of file qgslayermetadata.cpp.

◆ readMetadataXml()

bool QgsLayerMetadata::readMetadataXml ( const QDomElement &  metadataElement)

Sets state from Dom document.

Parameters
metadataElementThe Dom element corresponding to ``resourceMetadata'' tag
Returns
true if successful

Definition at line 281 of file qgslayermetadata.cpp.

◆ removeKeywords()

bool QgsLayerMetadata::removeKeywords ( const QString &  vocabulary)

Remove a vocabulary from the list.

See also
setKeywords()
addKeywords()

Definition at line 166 of file qgslayermetadata.cpp.

◆ rights()

QStringList QgsLayerMetadata::rights ( ) const

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

See also
setRights()

Definition at line 96 of file qgslayermetadata.cpp.

◆ saveToLayer()

void QgsLayerMetadata::saveToLayer ( QgsMapLayer layer) const

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

See also
readFromLayer()

Definition at line 238 of file qgslayermetadata.cpp.

◆ setAbstract()

void QgsLayerMetadata::setAbstract ( const QString &  abstract)

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

See also
abstract()

Definition at line 66 of file qgslayermetadata.cpp.

◆ setCategories()

void QgsLayerMetadata::setCategories ( const QStringList &  categories)

Sets categories of the resource.

Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.

See also
keywords()

Definition at line 193 of file qgslayermetadata.cpp.

◆ setConstraints()

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

Sets the list of constraints associated with using the resource.

See also
constraints()

Definition at line 91 of file qgslayermetadata.cpp.

◆ setContacts()

void QgsLayerMetadata::setContacts ( const QgsLayerMetadata::ContactList contacts)

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

Any existing contacts will be replaced.

See also
contacts()
addContact()

Definition at line 203 of file qgslayermetadata.cpp.

◆ setCrs()

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.

See also
crs()

Definition at line 146 of file qgslayermetadata.cpp.

◆ setEncoding()

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.

See also
encoding()

Definition at line 136 of file qgslayermetadata.cpp.

◆ setExtent()

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

Sets the spatial and temporal extents associated with the resource.

See also
setExtent()

Definition at line 746 of file qgslayermetadata.cpp.

◆ setFees()

void QgsLayerMetadata::setFees ( const QString &  fees)

Sets the fees associated with using the resource.

Use an empty string if no fees are set.

See also
fees()

Definition at line 76 of file qgslayermetadata.cpp.

◆ setHistory()

void QgsLayerMetadata::setHistory ( const QStringList &  history)

Sets the freeform description of the history or lineage of the resource.

Any existing history items will be overwritten.

See also
addHistoryItem()
history()

Definition at line 121 of file qgslayermetadata.cpp.

◆ setIdentifier()

void QgsLayerMetadata::setIdentifier ( const QString &  identifier)

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

See also
identifier()

Definition at line 26 of file qgslayermetadata.cpp.

◆ setKeywords()

void QgsLayerMetadata::setKeywords ( const KeywordMap keywords)

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

Definition at line 156 of file qgslayermetadata.cpp.

◆ setLanguage()

void QgsLayerMetadata::setLanguage ( const QString &  language)

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

Definition at line 233 of file qgslayermetadata.cpp.

◆ setLicenses()

void QgsLayerMetadata::setLicenses ( const QStringList &  licenses)

Sets a list of licenses associated with the resource.

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

See also
licenses()

Definition at line 111 of file qgslayermetadata.cpp.

◆ setLinks()

void QgsLayerMetadata::setLinks ( const QgsLayerMetadata::LinkList links)

Sets the list of online resources associated with the resource.

Any existing links will be replaced.

See also
links()
addLink()

Definition at line 218 of file qgslayermetadata.cpp.

◆ setParentIdentifier()

void QgsLayerMetadata::setParentIdentifier ( const QString &  parentIdentifier)

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.

See also
parentIdentifier()

Definition at line 36 of file qgslayermetadata.cpp.

◆ setRights()

void QgsLayerMetadata::setRights ( const QStringList &  rights)

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

See also
rights()

Definition at line 101 of file qgslayermetadata.cpp.

◆ setTitle()

void QgsLayerMetadata::setTitle ( const QString &  title)

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

See also
title()

Definition at line 56 of file qgslayermetadata.cpp.

◆ setType()

void QgsLayerMetadata::setType ( const QString &  type)

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

Definition at line 46 of file qgslayermetadata.cpp.

◆ title()

QString QgsLayerMetadata::title ( ) const

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

See also
setTitle()

Definition at line 51 of file qgslayermetadata.cpp.

◆ type()

QString QgsLayerMetadata::type ( ) const

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

Definition at line 41 of file qgslayermetadata.cpp.

◆ writeMetadataXml()

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

Stores state in Dom node.

Parameters
metadataElementis a Dom element corresponding to ``resourceMetadata'' tag
documentis a the dom document being written
Returns
true if successful

Definition at line 493 of file qgslayermetadata.cpp.


The documentation for this class was generated from the following files: