/// <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); }
public ItemCollection(string id, string description, List <StacItem> stacItems) : base(id, description, null) { if (stacItems != null) { Features = new List <StacItem>(stacItems); Extent = StacExtent.Create(stacItems); } }