QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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>

Inheritance diagram for QgsLayerMetadata:
Inheritance graph
[legend]

Classes

struct  Constraint
 Metadata constraint structure. More...
 
struct  Extent
 Metadata extent structure. More...
 
struct  SpatialExtent
 Metadata spatial extent structure. More...
 

Public Types

typedef QList< QgsLayerMetadata::ConstraintConstraintList
 A list of constraints.
 
- Public Types inherited from QgsAbstractMetadataBase
typedef QList< QgsAbstractMetadataBase::ContactContactList
 A list of contacts.
 
typedef QMap< QString, QStringList > KeywordMap
 Map of vocabulary string to keyword list.
 
typedef QList< QgsAbstractMetadataBase::LinkLinkList
 A list of links.
 

Public Member Functions

 QgsLayerMetadata ()=default
 
void addConstraint (const QgsLayerMetadata::Constraint &constraint)
 Adds an individual constraint to the existing constraints.
 
QgsLayerMetadataclone () const override
 Clones the metadata object.
 
void combine (const QgsAbstractMetadataBase *other) override
 Combines the metadata from this object with the metadata from an other object.
 
QgsLayerMetadata::ConstraintList constraints () const
 Returns a list of constraints associated with using the resource.
 
bool contains (const QString &searchString) const
 Returns true if the metadata identifier, title, abstract, keywords or categories contain searchString using case-insensitive search.
 
QgsCoordinateReferenceSystem crs () const
 Returns the coordinate reference system described by the layer's metadata.
 
QString encoding () const
 Returns the character encoding of the data in the resource.
 
QgsLayerMetadata::Extentextent ()
 Returns the spatial and temporal extents associated with the resource.
 
const QgsLayerMetadata::Extentextent () const
 Returns the spatial and temporal extents associated with the resource.
 
QString fees () const
 Returns any fees associated with using the resource.
 
QStringList licenses () const
 Returns a list of licenses associated with the resource (examples: http://opendefinition.org/licenses/).
 
bool matches (const QVector< QRegularExpression > &searchReList) const
 Returns true if the metadata identifier, title, abstract, keywords or categories matches any regular expression from searchReList.
 
bool operator== (const QgsLayerMetadata &metadataOther) const
 
void readFromLayer (const QgsMapLayer *layer)
 Reads the metadata state from a layer's custom properties (see QgsMapLayer::customProperty() ).
 
bool readMetadataXml (const QDomElement &metadataElement) override
 Sets state from DOM document.
 
QStringList rights () const
 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.
 
bool writeMetadataXml (QDomElement &metadataElement, QDomDocument &document) const override
 Stores state in a DOM node.
 
- Public Member Functions inherited from QgsAbstractMetadataBase
virtual ~QgsAbstractMetadataBase ()=default
 
QString abstract () const
 Returns a free-form description of the resource.
 
void addContact (const QgsAbstractMetadataBase::Contact &contact)
 Adds an individual contact to the existing contacts.
 
void addHistoryItem (const QString &text)
 Adds a single history text to the end of the existing history list.
 
void addKeywords (const QString &vocabulary, const QStringList &keywords)
 Adds a list of descriptive keywords for a specified vocabulary.
 
void addLink (const QgsAbstractMetadataBase::Link &link)
 Adds an individual link to the existing links.
 
QStringList categories () const
 Returns categories of the resource.
 
QgsAbstractMetadataBase::ContactList contacts () const
 Returns a list of contact persons or entities associated with the resource.
 
QDateTime dateTime (Qgis::MetadataDateType type) const
 Returns the date for the specified date type.
 
QStringList history () const
 Returns a freeform description of the history or lineage of the resource.
 
QString identifier () const
 A reference, URI, URL or some other mechanism to identify the resource.
 
QgsAbstractMetadataBase::KeywordMap keywords () const
 Returns the keywords map, which is a set of descriptive keywords associated with the resource.
 
QStringList keywords (const QString &vocabulary) const
 Returns a list of keywords for the specified vocabulary.
 
QStringList keywordVocabularies () const
 Returns a list of keyword vocabularies contained in the metadata.
 
QString language () const
 Returns the human language associated with the resource.
 
QgsAbstractMetadataBase::LinkList links () const
 Returns a list of online resources associated with the resource.
 
QString parentIdentifier () const
 A reference, URI, URL or some other mechanism to identify the parent resource that this resource is a part (child) of.
 
bool removeKeywords (const QString &vocabulary)
 Remove a vocabulary from the list.
 
void setAbstract (const QString &abstract)
 Sets a free-form abstract (description) of the resource.
 
void setCategories (const QStringList &categories)
 Sets categories of the resource.
 
void setContacts (const QgsAbstractMetadataBase::ContactList &contacts)
 Sets the list of contacts or entities associated with the resource.
 
void setDateTime (Qgis::MetadataDateType type, QDateTime date)
 Sets a date value for the specified date type.
 
void setHistory (const QStringList &history)
 Sets the freeform description of the history or lineage of the resource.
 
void setIdentifier (const QString &identifier)
 Sets the reference, URI, URL or some other mechanism to identify the resource.
 
void setKeywords (const QgsAbstractMetadataBase::KeywordMap &keywords)
 Sets the keywords map, which is a set of descriptive keywords associated with the resource.
 
void setLanguage (const QString &language)
 Sets the human language associated with the resource.
 
void setLinks (const QgsAbstractMetadataBase::LinkList &links)
 Sets the list of online resources associated with the resource.
 
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.
 
void setTitle (const QString &title)
 Sets the human readable title (name) of the resource, typically displayed in search results.
 
void setType (const QString &type)
 Sets the type (nature) of the resource.
 
QString title () const
 Returns the human readable name of the resource, typically displayed in search results.
 
QString type () const
 Returns the nature of the resource.
 

Additional Inherited Members

- Protected Member Functions inherited from QgsAbstractMetadataBase
 QgsAbstractMetadataBase ()=default
 Constructor for QgsAbstractMetadataBase.
 
bool equals (const QgsAbstractMetadataBase &other) const
 Tests whether the common metadata fields in this object are equal to other.
 
- Protected Attributes inherited from QgsAbstractMetadataBase
QString mAbstract
 
QgsAbstractMetadataBase::ContactList mContacts
 
QMap< Qgis::MetadataDateType, QDateTime > mDates
 Metadata dates.
 
QStringList mHistory
 
QString mIdentifier
 
QgsAbstractMetadataBase::KeywordMap mKeywords
 Keywords map.
 
QString mLanguage
 
QgsAbstractMetadataBase::LinkList mLinks
 
QString mParentIdentifier
 
QString mTitle
 
QString mType
 

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.

Definition at line 55 of file qgslayermetadata.h.

Member Typedef Documentation

◆ ConstraintList

A list of constraints.

Definition at line 167 of file qgslayermetadata.h.

Constructor & Destructor Documentation

◆ QgsLayerMetadata()

QgsLayerMetadata::QgsLayerMetadata ( )
default

Member Function Documentation

◆ addConstraint()

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

Adds an individual constraint to the existing constraints.

See also
constraints()
setConstraints()

Definition at line 37 of file qgslayermetadata.cpp.

◆ clone()

QgsLayerMetadata * QgsLayerMetadata::clone ( ) const
overridevirtual

Clones the metadata object.

Since
QGIS 3.2

Implements QgsAbstractMetadataBase.

Definition at line 22 of file qgslayermetadata.cpp.

◆ combine()

void QgsLayerMetadata::combine ( const QgsAbstractMetadataBase other)
overridevirtual

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.

Since
QGIS 3.20

Reimplemented from QgsAbstractMetadataBase.

Definition at line 345 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 42 of file qgslayermetadata.cpp.

◆ contains()

bool QgsLayerMetadata::contains ( const QString &  searchString) const

Returns true if the metadata identifier, title, abstract, keywords or categories contain searchString using case-insensitive search.

If searchString is empty this method returns false.

Since
QGIS 3.28

Definition at line 429 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 82 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 72 of file qgslayermetadata.cpp.

◆ extent() [1/2]

QgsLayerMetadata::Extent & QgsLayerMetadata::extent ( )

Returns the spatial and temporal extents associated with the resource.

See also
setExtent()

Definition at line 382 of file qgslayermetadata.cpp.

◆ extent() [2/2]

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

Returns the spatial and temporal extents associated with the resource.

See also
setExtent()

Definition at line 377 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 27 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 62 of file qgslayermetadata.cpp.

◆ matches()

bool QgsLayerMetadata::matches ( const QVector< QRegularExpression > &  searchReList) const

Returns true if the metadata identifier, title, abstract, keywords or categories matches any regular expression from searchReList.

Since
QGIS 3.28

Definition at line 468 of file qgslayermetadata.cpp.

◆ operator==()

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

Definition at line 417 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 113 of file qgslayermetadata.cpp.

◆ readMetadataXml()

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

Sets state from DOM document.

Parameters
metadataElementThe 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.

Reimplemented from QgsAbstractMetadataBase.

Definition at line 135 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 52 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 92 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 47 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 87 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 77 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 387 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 32 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 67 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 57 of file qgslayermetadata.cpp.

◆ writeMetadataXml()

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

Stores state in a DOM node.

Parameters
metadataElementis a DOM element corresponding to resourceMetadata tag
documentis 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.

Reimplemented from QgsAbstractMetadataBase.

Definition at line 243 of file qgslayermetadata.cpp.


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