@@ -18,12 +18,42 @@ func init() {
18
18
return & Asset {}
19
19
},
20
20
)
21
+
22
+ stac .RegisterItemExtension (
23
+ regexp .MustCompile (extensionPattern ),
24
+ func () stac.Extension {
25
+ return & Item {}
26
+ },
27
+ )
21
28
}
22
29
23
- type Asset struct {
30
+ type Item struct {
24
31
CloudCover * float64 `json:"eo:cloud_cover,omitempty"`
25
32
SnowCover * float64 `json:"eo:snow_cover,omitempty"`
26
- Bands []* Band `json:"eo:bands,omitempty"`
33
+ }
34
+
35
+ var _ stac.Extension = (* Item )(nil )
36
+
37
+ func (* Item ) URI () string {
38
+ return extensionUri
39
+ }
40
+
41
+ func (e * Item ) Encode (itemMap map [string ]any ) error {
42
+ return stac .EncodeExtendedItemProperties (e , itemMap )
43
+ }
44
+
45
+ func (e * Item ) Decode (itemMap map [string ]any ) error {
46
+ if err := stac .DecodeExtendedItemProperties (e , itemMap ); err != nil {
47
+ return err
48
+ }
49
+ if e .CloudCover == nil && e .SnowCover == nil {
50
+ return stac .ErrExtensionDoesNotApply
51
+ }
52
+ return nil
53
+ }
54
+
55
+ type Asset struct {
56
+ Bands []* Band `json:"eo:bands,omitempty"`
27
57
}
28
58
29
59
type Band struct {
@@ -46,5 +76,11 @@ func (e *Asset) Encode(assetMap map[string]any) error {
46
76
}
47
77
48
78
func (e * Asset ) Decode (assetMap map [string ]any ) error {
49
- return stac .DecodeExtendedMap (e , assetMap )
79
+ if err := stac .DecodeExtendedMap (e , assetMap ); err != nil {
80
+ return err
81
+ }
82
+ if len (e .Bands ) == 0 {
83
+ return stac .ErrExtensionDoesNotApply
84
+ }
85
+ return nil
50
86
}
0 commit comments