Skip to content

Commit 658473e

Browse files
nlebovitsgadomski
andauthored
docs: add how to section (#823)
* docs: add how to section - add how to section to docs with latest datetime search across multiple collections * docs: update changelog --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent f418960 commit 658473e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Make `get_collection` raise if `collection_id` is empty ([#809](https://github.com/stac-utils/pystac-client/pull/809))
1313

14+
### Documentation
15+
16+
- Add "How to..." section to usage documentation with latest datetime search across multiple collections example ([#823](https://github.com/stac-utils/pystac-client/pull/823))
17+
1418
## [v0.9.0] - 2025-07-17
1519

1620
### Added

docs/usage.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,33 @@ example from **odc-stac**'s documentation:
555555
556556
557557
See each packages's respective documentation for more examples and tutorials.
558+
559+
.. _how_to:
560+
561+
How To
562+
++++++++++++
563+
564+
Get the latest dataset across multiple collections
565+
-----------------------------------------
566+
567+
When searching for multiple datasets across different collections, each dataset may be derived from a different time period. You may want to get the latest dataset for each collection instead of all available datasets.
568+
569+
.. code-block:: python
570+
571+
from pystac_client import Client
572+
573+
client = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1")
574+
items = []
575+
for collection in ["nasadem", "esa-worldcover", "jrc-gsw"]:
576+
items.append(
577+
next(
578+
client.search(
579+
collections=[collection], max_items=1, sortby="-properties.datetime"
580+
).items()
581+
)
582+
)
583+
584+
The result will be a list containing the most recent item from each collection:
585+
586+
>>> items
587+
[<Item id=NASADEM_HGT_s56w072>, <Item id=ESA_WorldCover_10m_2021_v200_S60W030>, <Item id=90W_80Nv1_3_2020>]

0 commit comments

Comments
 (0)