Skip to content

Commit

Permalink
Fix Client.get_collection for static catalogs (#782)
Browse files Browse the repository at this point in the history
* add static catalog to test data (copied from pystac)
* ensure that `Client.get_collection` returns specified collection
* ensure that if no matching collection is found it raises
  • Loading branch information
jsignell authored Jan 31, 2025
1 parent b9d6540 commit 1b16191
Show file tree
Hide file tree
Showing 18 changed files with 966 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- `Client.get_collection` for static catalogs [#782](https://github.com/stac-utils/pystac-client/pull/782)

## [v0.8.5] - 2024-10-23

### Fixed
Expand Down
7 changes: 6 additions & 1 deletion pystac_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def get_collection(self, collection_id: str) -> Union[Collection, CollectionClie
Raises:
NotFoundError if collection_id does not exist.
"""
collection: Union[Collection, CollectionClient]
collection: Collection | CollectionClient | None = None

if self._supports_collections():
assert self._stac_io is not None
Expand All @@ -411,6 +411,11 @@ def get_collection(self, collection_id: str) -> Union[Collection, CollectionClie
for collection in super().get_collections():
if collection.id == collection_id:
call_modifier(self.modifier, collection)
break

if collection is None:
raise KeyError(f"Collection {collection_id} not found on catalog")

return collection

def get_collections(self) -> Iterator[Collection]:
Expand Down
24 changes: 24 additions & 0 deletions tests/data/test-case-1/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "Catalog",
"id": "test",
"stac_version": "1.1.0",
"description": "test catalog",
"links": [
{
"rel": "child",
"href": "./country-1/catalog.json",
"type": "application/json"
},
{
"rel": "child",
"href": "./country-2/catalog.json",
"type": "application/json"
},
{
"rel": "root",
"href": "./catalog.json",
"type": "application/json"
}
],
"stac_extensions": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"type": "Feature",
"stac_version": "1.1.0",
"id": "area-1-1-imagery",
"properties": {
"datetime": "2019-10-04T18:55:37Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-2.5048828125,
3.8916575492899987
],
[
-1.9610595703125,
3.8916575492899987
],
[
-1.9610595703125,
4.275202171119132
],
[
-2.5048828125,
4.275202171119132
],
[
-2.5048828125,
3.8916575492899987
]
]
]
},
"links": [
{
"rel": "collection",
"href": "../collection.json",
"type": "application/json"
},
{
"rel": "root",
"href": "../../../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../collection.json",
"type": "application/json"
}
],
"assets": {
"ortho": {
"href": "http://example.com/area-1-1_ortho.tif",
"type": "image/vnd.stac.geotiff"
},
"dsm": {
"href": "http://example.com/area-1-1_dsm.tif",
"type": "image/vnd.stac.geotiff"
}
},
"bbox": [
-2.5048828125,
3.8916575492899987,
-1.9610595703125,
3.8916575492899987
],
"stac_extensions": [],
"collection": "area-1-1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"type": "Feature",
"stac_version": "1.1.0",
"id": "area-1-1-labels",
"properties": {
"datetime": "2019-10-04T18:55:37Z",
"label:description": "labels for area-1-1",
"label:type": "vector",
"label:properties": [
"label"
],
"label:classes": [
{
"name": "label",
"classes": [
"one",
"two"
]
}
],
"label:tasks": [
"classification"
],
"label:methods": [
"manual"
]
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-2.5048828125,
3.8916575492899987
],
[
-1.9610595703125,
3.8916575492899987
],
[
-1.9610595703125,
4.275202171119132
],
[
-2.5048828125,
4.275202171119132
],
[
-2.5048828125,
3.8916575492899987
]
]
]
},
"links": [
{
"rel": "source",
"href": "../area-1-1-imagery/area-1-1-imagery.json",
"type": "application/json"
},
{
"rel": "collection",
"href": "../collection.json",
"type": "application/json"
},
{
"rel": "root",
"href": "../../../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../collection.json",
"type": "application/json"
}
],
"assets": {
"labels": {
"href": "http://example.com/area-1-1-labels.geojson",
"type": "application/geo+json"
}
},
"bbox": [
-2.5048828125,
3.8916575492899987,
-1.9610595703125,
3.8916575492899987
],
"stac_extensions": [
"https://stac-extensions.github.io/label/v1.0.1/schema.json"
],
"collection": "area-1-1"
}
50 changes: 50 additions & 0 deletions tests/data/test-case-1/country-1/area-1-1/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"type": "Collection",
"id": "area-1-1",
"stac_version": "1.1.0",
"description": "test collection country-1",
"links": [
{
"rel": "item",
"href": "./area-1-1-imagery/area-1-1-imagery.json",
"type": "application/json"
},
{
"rel": "item",
"href": "./area-1-1-labels/area-1-1-labels.json",
"type": "application/json"
},
{
"rel": "root",
"href": "../../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../catalog.json",
"type": "application/json"
}
],
"stac_extensions": [],
"extent": {
"spatial": {
"bbox": [
[
-2.5048828125,
3.8916575492899987,
-1.9610595703125,
4.275202171119132
]
]
},
"temporal": {
"interval": [
[
"2019-10-04T18:55:37Z",
null
]
]
}
},
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"type": "Feature",
"stac_version": "1.1.0",
"id": "area-1-2-imagery",
"properties": {
"datetime": "2019-10-04T18:55:37Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-2.5048828125,
3.8916575492899987
],
[
-1.9610595703125,
3.8916575492899987
],
[
-1.9610595703125,
4.275202171119132
],
[
-2.5048828125,
4.275202171119132
],
[
-2.5048828125,
3.8916575492899987
]
]
]
},
"links": [
{
"rel": "collection",
"href": "../collection.json",
"type": "application/json"
},
{
"rel": "root",
"href": "../../../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../collection.json",
"type": "application/json"
}
],
"assets": {
"ortho": {
"href": "http://example.com/area-1-2_ortho.tif",
"type": "image/vnd.stac.geotiff"
},
"dsm": {
"href": "http://example.com/area-1-2_dsm.tif",
"type": "image/vnd.stac.geotiff"
}
},
"bbox": [
-2.5048828125,
3.8916575492899987,
-1.9610595703125,
3.8916575492899987
],
"stac_extensions": [],
"collection": "area-1-2"
}
Loading

0 comments on commit 1b16191

Please sign in to comment.