示例#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);
        }
示例#2
0
        /// <summary>
        /// Set the id of the STAC Collection this Item references to
        /// see <seealso href="https://github.com/radiantearth/stac-spec/blob/master/item-spec/item-spec.md#relation-types">collection relation type</seealso>.
        /// </summary>
        /// <param name="stacItem">stacItem to set the collection to</param>
        /// <param name="collectionId">identifier of the collection</param>
        /// <param name="collectionUri">uri to the collection</param>
        /// <param name="collectionTitle">optional title of the collection</param>
        public static void SetCollection(this StacItem stacItem, string collectionId, Uri collectionUri, string collectionTitle = null)
        {
            var existingLink = stacItem.Links.FirstOrDefault(l => l.Uri == collectionUri);

            if (existingLink != null)
            {
                stacItem.Links.Remove(existingLink);
            }
            stacItem.Links.Add(StacLink.CreateCollectionLink(collectionUri));
            stacItem.Collection = collectionId;
        }
示例#3
0
 public StacLink(StacLink source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     Uri = source.Uri;
     RelationshipType = source.RelationshipType;
     Title            = source.Title;
     ContentType      = source.ContentType;
     Parent           = source.Parent;
     Length           = source.Length;
 }