Skip to content

Commit b43b12e

Browse files
committed
StacDummyBuilder.asset: "data" role by default and add "proj:" helper arguments
1 parent de6f91b commit b43b12e

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

openeo/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.47.0a3"
1+
__version__ = "0.47.0a4"

openeo/testing/stac.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Union
1+
from typing import Any, Dict, List, Optional, Sequence, Union
22

33

44
class StacDummyBuilder:
@@ -117,13 +117,25 @@ def asset(
117117
cls,
118118
href: str = "https://stac.test/asset.tiff",
119119
type: str = "image/tiff; application=geotiff",
120-
roles: Optional[List[str]] = None,
120+
roles: Union[Sequence[str], None] = ("data",),
121+
proj_code: Optional[str] = None,
122+
proj_bbox: Optional[Sequence[float]] = None,
123+
proj_shape: Optional[Sequence[int]] = None,
124+
proj_transform: Optional[Sequence[float]] = None,
121125
**kwargs,
122126
):
123-
d = {"href": href, **kwargs}
127+
d: Dict[str, Any] = {"href": href, **kwargs}
124128
if type:
125129
d["type"] = type
126-
if roles is not None:
127-
d["roles"] = roles
130+
if roles:
131+
d["roles"] = list(roles)
132+
if proj_code:
133+
d["proj:code"] = proj_code
134+
if proj_bbox:
135+
d["proj:bbox"] = list(proj_bbox)
136+
if proj_shape:
137+
d["proj:shape"] = list(proj_shape)
138+
if proj_transform:
139+
d["proj:transform"] = list(proj_transform)
128140

129141
return d

tests/testing/test_stac.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ def test_asset_default(self):
8787
assert asset == {
8888
"href": "https://stac.test/asset.tiff",
8989
"type": "image/tiff; application=geotiff",
90+
"roles": ["data"],
91+
}
92+
pystac.Asset.from_dict(asset)
93+
94+
def test_asset_no_roles(self):
95+
asset = StacDummyBuilder.asset(roles=None)
96+
assert asset == {
97+
"href": "https://stac.test/asset.tiff",
98+
"type": "image/tiff; application=geotiff",
99+
}
100+
pystac.Asset.from_dict(asset)
101+
102+
def test_asset_proj_fields(self):
103+
asset = StacDummyBuilder.asset(
104+
proj_code="EPSG:4326",
105+
proj_bbox=(3, 51, 4, 52),
106+
proj_shape=(100, 100),
107+
proj_transform=(0.01, 0.0, 3.0, 0.0, -0.01, 52.0),
108+
)
109+
assert asset == {
110+
"href": "https://stac.test/asset.tiff",
111+
"type": "image/tiff; application=geotiff",
112+
"roles": ["data"],
113+
"proj:code": "EPSG:4326",
114+
"proj:bbox": [3, 51, 4, 52],
115+
"proj:shape": [100, 100],
116+
"proj:transform": [0.01, 0.0, 3.0, 0.0, -0.01, 52.0],
90117
}
91-
# Check if the default asset validates
92118
pystac.Asset.from_dict(asset)

0 commit comments

Comments
 (0)