Skip to content

Commit

Permalink
Merge pull request #198 from planetlabs/eo-item
Browse files Browse the repository at this point in the history
Move eo properties from asset to item
  • Loading branch information
tschaub authored Sep 5, 2024
2 parents c130d9b + 3d94cac commit 2e49598
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 78 deletions.
42 changes: 39 additions & 3 deletions extensions/eo/eo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,42 @@ func init() {
return &Asset{}
},
)

stac.RegisterItemExtension(
regexp.MustCompile(extensionPattern),
func() stac.Extension {
return &Item{}
},
)
}

type Asset struct {
type Item struct {
CloudCover *float64 `json:"eo:cloud_cover,omitempty"`
SnowCover *float64 `json:"eo:snow_cover,omitempty"`
Bands []*Band `json:"eo:bands,omitempty"`
}

var _ stac.Extension = (*Item)(nil)

func (*Item) URI() string {
return extensionUri
}

func (e *Item) Encode(itemMap map[string]any) error {
return stac.EncodeExtendedItemProperties(e, itemMap)
}

func (e *Item) Decode(itemMap map[string]any) error {
if err := stac.DecodeExtendedItemProperties(e, itemMap); err != nil {
return err
}
if e.CloudCover == nil && e.SnowCover == nil {
return stac.ErrExtensionDoesNotApply
}
return nil
}

type Asset struct {
Bands []*Band `json:"eo:bands,omitempty"`
}

type Band struct {
Expand All @@ -46,5 +76,11 @@ func (e *Asset) Encode(assetMap map[string]any) error {
}

func (e *Asset) Decode(assetMap map[string]any) error {
return stac.DecodeExtendedMap(e, assetMap)
if err := stac.DecodeExtendedMap(e, assetMap); err != nil {
return err
}
if len(e.Bands) == 0 {
return stac.ErrExtensionDoesNotApply
}
return nil
}
Loading

0 comments on commit 2e49598

Please sign in to comment.