Exemplo n.º 1
0
        public void CreateEoExtension()
        {
            var coordinates = new[]
            {
                new List <IPosition>
                {
                    new Position(37.488035566, -122.308150179),
                    new Position(37.538869539, -122.597502109),
                    new Position(37.613537207, -122.576687533),
                    new Position(37.562818007, -122.288048600),
                    new Position(37.488035566, -122.308150179)
                }
            };

            var geometry = new Polygon(new LineString[] { new LineString(coordinates[0]) });

            var properties = new Dictionary <string, object>();

            properties.Add("datetime", DateTime.Parse("2016-05-03T13:21:30.040Z").ToUniversalTime());

            StacItem item = new StacItem("CS3-20160503_132130_04", geometry, properties);

            item.Links.Add(StacLink.CreateSelfLink(new Uri("http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json")));
            item.SetCollection("CS3", new Uri("http://cool-sat.com/catalog.json"));

            var asset = new StacAsset(item, new Uri("relative-path/to/analytic.tif", UriKind.Relative), null, "4-Band Analytic", null);

            asset.EoExtension().CloudCover = 0;

            item.Assets.Add("analytic", asset);
            item.Assets.Add("thumbnail", StacAsset.CreateThumbnailAsset(item, new Uri("http://cool-sat.com/catalog/CS3-20160503_132130_04/thumbnail.png"), null, "Thumbnail"));

            // item.BoundingBoxes = new double[4] { -122.59750209, 37.48803556, -122.2880486, 37.613537207 };
            item.BoundingBoxes = item.GetBoundingBoxFromGeometryExtent();

            EoStacExtension eo = item.EoExtension();

            eo.CloudCover = 0;

            Assert.Equal <double>(0.0, eo.CloudCover.Value);
            Assert.Equal <double>(0.0, double.Parse(asset.Properties["eo:cloud_cover"].ToString()));

            var actualJson = StacConvert.Serialize(item);

            ValidateJson(actualJson);

            var expectedJson = GetJson("Item");

            ValidateJson(expectedJson);

            JsonAssert.AreEqual(expectedJson, actualJson);

            asset.EoExtension().Bands = null;

            Assert.Null(asset.GetProperty("eo:bands"));
        }
Exemplo n.º 2
0
        public void GetAssetsBands()
        {
            var k3CompleteJson = GetJson("Item", "GetAssetsBands_K3_20201112193439_45302_18521139_L1G");

            ValidateJson(k3CompleteJson);

            StacItem k3complete = StacConvert.Deserialize <StacItem>(k3CompleteJson);

            var overviewAssets = k3complete.Assets.Where(a =>
            {
                if (a.Value.Properties.ContainsKey("eo:bands"))
                {
                    Assert.NotNull(k3complete.EoExtension().Bands);
                    Assert.NotEmpty(k3complete.EoExtension().Bands);
                    return(k3complete.EoExtension().Bands.Any(band => !string.IsNullOrEmpty(band.Name)));
                }
                return(false);
            });

            Assert.Equal(5, overviewAssets.Count());
        }
Exemplo n.º 3
0
        public Dictionary <string, StacAsset> SelectOverviewCombinationAssets(StacItem stacItem)
        {
            Dictionary <string, StacAsset> overviewAssets = stacItem.Assets
                                                            .Where(a => a.Value.Roles != null)
                                                            .Where(a => a.Value.Roles.Contains("overview") ||
                                                                   a.Value.Roles.Contains("visual"))
                                                            .Where(a => a.Key == "overview-trc")
                                                            .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                                                            .Take(1)
                                                            .ToDictionary(a => a.Key, a => a.Value);

            if (overviewAssets.Count == 1)
            {
                return(overviewAssets);
            }

            overviewAssets = stacItem.Assets.Where(a => a.Value.Roles != null)
                             .Where(a => a.Value.Roles.Contains("overview") ||
                                    a.Value.Roles.Contains("visual"))
                             .OrderBy(a => a.Value.GetProperty <long>("size"))
                             .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                             .Take(1)
                             .ToDictionary(a => a.Key, a => a.Value);
            if (overviewAssets.Count == 1)
            {
                return(overviewAssets);
            }

            var projext = stacItem.ProjectionExtension();

            overviewAssets = stacItem.Assets
                             .Where(a => a.Key.Equals("red", StringComparison.InvariantCultureIgnoreCase) ||
                                    a.Key.Equals("green", StringComparison.InvariantCultureIgnoreCase) ||
                                    a.Key.Equals("blue", StringComparison.InvariantCultureIgnoreCase))
                             .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                             .OrderByDescending(a => a.Key)
                             .ToDictionary(a => a.Key, a => a.Value);
            if (overviewAssets.Count == 3 && projext.IsDeclared)
            {
                return(overviewAssets);
            }

            var eoStacExtension = stacItem.EoExtension();

            if (eoStacExtension.IsDeclared)
            {
                overviewAssets = stacItem.Assets.Where(a =>
                {
                    var bands = a.Value.GetProperty <EoBandObject[]>("eo:bands");
                    if (bands == null)
                    {
                        return(false);
                    }
                    return(bands.Any(band => OVERVIEW_NAMES.ToList().Contains(band.CommonName.ToString())));
                })
                                 .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                                 .OrderByDescending(a => a.Value.GetProperty <EoBandObject[]>("eo:bands").First().CommonName.ToString())
                                 .Take(3)
                                 .ToDictionary(a => a.Key, a => a.Value);
            }
            if (overviewAssets.Count >= 1 && projext != null)
            {
                return(overviewAssets);
            }

            overviewAssets = stacItem.Assets
                             .Where(a => a.Key == "overview")
                             .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                             .ToDictionary(a => a.Key, a => a.Value);
            if (overviewAssets.Count == 1)
            {
                return(overviewAssets);
            }

            overviewAssets = stacItem.Assets
                             .Where(a => a.Key == "composite")
                             .Where(a => TITILER_VALID_TYPE
                                    .Contains(a.Value.MediaType?.MediaType)).ToDictionary(a => a.Key, a => a.Value);
            if (overviewAssets.Count == 1)
            {
                return(overviewAssets);
            }

            if (eoStacExtension != null)
            {
                overviewAssets = stacItem.Assets.Where(a =>
                {
                    var bands = a.Value.GetProperty <EoBandObject[]>("eo:bands");
                    if (bands == null)
                    {
                        return(false);
                    }
                    return(bands.Any(band => OVERVIEW_NAMES.ToList().Contains(band.CommonName.ToString())));
                })
                                 .Where(a => TITILER_VALID_TYPE.Contains(a.Value.MediaType?.MediaType))
                                 .ToDictionary(a => a.Key, a => a.Value);
            }
            if (overviewAssets.Count >= 1)
            {
                return(overviewAssets);
            }

            return(new Dictionary <string, StacAsset>());
        }