Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Client.get_collection for static catalogs #782

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jsignell marked this conversation as resolved.
Show resolved Hide resolved

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
Loading