Skip to content

Commit

Permalink
Add spatial and temporal extents to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 3, 2017
1 parent 8545b80 commit 75f5a5f
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 7 deletions.
72 changes: 70 additions & 2 deletions python/core/metadata/qgslayermetadata.sip
Expand Up @@ -44,6 +44,62 @@ class QgsLayerMetadata

typedef QMap< QString, QStringList > KeywordMap;

struct SpatialExtent
{

QgsCoordinateReferenceSystem extentCrs;
%Docstring
Coordinate reference system for spatial extent.
\see spatial
%End

QgsBox3d bounds;
%Docstring
Geospatial extent of the resource. X and Y coordinates are in the
CRS defined by the metadata (see extentCrs).

While the spatial extent can include a Z dimension, this is not
compulsory.
\see extentCrs
%End
};

struct Extent
{
public:

QList< QgsLayerMetadata::SpatialExtent > spatialExtents() const;
%Docstring
Spatial extents of the resource.
\see setSpatialExtents()
:rtype: list of QgsLayerMetadata.SpatialExtent
%End

void setSpatialExtents( const QList< QgsLayerMetadata::SpatialExtent > &extents );
%Docstring
Sets the spatial ``extents`` of the resource.
\see spatialExtents()
%End

QList< QgsDateTimeRange > temporalExtents() const;
%Docstring
Temporal extents of the resource. Use QgsDateTimeRange.isInstant() to determine
whether the temporal extent is a range or a single point in time.
If QgsDateTimeRange.isInfinite() returns true then the temporal extent
is considered to be indeterminate and continuous.
\see setTemporalExtents()
:rtype: list of QgsDateTimeRange
%End

void setTemporalExtents( const QList< QgsDateTimeRange > &extents );
%Docstring
Sets the temporal ``extents`` of the resource.
\see temporalExtents()
%End


};

struct Constraint
{

Expand Down Expand Up @@ -394,6 +450,20 @@ class QgsLayerMetadata
\see encoding()
%End


QgsLayerMetadata::Extent &extent();
%Docstring
Returns the spatial and temporal extents associated with the resource.
\see setExtent()
:rtype: QgsLayerMetadata.Extent
%End

void setExtent( const QgsLayerMetadata::Extent &extent );
%Docstring
Sets the spatial and temporal extents associated with the resource.
\see setExtent()
%End

QgsCoordinateReferenceSystem crs() const;
%Docstring
Returns the coordinate reference system described by the layer's metadata.
Expand Down Expand Up @@ -548,8 +618,6 @@ class QgsLayerMetadata
};




/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
37 changes: 37 additions & 0 deletions src/core/metadata/qgslayermetadata.cpp
Expand Up @@ -215,6 +215,7 @@ void QgsLayerMetadata::saveToLayer( QgsMapLayer *layer ) const
layer->setCustomProperty( QStringLiteral( "metadata/language" ), mLanguage );
layer->setCustomProperty( QStringLiteral( "metadata/type" ), mType );
layer->setCustomProperty( QStringLiteral( "metadata/title" ), mTitle );
layer->setCustomProperty( QStringLiteral( "metadata/extent" ), QVariant::fromValue( mExtent ) );
layer->setCustomProperty( QStringLiteral( "metadata/abstract" ), mAbstract );
layer->setCustomProperty( QStringLiteral( "metadata/fees" ), mFees );
layer->setCustomProperty( QStringLiteral( "metadata/rights" ), mRights );
Expand Down Expand Up @@ -243,8 +244,44 @@ void QgsLayerMetadata::readFromLayer( const QgsMapLayer *layer )
mEncoding = layer->customProperty( QStringLiteral( "metadata/encoding" ) ).toString();
QString crsAuthId = layer->customProperty( QStringLiteral( "metadata/crs" ) ).toString();
mCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crsAuthId );
mExtent = layer->customProperty( QStringLiteral( "metadata/extent" ) ).value<Extent>();
mConstraints = layer->customProperty( QStringLiteral( "metadata/constraints" ) ).value<ConstraintList>();
mKeywords = layer->customProperty( QStringLiteral( "metadata/keywords" ) ).value<KeywordMap>();
mContacts = layer->customProperty( QStringLiteral( "metadata/contacts" ) ).value<ContactList>();
mLinks = layer->customProperty( QStringLiteral( "metadata/links" ) ).value<LinkList>();
}

const QgsLayerMetadata::Extent &QgsLayerMetadata::extent() const
{
return mExtent;
}

QgsLayerMetadata::Extent &QgsLayerMetadata::extent()
{
return mExtent;
}

void QgsLayerMetadata::setExtent( const Extent &extent )
{
mExtent = extent;
}

QList<QgsLayerMetadata::SpatialExtent> QgsLayerMetadata::Extent::spatialExtents() const
{
return mSpatialExtents;
}

void QgsLayerMetadata::Extent::setSpatialExtents( const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents )
{
mSpatialExtents = spatialExtents;
}

QList<QgsDateTimeRange> QgsLayerMetadata::Extent::temporalExtents() const
{
return mTemporalExtents;
}

void QgsLayerMetadata::Extent::setTemporalExtents( const QList<QgsDateTimeRange> &temporalExtents )
{
mTemporalExtents = temporalExtents;
}
92 changes: 90 additions & 2 deletions src/core/metadata/qgslayermetadata.h
Expand Up @@ -21,6 +21,8 @@
#include "qgis.h"
#include "qgis_core.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsbox3d.h"
#include "qgsrange.h"

class QgsMapLayer;

Expand Down Expand Up @@ -59,6 +61,73 @@ class CORE_EXPORT QgsLayerMetadata
*/
typedef QMap< QString, QStringList > KeywordMap;

/**
* Metadata spatial extent structure.
*/
struct SpatialExtent
{

/**
* Coordinate reference system for spatial extent.
* \see spatial
*/
QgsCoordinateReferenceSystem extentCrs;

/**
* Geospatial extent of the resource. X and Y coordinates are in the
* CRS defined by the metadata (see extentCrs).
*
* While the spatial extent can include a Z dimension, this is not
* compulsory.
* \see extentCrs
*/
QgsBox3d bounds;
};

/**
* Metadata extent structure.
*/
struct Extent
{
public:

/**
* Spatial extents of the resource.
* \see setSpatialExtents()
*/
QList< QgsLayerMetadata::SpatialExtent > spatialExtents() const;

/**
* Sets the spatial \a extents of the resource.
* \see spatialExtents()
*/
void setSpatialExtents( const QList< QgsLayerMetadata::SpatialExtent > &extents );

/**
* Temporal extents of the resource. Use QgsDateTimeRange::isInstant() to determine
* whether the temporal extent is a range or a single point in time.
* If QgsDateTimeRange::isInfinite() returns true then the temporal extent
* is considered to be indeterminate and continuous.
* \see setTemporalExtents()
*/
QList< QgsDateTimeRange > temporalExtents() const;

/**
* Sets the temporal \a extents of the resource.
* \see temporalExtents()
*/
void setTemporalExtents( const QList< QgsDateTimeRange > &extents );

#ifndef SIP_RUN
private:

QList< QgsLayerMetadata::SpatialExtent > mSpatialExtents;
QList< QgsDateTimeRange > mTemporalExtents;

#endif

};

/**
* Metadata constraint structure.
*/
Expand Down Expand Up @@ -432,6 +501,24 @@ class CORE_EXPORT QgsLayerMetadata
*/
void setEncoding( const QString &encoding );

/**
* Returns the spatial and temporal extents associated with the resource.
* \see setExtent()
*/
SIP_SKIP const QgsLayerMetadata::Extent &extent() const;

/**
* Returns the spatial and temporal extents associated with the resource.
* \see setExtent()
*/
QgsLayerMetadata::Extent &extent();

/**
* Sets the spatial and temporal extents associated with the resource.
* \see setExtent()
*/
void setExtent( const QgsLayerMetadata::Extent &extent );

/**
* Returns the coordinate reference system described by the layer's metadata.
*
Expand Down Expand Up @@ -604,6 +691,8 @@ class CORE_EXPORT QgsLayerMetadata
QString mEncoding;
QgsCoordinateReferenceSystem mCrs;

Extent mExtent;

/**
* Keywords map. Key is the vocabulary, value is a list of keywords for that vocabulary.
*/
Expand All @@ -627,7 +716,6 @@ Q_DECLARE_METATYPE( QgsLayerMetadata::KeywordMap )
Q_DECLARE_METATYPE( QgsLayerMetadata::ConstraintList )
Q_DECLARE_METATYPE( QgsLayerMetadata::ContactList )
Q_DECLARE_METATYPE( QgsLayerMetadata::LinkList )


Q_DECLARE_METATYPE( QgsLayerMetadata::Extent )

#endif // QGSLAYERMETADATA_H
19 changes: 18 additions & 1 deletion src/core/metadata/qgslayermetadatavalidator.cpp
Expand Up @@ -65,6 +65,23 @@ bool QgsNativeMetadataValidator::validate( const QgsLayerMetadata &metadata, QLi
results << ValidationResult( QObject::tr( "crs" ), QObject::tr( "A valid CRS element is required." ) );
}

int index = 0;
Q_FOREACH ( const QgsLayerMetadata::SpatialExtent &extent, metadata.extent().spatialExtents() )
{
if ( !extent.extentCrs.isValid() )
{
result = false;
results << ValidationResult( QObject::tr( "extent" ), QObject::tr( "A valid CRS element for the spatial extent is required." ), index );
}

if ( extent.bounds.width() == 0.0 || extent.bounds.height() == 0.0 )
{
result = false;
results << ValidationResult( QObject::tr( "extent" ), QObject::tr( "A valid spatial extent is required." ), index );
}
index++;
}

if ( metadata.contacts().isEmpty() )
{
result = false;
Expand All @@ -80,7 +97,7 @@ bool QgsNativeMetadataValidator::validate( const QgsLayerMetadata &metadata, QLi
// validate keywords
QgsLayerMetadata::KeywordMap keywords = metadata.keywords();
QgsLayerMetadata::KeywordMap::const_iterator keywordIt = keywords.constBegin();
int index = 0;
index = 0;
for ( ; keywordIt != keywords.constEnd(); ++keywordIt )
{
if ( keywordIt.key().isEmpty() )
Expand Down

0 comments on commit 75f5a5f

Please sign in to comment.