Skip to content

Further Fixes for STAC Search#2340

Open
rajadain wants to merge 4 commits into
geopython:masterfrom
LimnoTech:tt/fix-stac-api-on-starlette
Open

Further Fixes for STAC Search#2340
rajadain wants to merge 4 commits into
geopython:masterfrom
LimnoTech:tt/fix-stac-api-on-starlette

Conversation

@rajadain
Copy link
Copy Markdown
Contributor

@rajadain rajadain commented May 11, 2026

Overview

Minor fixes that allow the STAC search endpoint to work correctly. This is in support of the USGS NHGF work.

Related Issue / discussion

This is a continuation of #2153.

Closes #2354
Closes #2355
Closes #2356

Additional information

Dependency policy (RFC2)

  • I have ensured that this PR meets RFC2 requirements

Updates to public demo

Contributions and licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

  • I'd like to contribute [feature X|bugfix Y|docs|something else] to pygeoapi. I confirm that my contributions to pygeoapi will be compatible with the pygeoapi license guidelines at the time of contribution
  • I have already previously agreed to the pygeoapi Contributions and Licensing Guidelines

@rajadain rajadain force-pushed the tt/fix-stac-api-on-starlette branch from 2d5f412 to a33a862 Compare May 11, 2026 21:25
Copy link
Copy Markdown
Member

@tomkralidis tomkralidis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See change requests. It would be valuable to clarify the problems the PR attempts to address/fix (and/or feel free to create an issue). Thanks!

Comment thread pygeoapi/api/stac.py
for la in ['links', 'assets']:
if feature.get(la) is None:
feature[la] = []
if feature.get('links') is None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the content model that this update is based on? Is properties.content.links and properties.content.assets part of STAC proper?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As can be seen in the STAC Spec:

image

links is a list, and assets is a dict.

Comment thread pygeoapi/api/stac.py Outdated
LOGGER.debug('Attempting to derive temporal from GeoJSON feature')
LOGGER.debug(feature)
if feature.get('time') is not None:
if not value.get('datetime') and feature.get('time') is not None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do if value.get('datetime') is None and feature.get('time') is not None: for readability?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 72e7a7f

Comment thread pygeoapi/api/stac.py Outdated
value['end_datetime'] = feature['time']['interval'][1]

if feature['properties'].get('created') is not None:
if not value.get('datetime') \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do if value.get('datetime') is None and feature['properties'].get('created') is not None: for readability?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 72e7a7f

@tomkralidis tomkralidis added the STAC SpatioTemporal Asset Catalog label May 12, 2026
@rajadain
Copy link
Copy Markdown
Contributor Author

Thank you for taking a quick look! I'll add more context and motivation for the changes, and make the readability improvements today. 🙏

rajadain added 4 commits June 5, 2026 14:18
This mistakenly used double slashes in the URL
which would break the output. A single slash fixes
this.

Closes geopython#2354
As specified in the STAC spec: https://stacspec.org/en/about/stac-spec/
assets are dicts, not lists. When missing,
now they are initialized as the correct empty
data structures.

Closes geopython#2354
Althought the STAC specification expects links and
assets to be top-level items, this is not the case
in pgSTAC tables, which store the details in a
`contents` JSONB column:

https://github.com/stac-utils/pgstac/blob/08ce5991e7840f51993d508c715fad44f889e5e5/src/pgstac/pgstac.sql#L889-L899

In cases where the top-level items are not available,
we attempt to source them fromm the pgSTAC-specific
source if available.

Closes geopython#2355
Previously the `datetime` field was not used to initalize
the temporal instant, causing it to be overridden by
other approximations.

This ensure that the initialization happens correctly,
and the overrides only occur in cases when `datetime`
is None.

Closes geopython#2356
@rajadain rajadain force-pushed the tt/fix-stac-api-on-starlette branch from a33a862 to 72e7a7f Compare June 5, 2026 18:24
@rajadain
Copy link
Copy Markdown
Contributor Author

rajadain commented Jun 5, 2026

Apologies for the long delay in getting back to this.

I created cards specifying the individual issues we need to fix: #2354, #2355, #2356. I've also marked this PR as closing those bugs. I've also added more detail to the individual commits, better explaining their relevance and motivation. And I've incorporated your keen recommendations to improve readability.

Would appreciate a second look at your convenience. Thank you!

Comment thread pygeoapi/api/stac.py
if feature.get(la) is None:
feature[la] = []
if feature.get('links') is None:
feature['links'] = feature\
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I am seeing:

                        .get('properties', {})\
                        .get('content', {})\
                        .get('links', [])

A STAC Item indeed has links and assets, but they are at the root of the STAC item, not in an object called properties.content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. This is quirk of the pgSTAC back-end. Please see #2355 for a more detailed explanation. I can also add a comment here pointing to that to keep the context near the code.

Also open to alternative approaches to address this discrepancy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I would suggest removing this given it is backend specific. You can work around this by adding your own feature provider plugin which reads PgSTAC and returns items such that the STAC code in pygeoapi is reading content on the absence of a backend specific data model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

STAC SpatioTemporal Asset Catalog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Instantaneous STAC datetime not correctly initialized Bug: STAC Item Search Breaks Bug: Links and Assets not sourced correctly from pgSTAC

2 participants