Example #1
0
        /// <summary>
        /// Generate a collection corresponding to the items' dictionary. Spatial and temporal extents
        /// are computed. Fields values are summarized in stats object and value sets.
        /// All Items are updated with the collection id
        /// </summary>

        /// <param name="id">Identifier of the collection</param>
        /// <param name="description">Description of the collection</param>
        /// <param name="items">Dictionary of Uri, StacItem. Uri points to the StacItem destination.</param>
        /// <param name="license">License of the collection</param>
        /// <param name="collectionUri">Uri of the collection. If provided, the items Uri and made relative to this one.</param>
        /// <param name="assets">Assets of the collection</param>
        /// <returns></returns>
        public static StacCollection Create(string id,
                                            string description,
                                            IDictionary <Uri, StacItem> items,
                                            string license    = null,
                                            Uri collectionUri = null,
                                            IDictionary <string, StacAsset> assets = null)
        {
            var collection = new StacCollection(
                id,
                description,
                StacExtent.Create(items.Values),
                assets,
                items.Select(item =>
            {
                Uri itemUri = item.Key;
                if (collectionUri != null)
                {
                    itemUri = collectionUri.MakeRelativeUri(item.Key);
                }
                if (!itemUri.IsAbsoluteUri)
                {
                    itemUri = new Uri("./" + itemUri.OriginalString, UriKind.Relative);
                }
                return(StacLink.CreateObjectLink(item.Value, itemUri));
            }),
                license);

            var usedExtensions = items.SelectMany(item => item.Value.GetDeclaredExtensions());

            var summaryFunctions = usedExtensions.SelectMany(ext => ext.GetSummaryFunctions())
                                   .GroupBy(prop => prop.Key)
                                   .ToDictionary(key => key.Key, value => value.First().Value);

            summaryFunctions.Add("gsd", new SummaryFunction <double>(null, "gsd", StacPropertiesContainerExtension.CreateRangeSummaryObject <double>));
            summaryFunctions.Add("platform", new SummaryFunction <string>(null, "platform", StacPropertiesContainerExtension.CreateSummaryValueSet <string>));
            summaryFunctions.Add("constellation", new SummaryFunction <string>(null, "constellation", StacPropertiesContainerExtension.CreateSummaryValueSet <string>));
            summaryFunctions.Add("instruments", new SummaryFunction <string>(null, "instruments", StacPropertiesContainerExtension.CreateSummaryValueSet <string>));

            collection.Summaries =
                items.Values.SelectMany(item => item.Properties.Where(k => summaryFunctions.Keys.Contains(k.Key)))
                .GroupBy(prop => prop.Key)
                .ToDictionary(key => key.Key, value =>
            {
                if (summaryFunctions.ContainsKey(value.Key))
                {
                    if (summaryFunctions[value.Key].Extension != null && !collection.StacExtensions.Contains(summaryFunctions[value.Key].Extension.Identifier))
                    {
                        collection.StacExtensions.Add(summaryFunctions[value.Key].Extension.Identifier);
                    }
                    return(summaryFunctions[value.Key].Summarize(value.Select(i => i.Value)));
                }
                return(null);
            });

            return(collection);
        }
Example #2
0
 /// <summary>
 /// Initialize a new Stac Collection from an existing one (clone)
 /// </summary>
 /// <param name="stacCollection">existing Stac Collection</param>
 public StacCollection(StacCollection stacCollection)
 {
     this.Id             = stacCollection.Id;
     this.StacExtensions = new SortedSet <string>(stacCollection.StacExtensions);
     this.StacVersion    = stacCollection.StacVersion;
     this.Links          = new Collection <StacLink>(stacCollection.Links.ToList());
     this.Summaries      = new Dictionary <string, Stac.Collection.IStacSummaryItem>(stacCollection.Summaries);
     this.Properties     = new Dictionary <string, object>(stacCollection.Properties);
     this.Assets         = new Dictionary <string, StacAsset>(stacCollection.Assets);
     this.License        = stacCollection.License;
     this.Keywords       = new Collection <string>(stacCollection.Keywords);
     this.Extent         = new StacExtent(stacCollection.Extent);
 }