Skip to content

Commit 42a3bcf

Browse files
uclaroswonder-sk
authored andcommitted
Address review
1 parent 5dd8b8c commit 42a3bcf

5 files changed

+248
-4
lines changed

src/core/stac/qgsstaccollections.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
QgsStacCollections::QgsStacCollections( const QVector< QgsStacCollection * > collections, const QVector< QgsStacLink > links, int numberMatched )
1919
: mCollections( collections )
20-
, mLinks( links )
2120
, mNumberMatched( numberMatched )
2221
{
23-
for ( const QgsStacLink &link : mLinks )
22+
for ( const QgsStacLink &link : links )
2423
{
2524
if ( link.relation() == QLatin1String( "self" ) ||
2625
link.relation() == QLatin1String( "root" ) ||
27-
link.relation() == QLatin1String( "next" ) )
26+
link.relation() == QLatin1String( "next" ) ||
27+
link.relation() == QLatin1String( "prev" ) )
2828
mUrls.insert( link.relation(), link.href() );
2929
}
3030
}
@@ -71,3 +71,8 @@ QUrl QgsStacCollections::nextUrl() const
7171
{
7272
return QUrl( mUrls.value( QStringLiteral( "next" ), QString() ) );
7373
}
74+
75+
QUrl QgsStacCollections::prevUrl() const
76+
{
77+
return QUrl( mUrls.value( QStringLiteral( "prev" ), QString() ) );
78+
}

src/core/stac/qgsstaccollections.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ class CORE_EXPORT QgsStacCollections
8787
*/
8888
QUrl nextUrl() const;
8989

90+
/**
91+
* Returns the url of the collections' "prev" link
92+
*/
93+
QUrl prevUrl() const;
94+
9095
private:
9196
QVector< QgsStacCollection * > mCollections;
92-
const QVector< QgsStacLink > mLinks;
9397
QMap< QString, QString > mUrls;
9498
int mNumberMatched = -1;
9599
};

tests/src/core/testqgsstac.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "qgsstaccatalog.h"
2525
#include "qgsstaccollection.h"
2626
#include "qgsstacitem.h"
27+
#include "qgsstacitemcollection.h"
28+
#include "qgsstaccollections.h"
2729
#include "qgsapplication.h"
2830
#include "qgsproject.h"
2931
#include "qgis.h"
@@ -48,6 +50,8 @@ class TestQgsStac : public QObject
4850
void testParseLocalCatalog();
4951
void testParseLocalCollection();
5052
void testParseLocalItem();
53+
void testParseLocalItemCollection();
54+
void testParseLocalCollections();
5155

5256
private:
5357
QString mDataDir;
@@ -146,5 +150,50 @@ void TestQgsStac::testParseLocalItem()
146150
delete item;
147151
}
148152

153+
void TestQgsStac::testParseLocalItemCollection()
154+
{
155+
const QString fileName = mDataDir + QStringLiteral( "itemcollection-sample-full.json" );
156+
QgsStacController c;
157+
QgsStacItemCollection *ic = c.fetchItemCollection( QStringLiteral( "file://%1" ).arg( fileName ) );
158+
QVERIFY( ic );
159+
QCOMPARE( ic->numberReturned(), 1 );
160+
QCOMPARE( ic->numberMatched(), 10 );
161+
QCOMPARE( ic->rootUrl().toString(), QLatin1String( "http://stac.example.com/" ) );
162+
163+
QVector<QgsStacItem *> items = ic->items();
164+
QCOMPARE( items.size(), 1 );
165+
QCOMPARE( items.first()->id(), QLatin1String( "cs3-20160503_132131_05" ) );
166+
QCOMPARE( items.first()->stacVersion(), QLatin1String( "1.0.0" ) );
167+
QCOMPARE( items.first()->links().size(), 3 );
168+
QCOMPARE( items.first()->stacExtensions().size(), 0 );
169+
QCOMPARE( items.first()->assets().size(), 2 );
170+
171+
delete ic;
172+
}
173+
174+
void TestQgsStac::testParseLocalCollections()
175+
{
176+
const QString fileName = mDataDir + QStringLiteral( "collectioncollection-sample-full.json" );
177+
QgsStacController c;
178+
QgsStacCollections *cols = c.fetchCollections( QStringLiteral( "file://%1" ).arg( fileName ) );
179+
QVERIFY( cols );
180+
QCOMPARE( cols->numberReturned(), 1 );
181+
QCOMPARE( cols->numberMatched(), 11 );
182+
QCOMPARE( cols->rootUrl().toString(), QLatin1String( "http://stac.example.com/" ) );
183+
QCOMPARE( cols->url().toString(), QLatin1String( "http://stac.example.com/collections?page=2" ) );
184+
QCOMPARE( cols->nextUrl().toString(), QLatin1String( "http://stac.example.com/collections?page=3" ) );
185+
QCOMPARE( cols->prevUrl().toString(), QLatin1String( "http://stac.example.com/collections?page=1" ) );
186+
187+
QCOMPARE( cols->collections().size(), 1 );
188+
189+
QgsStacCollection *col = cols->collections().first();
190+
QCOMPARE( col->id(), QStringLiteral( "simple-collection" ) );
191+
QCOMPARE( col->stacVersion(), QLatin1String( "1.0.0" ) );
192+
QCOMPARE( col->links().size(), 3 );
193+
QCOMPARE( col->stacExtensions().size(), 0 );
194+
195+
delete cols;
196+
}
197+
149198
QGSTEST_MAIN( TestQgsStac )
150199
#include "testqgsstac.moc"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"collections": [
3+
{
4+
"id": "simple-collection",
5+
"type": "Collection",
6+
"stac_extensions": [],
7+
"stac_version": "1.0.0",
8+
"description": "A simple collection demonstrating core collection fields in an API",
9+
"title": "Simple Example Collection",
10+
"providers": [
11+
{
12+
"name": "Remote Data, Inc",
13+
"description": "Producers of awesome spatiotemporal assets",
14+
"roles": [
15+
"producer",
16+
"processor"
17+
],
18+
"url": "http://remotedata.io"
19+
}
20+
],
21+
"extent": {
22+
"spatial": {
23+
"bbox": [
24+
[
25+
172.91173669923782,
26+
1.3438851951615003,
27+
172.95469614953714,
28+
1.3690476620161975
29+
]
30+
]
31+
},
32+
"temporal": {
33+
"interval": [
34+
[
35+
"2020-12-11T22:38:32.125Z",
36+
"2020-12-14T18:02:31.437Z"
37+
]
38+
]
39+
}
40+
},
41+
"license": "CC-BY-4.0",
42+
"links": [
43+
{
44+
"rel": "root",
45+
"href": "http://stac.example.com/",
46+
"type": "application/json"
47+
},
48+
{
49+
"rel": "items",
50+
"href": "http://stac.example.com/collections/simple-collection/items",
51+
"type": "application/geo+json"
52+
},
53+
{
54+
"rel": "self",
55+
"href": "http://stac.example.com/collections/simple-collection",
56+
"type": "application/json"
57+
}
58+
]
59+
}
60+
],
61+
"links": [
62+
{
63+
"rel": "self",
64+
"href": "http://stac.example.com/collections?page=2",
65+
"type": "application/json"
66+
},
67+
{
68+
"rel": "root",
69+
"href": "http://stac.example.com/",
70+
"type": "application/json"
71+
},
72+
{
73+
"rel": "next",
74+
"href": "http://stac.example.com/collections?page=3",
75+
"type": "application/json"
76+
},
77+
{
78+
"rel": "prev",
79+
"href": "http://stac.example.com/collections?page=1",
80+
"type": "application/json"
81+
}
82+
],
83+
"numberMatched": 11,
84+
"numberReturned": 1
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"type": "FeatureCollection",
3+
"numberMatched": 10,
4+
"numberReturned": 1,
5+
"features": [
6+
{
7+
"stac_version": "1.0.0",
8+
"stac_extensions": [],
9+
"type": "Feature",
10+
"id": "cs3-20160503_132131_05",
11+
"bbox": [
12+
-122.59750209,
13+
37.48803556,
14+
-122.2880486,
15+
37.613537207
16+
],
17+
"geometry": {
18+
"type": "Polygon",
19+
"coordinates": [
20+
[
21+
[
22+
-122.308150179,
23+
37.488035566
24+
],
25+
[
26+
-122.597502109,
27+
37.538869539
28+
],
29+
[
30+
-122.576687533,
31+
37.613537207
32+
],
33+
[
34+
-122.288048600,
35+
37.562818007
36+
],
37+
[
38+
-122.308150179,
39+
37.488035566
40+
]
41+
]
42+
]
43+
},
44+
"properties": {
45+
"datetime": "2016-05-03T13:22:30.040Z",
46+
"title": "A CS3 item",
47+
"license": "PDDL-1.0",
48+
"providers": [
49+
{
50+
"name": "CoolSat",
51+
"roles": [
52+
"producer",
53+
"licensor"
54+
],
55+
"url": "https://stac-api.example.com"
56+
}
57+
]
58+
},
59+
"collection": "cs3",
60+
"links": [
61+
{
62+
"rel": "self",
63+
"type": "application/json",
64+
"href": "https://stac-api.example.com/collections/cs3/items/CS3-20160503_132131_05"
65+
},
66+
{
67+
"rel": "root",
68+
"type": "application/json",
69+
"href": "https://stac-api.example.com/"
70+
},
71+
{
72+
"rel": "collection",
73+
"type": "application/json",
74+
"href": "https://stac-api.example.com/collections/cs3"
75+
}
76+
],
77+
"assets": {
78+
"analytic": {
79+
"href": "https://stac-api.example.com/catalog/cs3-20160503_132130_04/analytic.tif",
80+
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
81+
"title": "4-Band Analytic"
82+
},
83+
"thumbnail": {
84+
"href": "https://stac-api.example.com/catalog/cs3-20160503_132130_04/thumbnail.png",
85+
"type": "image/png",
86+
"title": "Thumbnail",
87+
"roles": [
88+
"thumbnail"
89+
]
90+
}
91+
}
92+
}
93+
],
94+
"links": [
95+
{
96+
"rel": "root",
97+
"href": "http://stac.example.com/",
98+
"type": "application/json"
99+
}
100+
]
101+
}

0 commit comments

Comments
 (0)