Skip to content

Commit 10cb05d

Browse files
authored
Update datacube extension (#1269)
* feat: update datacube extension * chore: update changelog
1 parent ce21599 commit 10cb05d

File tree

7 files changed

+1697
-344
lines changed

7 files changed

+1697
-344
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- `validate_all` now accepts a `STACObject` (in addition to accepting a dict, which is now deprecated), but prohibits supplying a value for `href`, which must be supplied _only_ when supplying an object as a dict. Once `validate_all` removes support for an object as a dict, the `href` parameter will also be removed. ([#1246](https://github.com/stac-utils/pystac/pull/1246))
1414
- Report `href` when schema url resolution fails ([#1263](https://github.com/stac-utils/pystac/pull/1263))
1515
- Version extension updated to v1.2.0 ([#1262](https://github.com/stac-utils/pystac/pull/1262))
16+
- Datacube extension updated to v2.2.0 ([#1269](https://github.com/stac-utils/pystac/pull/1269))
1617

1718
### Fixed
1819

pystac/extensions/datacube.py

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"T", pystac.Collection, pystac.Item, pystac.Asset, item_assets.AssetDefinition
1616
)
1717

18-
SCHEMA_URI = "https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
18+
SCHEMA_URI = "https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
1919

2020
PREFIX: str = "cube:"
2121
DIMENSIONS_PROP = PREFIX + "dimensions"
@@ -44,6 +44,7 @@ class DimensionType(StringEnum):
4444
"""Dimension object types for spatial and temporal Dimension Objects."""
4545

4646
SPATIAL = "spatial"
47+
GEOMETRIES = "geometries"
4748
TEMPORAL = "temporal"
4849

4950

@@ -75,12 +76,16 @@ def __init__(self, properties: dict[str, Any]) -> None:
7576

7677
@property
7778
def dim_type(self) -> DimensionType | str:
78-
"""The type of the dimension. Must be ``"spatial"`` for :stac-ext:`Horizontal
79-
Spatial Dimension Objects <datacube#horizontal-spatial-dimension-object>` or
79+
"""The type of the dimension. Must be ``"spatial"`` for
80+
:stac-ext:`Horizontal Spatial Dimension Objects
81+
<datacube#horizontal-raster-spatial-dimension-object>` or
8082
:stac-ext:`Vertical Spatial Dimension Objects
81-
<datacube#vertical-spatial-dimension-object>`, and ``"temporal"`` for
82-
:stac-ext:`Temporal Dimension Objects <datacube#temporal-dimension-object>`. May
83-
be an arbitrary string for :stac-ext:`Additional Dimension Objects
83+
<datacube#vertical-spatial-dimension-object>`, ``geometries`` for
84+
:stac-ext:`Spatial Vector Dimension Objects
85+
<datacube#spatial-vector-dimension-object>` ``"temporal"`` for
86+
:stac-ext:`Temporal Dimension Objects
87+
<datacube#temporal-dimension-object>`. May be an arbitrary string for
88+
:stac-ext:`Additional Dimension Objects
8489
<datacube#additional-dimension-object>`."""
8590
return get_required(
8691
self.properties.get(DIM_TYPE_PROP), "cube:dimension", DIM_TYPE_PROP
@@ -119,6 +124,8 @@ def from_dict(d: dict[str, Any]) -> Dimension:
119124
return VerticalSpatialDimension(d)
120125
else:
121126
return HorizontalSpatialDimension(d)
127+
elif dim_type == DimensionType.GEOMETRIES:
128+
return VectorSpatialDimension(d)
122129
elif dim_type == DimensionType.TEMPORAL:
123130
# The v1.0.0 spec says that AdditionalDimensions can have
124131
# type 'temporal', but it is unclear how to differentiate that
@@ -225,6 +232,68 @@ def unit(self, v: str | None) -> None:
225232
self.properties[DIM_UNIT_PROP] = v
226233

227234

235+
class VectorSpatialDimension(Dimension):
236+
@property
237+
def axes(self) -> list[str] | None:
238+
"""Axes of the vector dimension as an ordered set of `x`, `y` and `z`."""
239+
return self.properties.get("axes")
240+
241+
@axes.setter
242+
def axes(self, v: list[str]) -> None:
243+
if v is None:
244+
self.properties.pop("axes", None)
245+
else:
246+
self.properties["axes"] = v
247+
248+
@property
249+
def bbox(self) -> list[float]:
250+
"""A single bounding box of the geometries as defined for STAC
251+
Collections but not nested."""
252+
return get_required(self.properties.get("bbox"), "cube:bbox", "bbox")
253+
254+
@bbox.setter
255+
def bbox(self, v: list[float]) -> None:
256+
self.properties["bbox"] = v
257+
258+
@property
259+
def values(self) -> list[str] | None:
260+
"""Optionally, a representation of the geometries. This could be a list
261+
of WKT strings or other identifiers."""
262+
return self.properties.get(DIM_VALUES_PROP)
263+
264+
@values.setter
265+
def values(self, v: list[str] | None) -> None:
266+
if v is None:
267+
self.properties.pop(DIM_VALUES_PROP, None)
268+
else:
269+
self.properties[DIM_VALUES_PROP] = v
270+
271+
@property
272+
def geometry_types(self) -> list[str] | None:
273+
"""A set of geometry types. If not present, mixed geometry types must be
274+
assumed."""
275+
return self.properties.get("geometry_types")
276+
277+
@geometry_types.setter
278+
def geometry_types(self, v: list[str] | None) -> None:
279+
if v is None:
280+
self.properties.pop("geometry_types", None)
281+
else:
282+
self.properties["geometry_types"] = v
283+
284+
@property
285+
def reference_system(self) -> str | float | dict[str, Any] | None:
286+
"""The reference system for the data."""
287+
return self.properties.get(DIM_REF_SYS_PROP)
288+
289+
@reference_system.setter
290+
def reference_system(self, v: str | float | dict[str, Any] | None) -> None:
291+
if v is None:
292+
self.properties.pop(DIM_REF_SYS_PROP, None)
293+
else:
294+
self.properties[DIM_REF_SYS_PROP] = v
295+
296+
228297
class TemporalDimension(Dimension):
229298
@property
230299
def extent(self) -> list[str | None] | None:
@@ -636,6 +705,8 @@ class DatacubeExtensionHooks(ExtensionHooks):
636705
prev_extension_ids = {
637706
"datacube",
638707
"https://stac-extensions.github.io/datacube/v1.0.0/schema.json",
708+
"https://stac-extensions.github.io/datacube/v2.0.0/schema.json",
709+
"https://stac-extensions.github.io/datacube/v2.1.0/schema.json",
639710
}
640711
stac_object_types = {
641712
pystac.STACObjectType.COLLECTION,

tests/data-files/datacube/item.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stac_version": "1.0.0",
33
"stac_extensions": [
4-
"https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
4+
"https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
55
],
66
"id": "datacube-123",
77
"type": "Feature",
@@ -100,15 +100,15 @@
100100
},
101101
"cube:variables": {
102102
"temp": {
103-
"dimensions": [
104-
"time",
105-
"y",
106-
"x",
107-
"pressure_levels"
108-
],
109-
"type": "data"
103+
"dimensions": [
104+
"time",
105+
"y",
106+
"x",
107+
"pressure_levels"
108+
],
109+
"type": "data"
110110
}
111-
}
111+
}
112112
},
113113
"assets": {
114114
"data": {

0 commit comments

Comments
 (0)