mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Implement metadata store for map layers
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.
This commit is contained in:
parent
3a965e6dbb
commit
40fccf550a
@ -11,75 +11,476 @@
|
||||
|
||||
class QgsLayerMetadata
|
||||
{
|
||||
%Docstring
|
||||
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.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "qgslayermetadata.h"
|
||||
%End
|
||||
public:
|
||||
|
||||
struct Constraint
|
||||
{
|
||||
|
||||
Constraint( const QString &constraint = QString(), const QString &type = QString() );
|
||||
%Docstring
|
||||
Constructor for Constraint.
|
||||
%End
|
||||
|
||||
QString type;
|
||||
%Docstring
|
||||
Constraint type. Standard values include 'access' and 'other', however any
|
||||
string can be used for the type.
|
||||
%End
|
||||
|
||||
QString constraint;
|
||||
%Docstring
|
||||
Free-form constraint string.
|
||||
%End
|
||||
};
|
||||
|
||||
struct Address
|
||||
{
|
||||
|
||||
Address( const QString &type = QString(), const QString &address = QString(), const QString &city = QString(), const QString &administrativeArea = QString(), const QString &postalCode = QString(), const QString &country = QString() );
|
||||
%Docstring
|
||||
Constructor for Address.
|
||||
%End
|
||||
|
||||
QString type;
|
||||
%Docstring
|
||||
Type of address, e.g. 'postal'.
|
||||
%End
|
||||
|
||||
QString address;
|
||||
%Docstring
|
||||
Free-form physical address component, e.g. '221B Baker St' or 'P.O. Box 196'.
|
||||
%End
|
||||
|
||||
QString city;
|
||||
%Docstring
|
||||
City or locality name.
|
||||
%End
|
||||
|
||||
QString administrativeArea;
|
||||
%Docstring
|
||||
Administrative area (state, provice/territory, etc.).
|
||||
%End
|
||||
|
||||
QString postalCode;
|
||||
%Docstring
|
||||
Postal (or ZIP) code.
|
||||
%End
|
||||
|
||||
QString country;
|
||||
%Docstring
|
||||
Free-form country string.
|
||||
%End
|
||||
};
|
||||
|
||||
struct Contact
|
||||
{
|
||||
|
||||
Contact( const QString &name = QString() );
|
||||
%Docstring
|
||||
Constructor for Contact.
|
||||
%End
|
||||
|
||||
QString name;
|
||||
%Docstring
|
||||
Name of contact.
|
||||
%End
|
||||
|
||||
QString organization;
|
||||
%Docstring
|
||||
Organization contact belongs to/represents.
|
||||
%End
|
||||
|
||||
QString position;
|
||||
%Docstring
|
||||
Position/title of contact.
|
||||
%End
|
||||
|
||||
QList< QgsLayerMetadata::Address > addresses;
|
||||
%Docstring
|
||||
List of addresses associated with this contact.
|
||||
%End
|
||||
|
||||
QString voice;
|
||||
%Docstring
|
||||
Voice telephone.
|
||||
%End
|
||||
|
||||
QString fax;
|
||||
%Docstring
|
||||
Facsimile telephone.
|
||||
%End
|
||||
|
||||
QString email;
|
||||
%Docstring
|
||||
Electronic mail address.
|
||||
.. note::
|
||||
|
||||
Do not include mailto: protocol as part of the email address.
|
||||
%End
|
||||
|
||||
QString role;
|
||||
%Docstring
|
||||
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.
|
||||
%End
|
||||
};
|
||||
|
||||
struct Link
|
||||
{
|
||||
|
||||
Link( const QString &name = QString(), const QString &type = QString(), const QString &url = QString() );
|
||||
%Docstring
|
||||
Constructor for Link.
|
||||
%End
|
||||
|
||||
QString name;
|
||||
%Docstring
|
||||
Short link name. E.g. WMS layer name.
|
||||
%End
|
||||
|
||||
QString type;
|
||||
%Docstring
|
||||
Link type. It is strongly suggested to use values from the 'identifier'
|
||||
column in https://github.com/OSGeo/Cat-Interop/blob/master/LinkPropertyLookupTable.csv
|
||||
%End
|
||||
|
||||
QString description;
|
||||
%Docstring
|
||||
Abstract text about link.
|
||||
%End
|
||||
|
||||
QString url;
|
||||
%Docstring
|
||||
Link url. If the URL is an OWS server, specify the *base* URL only without parameters like service=xxx....
|
||||
%End
|
||||
|
||||
QString format;
|
||||
%Docstring
|
||||
Format specification of online resource. It is strongly suggested to use GDAL/OGR format values.
|
||||
%End
|
||||
|
||||
QString mimeType;
|
||||
%Docstring
|
||||
MIME type representative of the online resource response (image/png, application/json, etc.)
|
||||
%End
|
||||
|
||||
QString size;
|
||||
%Docstring
|
||||
Estimated size (in bytes) of the online resource response.
|
||||
%End
|
||||
};
|
||||
|
||||
QgsLayerMetadata();
|
||||
%Docstring
|
||||
Constructor for QgsLayerMetadata.
|
||||
%End
|
||||
|
||||
virtual ~QgsLayerMetadata();
|
||||
|
||||
|
||||
QString identifier() const;
|
||||
%Docstring
|
||||
A reference, URI, URL or some other mechanism to identify the resource.
|
||||
\see setIdentifier()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setIdentifier( const QString &identifier );
|
||||
%Docstring
|
||||
Sets the reference, URI, URL or some other mechanism to identify the resource.
|
||||
\see identifier()
|
||||
%End
|
||||
|
||||
QString parentIdentifier() const;
|
||||
%Docstring
|
||||
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 setParentIdentifier()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
|
||||
void setParentIdentifier( const QString &parentIdentifier );
|
||||
%Docstring
|
||||
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 parentIdentifier()
|
||||
%End
|
||||
|
||||
QString language() const;
|
||||
%Docstring
|
||||
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 setLanguage()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setLanguage( const QString &language );
|
||||
%Docstring
|
||||
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 language()
|
||||
%End
|
||||
|
||||
QString type() const;
|
||||
%Docstring
|
||||
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 setType()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setType( const QString &type );
|
||||
%Docstring
|
||||
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 type()
|
||||
%End
|
||||
|
||||
QString title() const;
|
||||
%Docstring
|
||||
Returns the human readable name of the resource, typically displayed in search results.
|
||||
\see setTitle()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setTitle( const QString &title );
|
||||
%Docstring
|
||||
Sets the human readable title (name) of the resource, typically displayed in search results.
|
||||
\see title()
|
||||
%End
|
||||
|
||||
QString abstract() const;
|
||||
%Docstring
|
||||
Returns a free-form description of the resource.
|
||||
\see setAbstract()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setAbstract( const QString &abstract );
|
||||
%Docstring
|
||||
Sets a free-form abstract (description) of the resource.
|
||||
\see abstract()
|
||||
%End
|
||||
|
||||
QString fees() const;
|
||||
%Docstring
|
||||
Returns an empty string if no fees are set.
|
||||
Returns any fees associated with using the resource.
|
||||
An empty string will be returned if no fees are set.
|
||||
\see setFees()
|
||||
:rtype: str
|
||||
%End
|
||||
void setFees( const QString &fees );
|
||||
|
||||
QStringList constraints() const;
|
||||
void setFees( const QString &fees );
|
||||
%Docstring
|
||||
:rtype: list of str
|
||||
Sets the fees associated with using the resource.
|
||||
Use an empty string if no fees are set.
|
||||
\see fees()
|
||||
%End
|
||||
|
||||
QList< QgsLayerMetadata::Constraint > constraints() const;
|
||||
%Docstring
|
||||
Returns a list of constraints associated with using the resource.
|
||||
\see setConstraints()
|
||||
:rtype: list of QgsLayerMetadata.Constraint
|
||||
%End
|
||||
|
||||
void setConstraints( const QList<QgsLayerMetadata::Constraint> &constraints );
|
||||
%Docstring
|
||||
Sets the list of constraints associated with using the resource.
|
||||
\see constraints()
|
||||
%End
|
||||
void setConstraints( const QStringList &constraints );
|
||||
|
||||
QStringList rights() const;
|
||||
%Docstring
|
||||
Returns a list of attribution or copyright strings associated with the resource.
|
||||
\see setRights()
|
||||
:rtype: list of str
|
||||
%End
|
||||
|
||||
void setRights( const QStringList &rights );
|
||||
%Docstring
|
||||
Sets a list of rights (attribution or copyright strings) associated with the resource.
|
||||
\see rights()
|
||||
%End
|
||||
|
||||
QString encoding() const;
|
||||
%Docstring
|
||||
Returns an empty string if no encoding is set.
|
||||
Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.
|
||||
\see setEncoding()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setEncoding( const QString &encoding );
|
||||
%Docstring
|
||||
Sets the character encoding of the data in the resource. Use an empty string if no encoding is set.
|
||||
\see encoding()
|
||||
%End
|
||||
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
%Docstring
|
||||
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.
|
||||
\see setCrs()
|
||||
:rtype: QgsCoordinateReferenceSystem
|
||||
%End
|
||||
|
||||
void setCrs( const QgsCoordinateReferenceSystem &crs );
|
||||
%Docstring
|
||||
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.
|
||||
\see setCrs()
|
||||
%End
|
||||
|
||||
QMap<QString, QStringList> keywords() const;
|
||||
%Docstring
|
||||
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 setKeywords()
|
||||
\see keywordVocabularies()
|
||||
:rtype: QMap<str, list of str>
|
||||
%End
|
||||
|
||||
void setKeywords( const QMap<QString, QStringList> &keywords );
|
||||
%Docstring
|
||||
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 keywords()
|
||||
\see addKeywords()
|
||||
%End
|
||||
|
||||
void addKeywords( const QString &vocabulary, const QStringList &keywords );
|
||||
%Docstring
|
||||
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 setKeywords()
|
||||
%End
|
||||
|
||||
QStringList keywordVocabularies() const;
|
||||
%Docstring
|
||||
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 keywords()
|
||||
:rtype: list of str
|
||||
%End
|
||||
|
||||
QStringList keywords( const QString &vocabulary ) const;
|
||||
%Docstring
|
||||
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 keywordVocabularies()
|
||||
:rtype: list of str
|
||||
%End
|
||||
|
||||
QList<QgsLayerMetadata::Contact> contacts() const;
|
||||
%Docstring
|
||||
Returns a list of contact persons or entities associated with the resource.
|
||||
\see setContacts()
|
||||
:rtype: list of QgsLayerMetadata.Contact
|
||||
%End
|
||||
|
||||
void setContacts( const QList<QgsLayerMetadata::Contact> &contacts );
|
||||
%Docstring
|
||||
Sets the list of contacts or entities associated with the resource. Any existing contacts
|
||||
will be replaced.
|
||||
\see contacts()
|
||||
\see addContact()
|
||||
%End
|
||||
|
||||
void addContact( const QgsLayerMetadata::Contact &contact );
|
||||
%Docstring
|
||||
Adds an individual contact to the existing contacts.
|
||||
\see contacts()
|
||||
\see setContacts()
|
||||
%End
|
||||
|
||||
QList<QgsLayerMetadata::Link> links() const;
|
||||
%Docstring
|
||||
Returns a list of online resources associated with the resource.
|
||||
\see setLinks()
|
||||
:rtype: list of QgsLayerMetadata.Link
|
||||
%End
|
||||
|
||||
void setLinks( const QList<QgsLayerMetadata::Link> &links );
|
||||
%Docstring
|
||||
Sets the list of online resources associated with the resource. Any existing links
|
||||
will be replaced.
|
||||
\see links()
|
||||
\see addLink()
|
||||
%End
|
||||
|
||||
void addLink( const QgsLayerMetadata::Link &link );
|
||||
%Docstring
|
||||
Adds an individual link to the existing links.
|
||||
\see links()
|
||||
\see setLinks()
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -77,12 +77,12 @@ void QgsLayerMetadata::setFees( const QString &fees )
|
||||
mFees = fees;
|
||||
}
|
||||
|
||||
QStringList QgsLayerMetadata::constraints() const
|
||||
QList<QgsLayerMetadata::Constraint> QgsLayerMetadata::constraints() const
|
||||
{
|
||||
return mConstraints;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setConstraints( const QStringList &constraints )
|
||||
void QgsLayerMetadata::setConstraints( const QList<Constraint> &constraints )
|
||||
{
|
||||
mConstraints = constraints;
|
||||
}
|
||||
@ -106,3 +106,78 @@ void QgsLayerMetadata::setEncoding( const QString &encoding )
|
||||
{
|
||||
mEncoding = encoding;
|
||||
}
|
||||
|
||||
QgsCoordinateReferenceSystem QgsLayerMetadata::crs() const
|
||||
{
|
||||
return mCrs;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setCrs( const QgsCoordinateReferenceSystem &crs )
|
||||
{
|
||||
mCrs = crs;
|
||||
}
|
||||
|
||||
QMap<QString, QStringList> QgsLayerMetadata::keywords() const
|
||||
{
|
||||
return mKeywords;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setKeywords( const QMap<QString, QStringList> &keywords )
|
||||
{
|
||||
mKeywords = keywords;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::addKeywords( const QString &vocabulary, const QStringList &keywords )
|
||||
{
|
||||
mKeywords.insert( vocabulary, keywords );
|
||||
}
|
||||
|
||||
QStringList QgsLayerMetadata::keywordVocabularies() const
|
||||
{
|
||||
return mKeywords.keys();
|
||||
}
|
||||
|
||||
QStringList QgsLayerMetadata::keywords( const QString &vocabulary ) const
|
||||
{
|
||||
return mKeywords.value( vocabulary );
|
||||
}
|
||||
|
||||
QList<QgsLayerMetadata::Contact> QgsLayerMetadata::contacts() const
|
||||
{
|
||||
return mContacts;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setContacts( const QList<Contact> &contacts )
|
||||
{
|
||||
mContacts = contacts;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::addContact( const QgsLayerMetadata::Contact &contact )
|
||||
{
|
||||
mContacts << contact;
|
||||
}
|
||||
|
||||
QList<QgsLayerMetadata::Link> QgsLayerMetadata::links() const
|
||||
{
|
||||
return mLinks;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setLinks( const QList<QgsLayerMetadata::Link> &links )
|
||||
{
|
||||
mLinks = links;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::addLink( const QgsLayerMetadata::Link &link )
|
||||
{
|
||||
mLinks << link;
|
||||
}
|
||||
|
||||
QString QgsLayerMetadata::language() const
|
||||
{
|
||||
return mLanguage;
|
||||
}
|
||||
|
||||
void QgsLayerMetadata::setLanguage( const QString &language )
|
||||
{
|
||||
mLanguage = language;
|
||||
}
|
||||
|
||||
@ -20,65 +20,530 @@
|
||||
|
||||
#include "qgis.h"
|
||||
#include "qgis_core.h"
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgsLayerMetadata
|
||||
* \brief 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.
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayerMetadata
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Metadata constraint structure.
|
||||
*/
|
||||
struct Constraint
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for Constraint.
|
||||
*/
|
||||
Constraint( const QString &constraint = QString(), const QString &type = QString() )
|
||||
: type( type )
|
||||
, constraint( constraint )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Constraint type. Standard values include 'access' and 'other', however any
|
||||
* string can be used for the type.
|
||||
*/
|
||||
QString type;
|
||||
|
||||
/**
|
||||
* Free-form constraint string.
|
||||
*/
|
||||
QString constraint;
|
||||
};
|
||||
|
||||
/**
|
||||
* Metadata address structure.
|
||||
*/
|
||||
struct Address
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for Address.
|
||||
*/
|
||||
Address( const QString &type = QString(), const QString &address = QString(), const QString &city = QString(), const QString &administrativeArea = QString(), const QString &postalCode = QString(), const QString &country = QString() )
|
||||
: type( type )
|
||||
, address( address )
|
||||
, city( city )
|
||||
, administrativeArea( administrativeArea )
|
||||
, postalCode( postalCode )
|
||||
, country( country )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Type of address, e.g. 'postal'.
|
||||
*/
|
||||
QString type;
|
||||
|
||||
/**
|
||||
* Free-form physical address component, e.g. '221B Baker St' or 'P.O. Box 196'.
|
||||
*/
|
||||
QString address;
|
||||
|
||||
/**
|
||||
* City or locality name.
|
||||
*/
|
||||
QString city;
|
||||
|
||||
/**
|
||||
* Administrative area (state, provice/territory, etc.).
|
||||
*/
|
||||
QString administrativeArea;
|
||||
|
||||
/**
|
||||
* Postal (or ZIP) code.
|
||||
*/
|
||||
QString postalCode;
|
||||
|
||||
/**
|
||||
* Free-form country string.
|
||||
*/
|
||||
QString country;
|
||||
};
|
||||
|
||||
/**
|
||||
* Metadata contact structure.
|
||||
*/
|
||||
struct Contact
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for Contact.
|
||||
*/
|
||||
Contact( const QString &name = QString() )
|
||||
: name( name )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Name of contact.
|
||||
*/
|
||||
QString name;
|
||||
|
||||
/**
|
||||
* Organization contact belongs to/represents.
|
||||
*/
|
||||
QString organization;
|
||||
|
||||
/**
|
||||
* Position/title of contact.
|
||||
*/
|
||||
QString position;
|
||||
|
||||
/**
|
||||
* List of addresses associated with this contact.
|
||||
*/
|
||||
QList< QgsLayerMetadata::Address > addresses;
|
||||
|
||||
/**
|
||||
* Voice telephone.
|
||||
*/
|
||||
QString voice;
|
||||
|
||||
/**
|
||||
* Facsimile telephone.
|
||||
*/
|
||||
QString fax;
|
||||
|
||||
/**
|
||||
* Electronic mail address.
|
||||
* \note Do not include mailto: protocol as part of the email address.
|
||||
*/
|
||||
QString email;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
QString role;
|
||||
};
|
||||
|
||||
/**
|
||||
* Metadata link structure.
|
||||
*/
|
||||
struct Link
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for Link.
|
||||
*/
|
||||
Link( const QString &name = QString(), const QString &type = QString(), const QString &url = QString() )
|
||||
: name( name )
|
||||
, type( type )
|
||||
, url( url )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Short link name. E.g. WMS layer name.
|
||||
*/
|
||||
QString name;
|
||||
|
||||
/**
|
||||
* Link type. It is strongly suggested to use values from the 'identifier'
|
||||
* column in https://github.com/OSGeo/Cat-Interop/blob/master/LinkPropertyLookupTable.csv
|
||||
*/
|
||||
QString type;
|
||||
|
||||
/**
|
||||
* Abstract text about link.
|
||||
*/
|
||||
QString description;
|
||||
|
||||
/**
|
||||
* Link url. If the URL is an OWS server, specify the *base* URL only without parameters like service=xxx....
|
||||
*/
|
||||
QString url;
|
||||
|
||||
/**
|
||||
* Format specification of online resource. It is strongly suggested to use GDAL/OGR format values.
|
||||
*/
|
||||
QString format;
|
||||
|
||||
/**
|
||||
* MIME type representative of the online resource response (image/png, application/json, etc.)
|
||||
*/
|
||||
QString mimeType;
|
||||
|
||||
/**
|
||||
* Estimated size (in bytes) of the online resource response.
|
||||
*/
|
||||
QString size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor for QgsLayerMetadata.
|
||||
*/
|
||||
QgsLayerMetadata() = default;
|
||||
|
||||
virtual ~QgsLayerMetadata() = default;
|
||||
|
||||
|
||||
/**
|
||||
* A reference, URI, URL or some other mechanism to identify the resource.
|
||||
* \see setIdentifier()
|
||||
*/
|
||||
QString identifier() const;
|
||||
|
||||
/**
|
||||
* Sets the reference, URI, URL or some other mechanism to identify the resource.
|
||||
* \see identifier()
|
||||
*/
|
||||
void setIdentifier( const QString &identifier );
|
||||
|
||||
/**
|
||||
* 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 setParentIdentifier()
|
||||
*/
|
||||
QString parentIdentifier() const;
|
||||
|
||||
|
||||
/**
|
||||
* 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 parentIdentifier()
|
||||
*/
|
||||
void setParentIdentifier( const QString &parentIdentifier );
|
||||
|
||||
/**
|
||||
* 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 setLanguage()
|
||||
*/
|
||||
QString language() const;
|
||||
|
||||
/**
|
||||
* Sets the human \a 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 language()
|
||||
*/
|
||||
void setLanguage( const QString &language );
|
||||
|
||||
/**
|
||||
* 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 setType()
|
||||
*/
|
||||
QString type() const;
|
||||
|
||||
/**
|
||||
* Sets the \a 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 type()
|
||||
*/
|
||||
void setType( const QString &type );
|
||||
|
||||
/**
|
||||
* Returns the human readable name of the resource, typically displayed in search results.
|
||||
* \see setTitle()
|
||||
*/
|
||||
QString title() const;
|
||||
|
||||
/**
|
||||
* Sets the human readable \a title (name) of the resource, typically displayed in search results.
|
||||
* \see title()
|
||||
*/
|
||||
void setTitle( const QString &title );
|
||||
|
||||
/**
|
||||
* Returns a free-form description of the resource.
|
||||
* \see setAbstract()
|
||||
*/
|
||||
QString abstract() const;
|
||||
|
||||
/**
|
||||
* Sets a free-form \a abstract (description) of the resource.
|
||||
* \see abstract()
|
||||
*/
|
||||
void setAbstract( const QString &abstract );
|
||||
|
||||
/**
|
||||
* Returns an empty string if no fees are set.
|
||||
* Returns any fees associated with using the resource.
|
||||
* An empty string will be returned if no fees are set.
|
||||
* \see setFees()
|
||||
*/
|
||||
QString fees() const;
|
||||
|
||||
/**
|
||||
* Sets the \a fees associated with using the resource.
|
||||
* Use an empty string if no fees are set.
|
||||
* \see fees()
|
||||
*/
|
||||
void setFees( const QString &fees );
|
||||
|
||||
QStringList constraints() const;
|
||||
void setConstraints( const QStringList &constraints );
|
||||
/**
|
||||
* Returns a list of constraints associated with using the resource.
|
||||
* \see setConstraints()
|
||||
*/
|
||||
QList< QgsLayerMetadata::Constraint > constraints() const;
|
||||
|
||||
/**
|
||||
* Sets the list of \a constraints associated with using the resource.
|
||||
* \see constraints()
|
||||
*/
|
||||
void setConstraints( const QList<QgsLayerMetadata::Constraint> &constraints );
|
||||
|
||||
/**
|
||||
* Returns a list of attribution or copyright strings associated with the resource.
|
||||
* \see setRights()
|
||||
*/
|
||||
QStringList rights() const;
|
||||
|
||||
/**
|
||||
* Sets a list of \a rights (attribution or copyright strings) associated with the resource.
|
||||
* \see rights()
|
||||
*/
|
||||
void setRights( const QStringList &rights );
|
||||
|
||||
/**
|
||||
* Returns an empty string if no encoding is set.
|
||||
* Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.
|
||||
* \see setEncoding()
|
||||
*/
|
||||
QString encoding() const;
|
||||
|
||||
/**
|
||||
* Sets the character \a encoding of the data in the resource. Use an empty string if no encoding is set.
|
||||
* \see encoding()
|
||||
*/
|
||||
void setEncoding( const QString &encoding );
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* \see setCrs()
|
||||
*/
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* \see setCrs()
|
||||
*/
|
||||
void setCrs( const QgsCoordinateReferenceSystem &crs );
|
||||
|
||||
/**
|
||||
* 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 setKeywords()
|
||||
* \see keywordVocabularies()
|
||||
*/
|
||||
QMap<QString, QStringList> keywords() const;
|
||||
|
||||
/**
|
||||
* Sets the \a 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 keywords()
|
||||
* \see addKeywords()
|
||||
*/
|
||||
void setKeywords( const QMap<QString, QStringList> &keywords );
|
||||
|
||||
/**
|
||||
* Adds a list of descriptive \a keywords for a specified \a 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 setKeywords()
|
||||
*/
|
||||
void addKeywords( const QString &vocabulary, const QStringList &keywords );
|
||||
|
||||
/**
|
||||
* 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 keywords()
|
||||
*/
|
||||
QStringList keywordVocabularies() const;
|
||||
|
||||
/**
|
||||
* Returns a list of keywords for the specified \a 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 keywordVocabularies()
|
||||
*/
|
||||
QStringList keywords( const QString &vocabulary ) const;
|
||||
|
||||
/**
|
||||
* Returns a list of contact persons or entities associated with the resource.
|
||||
* \see setContacts()
|
||||
*/
|
||||
QList<QgsLayerMetadata::Contact> contacts() const;
|
||||
|
||||
/**
|
||||
* Sets the list of \a contacts or entities associated with the resource. Any existing contacts
|
||||
* will be replaced.
|
||||
* \see contacts()
|
||||
* \see addContact()
|
||||
*/
|
||||
void setContacts( const QList<QgsLayerMetadata::Contact> &contacts );
|
||||
|
||||
/**
|
||||
* Adds an individual \a contact to the existing contacts.
|
||||
* \see contacts()
|
||||
* \see setContacts()
|
||||
*/
|
||||
void addContact( const QgsLayerMetadata::Contact &contact );
|
||||
|
||||
/**
|
||||
* Returns a list of online resources associated with the resource.
|
||||
* \see setLinks()
|
||||
*/
|
||||
QList<QgsLayerMetadata::Link> links() const;
|
||||
|
||||
/**
|
||||
* Sets the list of online resources associated with the resource. Any existing links
|
||||
* will be replaced.
|
||||
* \see links()
|
||||
* \see addLink()
|
||||
*/
|
||||
void setLinks( const QList<QgsLayerMetadata::Link> &links );
|
||||
|
||||
/**
|
||||
* Adds an individual \a link to the existing links.
|
||||
* \see links()
|
||||
* \see setLinks()
|
||||
*/
|
||||
void addLink( const QgsLayerMetadata::Link &link );
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
* IMPORTANT!!!!!!
|
||||
*
|
||||
* Do NOT add anything to this class without also updating the schema
|
||||
* definition located at resources/qgis-resource-metadata.xsd
|
||||
*
|
||||
*/
|
||||
|
||||
QString mIdentifier;
|
||||
QString mParentIdentifier;
|
||||
QString mLanguage;
|
||||
QString mType;
|
||||
QString mTitle;
|
||||
QString mAbstract;
|
||||
QString mFees;
|
||||
QStringList mConstraints;
|
||||
QList<QgsLayerMetadata::Constraint> mConstraints;
|
||||
QStringList mRights;
|
||||
|
||||
// IMPORTANT - look up before adding anything here!!
|
||||
|
||||
QString mEncoding;
|
||||
QgsCoordinateReferenceSystem mCrs;
|
||||
|
||||
/**
|
||||
* Keywords map. Key is the vocabulary, value is a list of keywords for that vocabulary.
|
||||
*/
|
||||
QMap< QString, QStringList > mKeywords;
|
||||
|
||||
QList< Contact > mContacts;
|
||||
|
||||
QList< Link > mLinks;
|
||||
|
||||
/*
|
||||
* IMPORTANT!!!!!!
|
||||
*
|
||||
* Do NOT add anything to this class without also updating the schema
|
||||
* definition located at resources/qgis-resource-metadata.xsd
|
||||
*
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -71,6 +71,7 @@ ADD_PYTHON_TEST(PyQgsLayerTreeMapCanvasBridge test_qgslayertreemapcanvasbridge.p
|
||||
ADD_PYTHON_TEST(PyQgsLayerTree test_qgslayertree.py)
|
||||
ADD_PYTHON_TEST(PyQgsLayoutManager test_qgslayoutmanager.py)
|
||||
ADD_PYTHON_TEST(PyQgsLineSymbolLayers test_qgslinesymbollayers.py)
|
||||
ADD_PYTHON_TEST(PyQgsLayerMetadata test_qgslayermetadata.py)
|
||||
ADD_PYTHON_TEST(PyQgsMapCanvas test_qgsmapcanvas.py)
|
||||
ADD_PYTHON_TEST(PyQgsMapCanvasAnnotationItem test_qgsmapcanvasannotationitem.py)
|
||||
ADD_PYTHON_TEST(PyQgsMapLayer test_qgsmaplayer.py)
|
||||
|
||||
288
tests/src/python/test_qgslayermetadata.py
Normal file
288
tests/src/python/test_qgslayermetadata.py
Normal file
@ -0,0 +1,288 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""QGIS Unit tests for QgsLayerMetadata.
|
||||
|
||||
.. note:: This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
"""
|
||||
__author__ = 'Nyall Dawson'
|
||||
__date__ = '11/04/2017'
|
||||
__copyright__ = 'Copyright 2017, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis # NOQA
|
||||
|
||||
from qgis.core import (QgsLayerMetadata,
|
||||
QgsCoordinateReferenceSystem)
|
||||
from qgis.testing import start_app, unittest
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
class TestQgsLayerMetadata(unittest.TestCase):
|
||||
|
||||
def testGettersSetters(self):
|
||||
m = QgsLayerMetadata()
|
||||
|
||||
m.setIdentifier('identifier')
|
||||
self.assertEqual(m.identifier(), 'identifier')
|
||||
|
||||
m.setParentIdentifier('parent identifier')
|
||||
self.assertEqual(m.parentIdentifier(), 'parent identifier')
|
||||
|
||||
m.setLanguage('en-us')
|
||||
self.assertEqual(m.language(), 'en-us')
|
||||
|
||||
m.setType('type')
|
||||
self.assertEqual(m.type(), 'type')
|
||||
|
||||
m.setTitle('title')
|
||||
self.assertEqual(m.title(), 'title')
|
||||
|
||||
m.setAbstract('abstract')
|
||||
self.assertEqual(m.abstract(), 'abstract')
|
||||
|
||||
m.setFees('fees')
|
||||
self.assertEqual(m.fees(), 'fees')
|
||||
|
||||
m.setConstraints([QgsLayerMetadata.Constraint('constraint a'), QgsLayerMetadata.Constraint('constraint b')])
|
||||
self.assertEqual(m.constraints()[0].constraint, 'constraint a')
|
||||
self.assertEqual(m.constraints()[1].constraint, 'constraint b')
|
||||
|
||||
m.setRights(['right a', 'right b'])
|
||||
self.assertEqual(m.rights(), ['right a', 'right b'])
|
||||
|
||||
m.setEncoding('encoding')
|
||||
self.assertEqual(m.encoding(), 'encoding')
|
||||
|
||||
m.setCrs(QgsCoordinateReferenceSystem.fromEpsgId(3111))
|
||||
self.assertEqual(m.crs().authid(), 'EPSG:3111')
|
||||
|
||||
def testKeywords(self):
|
||||
m = QgsLayerMetadata()
|
||||
|
||||
m.setKeywords({'vocab a': ['keyword a', 'other a'],
|
||||
'vocab b': ['keyword b', 'other b']})
|
||||
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
|
||||
'vocab b': ['keyword b', 'other b']})
|
||||
self.assertEqual(m.keywordVocabularies(), ['vocab a', 'vocab b'])
|
||||
self.assertEqual(m.keywords('vocab a'), ['keyword a', 'other a'])
|
||||
self.assertEqual(m.keywords('vocab b'), ['keyword b', 'other b'])
|
||||
self.assertEqual(m.keywords('not valid'), [])
|
||||
|
||||
m.addKeywords('vocab c', ['keyword c'])
|
||||
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
|
||||
'vocab b': ['keyword b', 'other b'],
|
||||
'vocab c': ['keyword c']})
|
||||
# replace existing using addKeywords
|
||||
m.addKeywords('vocab c', ['c'])
|
||||
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],
|
||||
'vocab b': ['keyword b', 'other b'],
|
||||
'vocab c': ['c']})
|
||||
# replace existing using setKeywords
|
||||
m.setKeywords({'x': ['x'], 'y': ['y']})
|
||||
self.assertEqual(m.keywords(), {'x': ['x'],
|
||||
'y': ['y']})
|
||||
|
||||
def testAddress(self):
|
||||
a = QgsLayerMetadata.Address()
|
||||
a.type = 'postal'
|
||||
a.address = '13 north rd'
|
||||
a.city = 'huxleys haven'
|
||||
a.administrativeArea = 'land of the queens'
|
||||
a.postalCode = '4123'
|
||||
a.country = 'straya!'
|
||||
self.assertEqual(a.type, 'postal')
|
||||
self.assertEqual(a.address, '13 north rd')
|
||||
self.assertEqual(a.city, 'huxleys haven')
|
||||
self.assertEqual(a.administrativeArea, 'land of the queens')
|
||||
self.assertEqual(a.postalCode, '4123')
|
||||
self.assertEqual(a.country, 'straya!')
|
||||
|
||||
def testContact(self):
|
||||
c = QgsLayerMetadata.Contact()
|
||||
c.name = 'Prince Gristle'
|
||||
c.organization = 'Bergen co'
|
||||
c.position = 'prince'
|
||||
c.voice = '1500 515 555'
|
||||
c.fax = 'who the f*** still uses fax?'
|
||||
c.email = 'limpbiskitrulez69@hotmail.com'
|
||||
c.role = 'person to blame when all goes wrong'
|
||||
a = QgsLayerMetadata.Address()
|
||||
a.type = 'postal'
|
||||
a2 = QgsLayerMetadata.Address()
|
||||
a2.type = 'street'
|
||||
c.addresses = [a, a2]
|
||||
self.assertEqual(c.name, 'Prince Gristle')
|
||||
self.assertEqual(c.organization, 'Bergen co')
|
||||
self.assertEqual(c.position, 'prince')
|
||||
self.assertEqual(c.voice, '1500 515 555')
|
||||
self.assertEqual(c.fax, 'who the f*** still uses fax?')
|
||||
self.assertEqual(c.email, 'limpbiskitrulez69@hotmail.com')
|
||||
self.assertEqual(c.role, 'person to blame when all goes wrong')
|
||||
self.assertEqual(c.addresses[0].type, 'postal')
|
||||
self.assertEqual(c.addresses[1].type, 'street')
|
||||
|
||||
m = QgsLayerMetadata()
|
||||
c2 = QgsLayerMetadata.Contact(c)
|
||||
c2.name = 'Bridgette'
|
||||
|
||||
m.setContacts([c, c2])
|
||||
self.assertEqual(m.contacts()[0].name, 'Prince Gristle')
|
||||
self.assertEqual(m.contacts()[1].name, 'Bridgette')
|
||||
|
||||
# add contact
|
||||
c3 = QgsLayerMetadata.Contact(c)
|
||||
c3.name = 'Princess Poppy'
|
||||
m.addContact(c3)
|
||||
self.assertEqual(len(m.contacts()), 3)
|
||||
self.assertEqual(m.contacts()[2].name, 'Princess Poppy')
|
||||
|
||||
def testLinks(self):
|
||||
l = QgsLayerMetadata.Link()
|
||||
l.name = 'Trashbat'
|
||||
l.type = 'fashion'
|
||||
l.description = 'registered in the cook islands!'
|
||||
l.url = 'http://trashbat.co.uk'
|
||||
l.format = 'whois'
|
||||
l.mimeType = 'text/string'
|
||||
l.size = '112'
|
||||
self.assertEqual(l.name, 'Trashbat')
|
||||
self.assertEqual(l.type, 'fashion')
|
||||
self.assertEqual(l.description, 'registered in the cook islands!')
|
||||
self.assertEqual(l.url, 'http://trashbat.co.uk')
|
||||
self.assertEqual(l.format, 'whois')
|
||||
self.assertEqual(l.mimeType, 'text/string')
|
||||
self.assertEqual(l.size, '112')
|
||||
|
||||
m = QgsLayerMetadata()
|
||||
l2 = QgsLayerMetadata.Link(l)
|
||||
l2.name = 'Trashbat2'
|
||||
|
||||
m.setLinks([l, l2])
|
||||
self.assertEqual(m.links()[0].name, 'Trashbat')
|
||||
self.assertEqual(m.links()[1].name, 'Trashbat2')
|
||||
|
||||
# add link
|
||||
l3 = QgsLayerMetadata.Link(l)
|
||||
l3.name = 'Trashbat3'
|
||||
m.addLink(l3)
|
||||
self.assertEqual(len(m.links()), 3)
|
||||
self.assertEqual(m.links()[2].name, 'Trashbat3')
|
||||
|
||||
def createTestMetadata(self):
|
||||
"""
|
||||
Returns a standard metadata which can be tested with checkExpectedMetadata
|
||||
"""
|
||||
m = QgsLayerMetadata()
|
||||
m.setIdentifier('1234')
|
||||
m.setParentIdentifier('xyz')
|
||||
m.setLanguage('en-CA')
|
||||
m.setType('dataset')
|
||||
m.setTitle('roads')
|
||||
m.setAbstract('my roads')
|
||||
m.setFees('None')
|
||||
m.setConstraints([QgsLayerMetadata.Constraint('None', 'access')])
|
||||
m.setRights(['Copyright foo 2017'])
|
||||
m.setKeywords({'GEMET': ['kw1', 'kw2']})
|
||||
m.setEncoding('utf-8')
|
||||
m.setCrs(QgsCoordinateReferenceSystem.fromOgcWmsCrs('EPSG:4326'))
|
||||
|
||||
c = QgsLayerMetadata.Contact()
|
||||
c.name = 'John Smith'
|
||||
c.organization = 'ACME'
|
||||
c.position = 'staff'
|
||||
c.voice = '1500 515 555'
|
||||
c.fax = 'xx.xxx.xxx.xxxx'
|
||||
c.email = 'foo@example.org'
|
||||
c.role = 'pointOfContact'
|
||||
address = QgsLayerMetadata.Address()
|
||||
address.type = 'postal'
|
||||
address.address = '123 Main Street'
|
||||
address.city = 'anycity'
|
||||
address.administrativeArea = 'anyprovince'
|
||||
address.postalCode = '90210'
|
||||
address.country = 'Canada'
|
||||
c.addresses = [address]
|
||||
m.setContacts([c])
|
||||
|
||||
l = QgsLayerMetadata.Link()
|
||||
l.name = 'geonode:roads'
|
||||
l.type = 'OGC:WMS'
|
||||
l.description = 'my GeoNode road layer'
|
||||
l.url = 'http://example.org/wms'
|
||||
|
||||
l2 = QgsLayerMetadata.Link()
|
||||
l2.name = 'geonode:roads'
|
||||
l2.type = 'OGC:WFS'
|
||||
l2.description = 'my GeoNode road layer'
|
||||
l2.url = 'http://example.org/wfs'
|
||||
|
||||
l3 = QgsLayerMetadata.Link()
|
||||
l3.name = 'roads'
|
||||
l3.type = 'WWW:LINK'
|
||||
l3.description = 'full dataset download'
|
||||
l3.url = 'http://example.org/roads.tgz'
|
||||
l3.format = 'ESRI Shapefile'
|
||||
l3.mimeType = 'application/gzip'
|
||||
l3.size = '283676'
|
||||
|
||||
m.setLinks([l, l2, l3])
|
||||
|
||||
return m
|
||||
|
||||
def checkExpectedMetadata(self, m):
|
||||
"""
|
||||
Checks that a metadata object matches that returned by createTestMetadata
|
||||
"""
|
||||
self.assertEqual(m.identifier(), '1234')
|
||||
self.assertEqual(m.parentIdentifier(), 'xyz')
|
||||
self.assertEqual(m.language(), 'en-CA')
|
||||
self.assertEqual(m.type(), 'dataset')
|
||||
self.assertEqual(m.title(), 'roads')
|
||||
self.assertEqual(m.abstract(), 'my roads')
|
||||
self.assertEqual(m.fees(), 'None')
|
||||
self.assertEqual(m.constraints()[0].constraint, 'None')
|
||||
self.assertEqual(m.constraints()[0].type, 'access')
|
||||
self.assertEqual(m.rights(), ['Copyright foo 2017'])
|
||||
self.assertEqual(m.encoding(), 'utf-8')
|
||||
self.assertEqual(m.keywords(), {'GEMET': ['kw1', 'kw2']})
|
||||
self.assertEqual(m.crs().authid(), 'EPSG:4326')
|
||||
self.assertEqual(m.contacts()[0].name, 'John Smith')
|
||||
self.assertEqual(m.contacts()[0].organization, 'ACME')
|
||||
self.assertEqual(m.contacts()[0].position, 'staff')
|
||||
self.assertEqual(m.contacts()[0].voice, '1500 515 555')
|
||||
self.assertEqual(m.contacts()[0].fax, 'xx.xxx.xxx.xxxx')
|
||||
self.assertEqual(m.contacts()[0].email, 'foo@example.org')
|
||||
self.assertEqual(m.contacts()[0].role, 'pointOfContact')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].type, 'postal')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].address, '123 Main Street')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].city, 'anycity')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].administrativeArea, 'anyprovince')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].postalCode, '90210')
|
||||
self.assertEqual(m.contacts()[0].addresses[0].country, 'Canada')
|
||||
self.assertEqual(m.links()[0].name, 'geonode:roads')
|
||||
self.assertEqual(m.links()[0].type, 'OGC:WMS')
|
||||
self.assertEqual(m.links()[0].description, 'my GeoNode road layer')
|
||||
self.assertEqual(m.links()[0].url, 'http://example.org/wms')
|
||||
self.assertEqual(m.links()[1].name, 'geonode:roads')
|
||||
self.assertEqual(m.links()[1].type, 'OGC:WFS')
|
||||
self.assertEqual(m.links()[1].description, 'my GeoNode road layer')
|
||||
self.assertEqual(m.links()[1].url, 'http://example.org/wfs')
|
||||
self.assertEqual(m.links()[2].name, 'roads')
|
||||
self.assertEqual(m.links()[2].type, 'WWW:LINK')
|
||||
self.assertEqual(m.links()[2].description, 'full dataset download')
|
||||
self.assertEqual(m.links()[2].url, 'http://example.org/roads.tgz')
|
||||
self.assertEqual(m.links()[2].format, 'ESRI Shapefile')
|
||||
self.assertEqual(m.links()[2].mimeType, 'application/gzip')
|
||||
self.assertEqual(m.links()[2].size, '283676')
|
||||
|
||||
def testStandard(self):
|
||||
m = self.createTestMetadata()
|
||||
self.checkExpectedMetadata(m)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
x
Reference in New Issue
Block a user