QGIS API Documentation 4.3.0-Master (389d690bb77)
Loading...
Searching...
No Matches
qgsstacitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsstacitem.cpp
3 ---------------------
4 begin : August 2024
5 copyright : (C) 2024 by Stefanos Natsis
6 email : uclaros at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsstacitem.h"
17
18#include <QString>
19
20using namespace Qt::StringLiterals;
21
23 const QString &id, const QString &version, const QgsGeometry &geometry, const QVariantMap &properties, const QVector< QgsStacLink > &links, const QMap< QString, QgsStacAsset > &assets, const QgsBox3D &bbox
24)
25 : QgsStacObject( id, version, links )
26 , mGeometry( geometry )
27 , mBbox( bbox )
28 , mProperties( properties )
29 , mAssets( assets )
30{}
31
36
37QString QgsStacItem::toHtml() const
38{
39 QString html = u"<h1>%1</h1>\n<hr>\n"_s.arg( "Item"_L1 );
40 html += "<table class=\"list-view\">\n"_L1;
41 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"id"_s, id() );
42 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"stac_version"_s, stacVersion() );
43 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"collection"_s, collection() );
44 html += "</table>\n"_L1;
45
46 if ( !mStacExtensions.isEmpty() )
47 {
48 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Extensions"_L1 );
49 html += "<ul>\n"_L1;
50 for ( const QString &extension : mStacExtensions )
51 {
52 html += u"<li>%1</li>\n"_s.arg( extension );
53 }
54 html += "</ul>\n"_L1;
55 }
56
57 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Geometry"_L1 );
58 html += "<table class=\"list-view\">\n"_L1;
59 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"WKT"_s, mGeometry.asWkt() );
60 html += "</table>\n"_L1;
61
62 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Bounding Box"_L1 );
63 html += "<ul>\n"_L1;
64 html += u"<li>%1</li>\n"_s.arg( mBbox.is2d() ? mBbox.toRectangle().toString() : mBbox.toString() );
65 html += "</ul>\n"_L1;
66
67 if ( !mProperties.isEmpty() )
68 {
69 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Properties"_L1 );
70 html += "<table class=\"list-view\">\n"_L1;
71 for ( auto it = mProperties.constBegin(); it != mProperties.constEnd(); ++it )
72 {
73 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( it.key(), it.value().toString() );
74 }
75 html += "</table><br/>\n"_L1;
76 }
77
78 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Links"_L1 );
79 for ( const QgsStacLink &link : mLinks )
80 {
81 html += "<table class=\"list-view\">\n"_L1;
82 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"relation"_s, link.relation() );
83 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"title"_s, link.title() );
84 html += u"<tr><td class=\"highlight\">%1</td><td><a href=\"%2\">%2</a></td></tr>\n"_s.arg( u"url"_s, link.href() );
85 html += u"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>\n"_s.arg( u"type"_s, link.mediaType() );
86 html += "</table><br/>\n"_L1;
87 }
88
89 if ( !mAssets.isEmpty() )
90 {
91 html += u"<h1>%1</h1>\n<hr>\n"_s.arg( "Assets"_L1 );
92 for ( auto it = mAssets.constBegin(); it != mAssets.constEnd(); ++it )
93 {
94 html += it->toHtml( it.key() );
95 }
96 }
97 return html;
98}
99
101{
102 return mGeometry;
103}
104
106{
107 mGeometry = geometry;
108}
109
111{
112 return mBbox;
113}
114
116{
117 mBbox = bbox;
118}
119
120QVariantMap QgsStacItem::properties() const
121{
122 return mProperties;
123}
124
125void QgsStacItem::setProperties( const QVariantMap &properties )
126{
127 mProperties = properties;
128}
129
130QMap< QString, QgsStacAsset > QgsStacItem::assets() const
131{
132 return mAssets;
133}
134
135void QgsStacItem::setAssets( const QMap< QString, QgsStacAsset > &assets )
136{
137 mAssets = assets;
138}
139
141{
142 return mCollection;
143}
144
146{
147 mCollection = collection;
148}
149
150QDateTime QgsStacItem::dateTime() const
151{
152 return QDateTime::fromString( mProperties.value( u"datetime"_s, u"null"_s ).toString() );
153}
154
156{
157 return mProperties.contains( u"start_datetime"_s ) && mProperties.contains( u"end_datetime"_s );
158}
159
161{
162 const QDateTime start = QDateTime::fromString( mProperties.value( u"start_datetime"_s, u"null"_s ).toString() );
163 const QDateTime end = QDateTime::fromString( mProperties.value( u"end_datetime"_s, u"null"_s ).toString() );
164 return QgsDateTimeRange( start, end );
165}
166
167QString QgsStacItem::title() const
168{
169 return mProperties.value( u"title"_s ).toString();
170}
171
173{
174 return mProperties.value( u"description"_s ).toString();
175}
176
178{
180 for ( const QgsStacAsset &asset : std::as_const( mAssets ) )
181 {
182 QgsMimeDataUtils::Uri uri = asset.uri();
183
184 // skip assets with incompatible formats
185 if ( uri.uri.isEmpty() )
186 continue;
187
188 uris.append( uri );
189 }
190 return uris;
191}
StacObjectType
Available types of stac objects.
Definition qgis.h:6885
@ Item
STAC item.
Definition qgis.h:6889
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
A geometry is the spatial representation of a feature.
QList< QgsMimeDataUtils::Uri > UriList
Stores data associated with a STAC asset.
QMap< QString, QgsStacAsset > assets() const
Returns a dictionary of asset objects, each with a unique key.
QString title() const
Returns an optional human readable title describing the Item.
QgsBox3D boundingBox() const
Returns the STAC item's spatial extent in WGS84 coordinates.
QgsMimeDataUtils::UriList uris() const
Returns a list of uris of all assets that have a cloud optimized format like COG or COPC.
QString description() const
Returns a Detailed multi-line description to fully explain the Item.
bool hasDateTimeRange() const
Returns true if a temporal interval is available for this item, false if a single QDateTime is availa...
QgsDateTimeRange dateTimeRange() const
Returns the temporal interval stored in the item's properties().
void setAssets(const QMap< QString, QgsStacAsset > &assets)
Sets the asset objects, each with a unique key.
void setProperties(const QVariantMap &properties)
Sets the item's additional metadata to properties.
QString collection() const
Returns the id of the STAC Collection this Item references to.
QDateTime dateTime() const
Returns the single nominal date/time for the item, stored in the item's properties().
QString toHtml() const override
Returns an HTML representation of the STAC object.
QVariantMap properties() const
Returns a dictionary of additional metadata for the Item.
QgsGeometry geometry() const
Returns the full footprint of the asset represented by this item, in WGS84.
QgsStacItem()=delete
Default constructor deleted, use the variant with required parameters.
Qgis::StacObjectType type() const override
Returns the Type of the STAC object.
void setBoundingBox(const QgsBox3D &bbox)
Sets the STAC item's spatial extent in WGS84 coordinates to bbox.
void setCollection(const QString &collection)
Sets the id of the STAC Collection this Item references to.
void setGeometry(const QgsGeometry &geometry)
Sets the full footprint of the asset represented by this item, in WGS84.
QString stacVersion() const
Returns the STAC version the object implements.
QString id() const
Id of the STAC object.
QVector< QgsStacLink > mLinks
QgsStacObject()=delete
Default constructor is used for creating invalid objects.
QStringList mStacExtensions
QVector< QgsStacLink > links() const
Returns the STAC links included in the object.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:705
QString uri
Identifier of the data source recognized by its providerKey.