Skip to content

Simpler extension interface #1051

Closed
@jsignell

Description

@jsignell

I just started interacting with the extensions in pystac and I was surprised by the API. As an xarray user I was expecting to just do item.proj. I think we can implement that by copying the _CachedAccessor code from xarray (this seems to be what pandas has done as well)

Getting extension and setting fields on it

Existing API

from pystac.extensions.proj import ProjectionExtension
import pystac 

PROJ_EXT_EXAMPLE_URL = "https://raw.githubusercontent.com/stac-extensions/projection/v1.1.0/examples/item.json"
item = pystac.Item.from_file(PROJ_EXT_EXAMPLE_URL)

proj_ext = ProjectExtension.ext(item)
proj_ext.proj

Proposed API

import pystac 

PROJ_EXT_EXAMPLE_URL = "https://raw.githubusercontent.com/stac-extensions/projection/v1.1.0/examples/item.json"
item = pystac.Item.from_file(PROJ_EXT_EXAMPLE_URL)

item.proj.epsg

Adding extension to item

I'm not sure what adding new extensions to existing items should look like.

Existing API

from pystac.extensions.eo import EOExtension

eo_ext = EOExtension.add_to(item)
eo_ext.cloud_cover = 0.7

Options

In the most magical world (probably too magical) just setting an extension field on the item could add the extension to the item:

item.eo.cloud_cover = 0.7

Another option would be to preserver the existing explicit add_to and remove_from functionality but maybe with the functions defined on the STACObject class so you could do:

item.add_extension("eo")  
item.eo.cloud_cover = 0.7

Either way, I think trying to set the field directly: item.proj = ProjectionExtension() should fail.

xref: #448 where extensions are also being discussed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions