|
| 1 | +package stac |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + |
| 6 | + "github.com/mitchellh/mapstructure" |
| 7 | +) |
| 8 | + |
| 9 | +type Collection struct { |
| 10 | + Version string `json:"stac_version"` |
| 11 | + Id string `json:"id"` |
| 12 | + Title string `json:"title,omitempty"` |
| 13 | + Description string `json:"description"` |
| 14 | + Keywords []string `json:"keywords,omitempty"` |
| 15 | + License string `json:"license"` |
| 16 | + Providers []*Provider `json:"providers,omitempty"` |
| 17 | + Extent *Extent `json:"extent"` |
| 18 | + Summaries map[string]any `json:"summaries,omitempty"` |
| 19 | + Links []*Link `json:"links"` |
| 20 | + Assets map[string]*Asset `json:"assets,omitempty"` |
| 21 | +} |
| 22 | + |
| 23 | +type Provider struct { |
| 24 | + Name string `json:"name"` |
| 25 | + Description string `json:"description,omitempty"` |
| 26 | + Roles []string `json:"roles,omitempty"` |
| 27 | + Url string `json:"url,omitempty"` |
| 28 | +} |
| 29 | + |
| 30 | +type Extent struct { |
| 31 | + Spatial *SpatialExtent `json:"spatial,omitempty"` |
| 32 | + Temporal *TemporalExtent `json:"temporal,omitempty"` |
| 33 | +} |
| 34 | + |
| 35 | +type SpatialExtent struct { |
| 36 | + Bbox [][]float64 `json:"bbox"` |
| 37 | +} |
| 38 | + |
| 39 | +type TemporalExtent struct { |
| 40 | + Interval [][]any `json:"interval"` |
| 41 | +} |
| 42 | + |
| 43 | +var _ json.Marshaler = (*Collection)(nil) |
| 44 | + |
| 45 | +func (collection Collection) MarshalJSON() ([]byte, error) { |
| 46 | + collectionMap := map[string]any{ |
| 47 | + "type": "Collection", |
| 48 | + } |
| 49 | + decoder, decoderErr := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ |
| 50 | + TagName: "json", |
| 51 | + Result: &collectionMap, |
| 52 | + }) |
| 53 | + if decoderErr != nil { |
| 54 | + return nil, decoderErr |
| 55 | + } |
| 56 | + |
| 57 | + decodeErr := decoder.Decode(collection) |
| 58 | + if decodeErr != nil { |
| 59 | + return nil, decodeErr |
| 60 | + } |
| 61 | + |
| 62 | + return json.Marshal(collectionMap) |
| 63 | +} |
| 64 | + |
| 65 | +type CollectionsList struct { |
| 66 | + Collections []*Collection `json:"collections"` |
| 67 | + Links []*Link `json:"links"` |
| 68 | +} |
0 commit comments