public void GetProperty() { 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()); properties.Add("collection", "CS3"); StacItem item = new StacItem("CS3-20160503_132130_04", geometry, properties); item.SetProperty("test", new string[] { "test1", "test2", "test3" }); string json = StacConvert.Serialize(item); ValidateJson(json); item = StacConvert.Deserialize <StacItem>(json); var array = item.GetProperty <string[]>("test"); }
public void SetAssetBands() { var k3CompleteJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G"); var k3MissingBandsJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G_missing_bands"); ValidateJson(k3CompleteJson); ValidateJson(k3MissingBandsJson); StacItem k3MissingBands = StacConvert.Deserialize <StacItem>(k3MissingBandsJson); EoBandObject eoBandObject = new EoBandObject("MS1", EoBandCommonName.blue) { CenterWavelength = 0.485 }; eoBandObject.Properties.Add("scale", 27.62430939226519); eoBandObject.Properties.Add("offset", -22.1416); eoBandObject.SolarIllumination = 2001.0; Assert.NotNull(k3MissingBands.Assets["MS1"]); k3MissingBands.Assets["MS1"].EoExtension().Bands = new EoBandObject[] { eoBandObject }; Assert.Same(k3MissingBands, k3MissingBands.StacObjectContainer); Assert.Same(k3MissingBands, k3MissingBands.Assets.First().Value.StacObjectContainer); Assert.NotNull(k3MissingBands.GetAsset(EoBandCommonName.blue)); Assert.Equal(2001, k3MissingBands.GetBandObject(EoBandCommonName.blue).SolarIllumination); k3MissingBandsJson = JsonConvert.SerializeObject(k3MissingBands); ValidateJson(k3MissingBandsJson); JsonAssert.AreEqual(k3CompleteJson, k3MissingBandsJson); }
public async System.Threading.Tasks.Task SetPropertiesFromFileInfo() { var simpleJson = GetJson("Extensions", "MinimalSample"); ValidateJson(simpleJson); StacItem simpleitem = StacConvert.Deserialize <StacItem>(simpleJson); StacAsset stacAsset = StacAsset.CreateDataAsset(simpleitem, new Uri("file:///srid.csv"), new System.Net.Mime.ContentType("text/csv"), "System reference Ids"); await stacAsset.FileExtension().SetFileExtensionProperties(new System.IO.FileInfo("SRID.csv")); simpleitem.Assets.Add("srid", stacAsset); Assert.Equal <UInt64>(1536937, stacAsset.FileExtension().Size.Value); string actualJson = JsonConvert.SerializeObject(simpleitem); ValidateJson(actualJson); string expectedJson = GetJson("Extensions"); JsonAssert.AreEqual(expectedJson, actualJson); }
void ListChildrensItemsAndAssets(IStacParent catalog, Uri baseUri, string prefix = "", int limit = 2) { // Get children first (sub catalogs and collections) foreach (var childLink in catalog.GetChildrenLinks().Concat(catalog.GetItemLinks())) { Uri childUri = childLink.Uri; if (!childUri.IsAbsoluteUri) { childUri = new Uri(baseUri, childUri.ToString()); } IStacObject child = StacConvert.Deserialize <IStacObject>(httpClient.GetStringAsync(childUri).GetAwaiter().GetResult()); Console.Out.WriteLine(prefix + child.Id + ": " + child.Title); if (child is StacCatalog || child is StacCollection) { ListChildrensItemsAndAssets(child as IStacParent, childUri, prefix + " "); } if (child is StacItem) { foreach (var asset in (child as StacItem).Assets) { Console.Out.WriteLine(prefix + asset.Key + ": *[" + asset.Value.MediaType + "] " + asset.Value.Uri); } } } }
public void UpdateCollection() { var collectionJson = GetJson("Collection", "CanDeserializeSentinel2Sample"); ValidateJson(collectionJson); var collection = StacConvert.Deserialize <StacCollection>(collectionJson); var itemJson = GetJson("Collection", "K3A_20200508102646_28267_00027320_L1G"); ValidateJson(itemJson); var item = StacConvert.Deserialize <StacItem>(itemJson); Dictionary <Uri, StacItem> items = new Dictionary <Uri, StacItem>(); items.Add(new Uri("http://test/test.json"), item); collection.Update(items); var actualJson = StacConvert.Serialize(collection); var expectedJson = GetJson("Collection"); JsonAssert.AreEqual(expectedJson, actualJson); }
public void CanDeserializeMinimalSample() { var json = GetJson("Catalog"); ValidateJson(json); var catalog = StacConvert.Deserialize <StacCatalog>(json); Assert.NotNull(catalog); Assert.Equal(Versions.StacVersionList.Current, catalog.StacVersion); Assert.Empty(catalog.StacExtensions); Assert.Equal("NAIP", catalog.Id); Assert.Equal("Catalog of NAIP Imagery", catalog.Description); Assert.Contains(catalog.Links, link => link.RelationshipType == "self" && link.Uri == new Uri("https://www.fsa.usda.gov/naip/catalog.json")); Assert.Contains(catalog.Links, link => link.RelationshipType == "child" && link.Uri == new Uri("https://www.fsa.usda.gov/naip/30087/catalog.json")); Assert.Contains(catalog.Links, link => link.RelationshipType == "root" && link.Uri == new Uri("https://www.fsa.usda.gov/catalog.json")); var json2 = StacConvert.Serialize(catalog); ValidateJson(json2); JsonAssert.AreEqual(json, json2); }
public void CollectionStacObjectLink() { var simpleJson = GetJson("Collection", "CanDeserializeSentinel2Sample"); ValidateJson(simpleJson); StacCollection simpleCollection = StacConvert.Deserialize <StacCollection>(simpleJson); StacObjectLink stacObjectLink = (StacObjectLink)StacLink.CreateObjectLink(simpleCollection, new Uri("file:///test")); }
public void WrongCommonName() { var json = GetJson("Extensions"); var item = StacConvert.Deserialize <StacItem>(json); Assert.Null(item.Assets["MS2"].EoExtension().Bands[0].CommonName); }
public void CatalogStacObjectLink() { var simpleJson = GetJson("Catalog", "CanDeserializeMinimalSample"); ValidateJson(simpleJson); StacCatalog simpleCollection = StacConvert.Deserialize <StacCatalog>(simpleJson); StacObjectLink stacObjectLink = (StacObjectLink)StacLink.CreateObjectLink(simpleCollection, new Uri("file:///test")); }
//[Fact] public void Deserialize() { Uri catalogUri = new Uri("https://landsat-stac.s3.amazonaws.com/catalog.json"); StacCatalog catalog = StacConvert.Deserialize <StacCatalog>(httpClient.GetStringAsync(catalogUri).GetAwaiter().GetResult()); Console.Out.WriteLine(catalog.Id); Console.Out.WriteLine(catalog.StacVersion); ListChildrensItemsAndAssets(catalog, catalogUri); }
public void CanManageDates() { var json = GetJson("Item"); ValidateJson(json); var item = StacConvert.Deserialize <StacItem>(json); Assert.Equal(item.DateTime, new Itenso.TimePeriod.TimeInterval(DateTime.Parse("2016-05-03T13:22:30Z").ToUniversalTime())); }
public void CalculatePerpendicularBaseline() { var sentinel1Json_1 = GetJson("Item", "S1A_IW_SLC__1SDV_20150305T051937_20150305T052005_004892_006196_ABBB"); var sentinel1Json_2 = GetJson("Item", "S1A_IW_SLC__1SDV_20150317T051938_20150317T052005_005067_0065D5_B405"); StacItem sentinel1Item_1 = StacConvert.Deserialize <StacItem>(sentinel1Json_1); StacItem sentinel1Item_2 = StacConvert.Deserialize <StacItem>(sentinel1Json_2); var baseline = sentinel1Item_1.SatExtension().CalculateBaseline(sentinel1Item_2.SatExtension()); }
public void StacConvertEx() { var simpleJson = GetJson("Exceptions", "MinimalSample"); ValidateJson(simpleJson); Assert.Throws <InvalidCastException>(() => StacConvert.Deserialize <IStacCatalog>(simpleJson)); var errorJson = GetJson("Exceptions", "ErrorSample"); Assert.Throws <InvalidStacDataException>(() => StacConvert.Deserialize <StacItem>(errorJson)); }
public void CanCreateBaseCollectionExample() { var expectedJson = httpClient.GetStringAsync($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/collection.json").GetAwaiter().GetResult(); //TMP expectedJson = expectedJson.Replace("\"proj:epsg\": {\n \"minimum\": 32659,\n \"maximum\": 32659\n }", "\"proj:epsg\":[32659]"); ValidateJson(expectedJson); Dictionary <Uri, StacItem> items = new Dictionary <Uri, StacItem>(); Uri simpleItemUri = new Uri($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/simple-item.json"); items.Add(simpleItemUri, StacConvert.Deserialize <StacItem>(httpClient.GetStringAsync(simpleItemUri).GetAwaiter().GetResult())); items[simpleItemUri].Title = "Simple Item"; Uri coreItemUri = new Uri($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/core-item.json"); string coreItemJson = httpClient.GetStringAsync(coreItemUri).GetAwaiter().GetResult(); coreItemJson = coreItemJson.Replace("cool_sat2", "cool_sat1"); items.Add(coreItemUri, StacConvert.Deserialize <StacItem>(coreItemJson)); Uri extendedItemUri = new Uri($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/extended-item.json"); string extendedItemJson = httpClient.GetStringAsync(extendedItemUri).GetAwaiter().GetResult(); extendedItemJson = extendedItemJson.Replace("cool_sensor_v1", "cool_sensor_v2"); items.Add(extendedItemUri, StacConvert.Deserialize <StacItem>(extendedItemJson)); StacCollection collection = StacCollection.Create("simple-collection", "A simple collection demonstrating core catalog fields with links to a couple of items", items, "CC-BY-4.0", new Uri($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/collection.json"), null); collection.Title = "Simple Example Collection"; collection.Links.Insert(0, StacLink.CreateRootLink(new Uri("./collection.json", UriKind.Relative), StacCollection.MEDIATYPE, "Simple Example Collection")); collection.Links.Add(StacLink.CreateSelfLink(new Uri($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/collection.json"), StacCollection.MEDIATYPE)); collection.Providers.Add(new StacProvider("Remote Data, Inc") { Description = "Producers of awesome spatiotemporal assets", Uri = new Uri("http://remotedata.io") }); collection.Providers[0].Roles.Add(StacProviderRole.producer); collection.Providers[0].Roles.Add(StacProviderRole.processor); var orderedext = collection.StacExtensions.OrderBy(a => a).ToArray(); collection.StacExtensions.Clear(); collection.StacExtensions.AddRange(orderedext); Assert.Equal(Versions.StacVersionList.Current.ToString(), collection.StacVersion.ToString()); string actualJson = StacConvert.Serialize(collection); ValidateJson(actualJson); JsonAssert.AreEqual(expectedJson, actualJson); }
public void LoadRootCatalog() { var json = GetUseCaseJson("catalog.json"); ValidateJson(json); catalog = StacConvert.Deserialize <StacCatalog>(json); Assert.NotNull(catalog); Assert.Equal("sentinel-stac", catalog.Id); }
public void CanDeserializeBaseCatalogExample() { var json = httpClient.GetStringAsync($"https://raw.githubusercontent.com/radiantearth/stac-spec/v{Versions.StacVersionList.Current}/examples/catalog.json").GetAwaiter().GetResult(); StacCatalog catalog = StacConvert.Deserialize <StacCatalog>(json); Assert.NotNull(catalog); Assert.Equal(Versions.StacVersionList.Current.ToString(), catalog.StacVersion.ToString()); string catalog2json = StacConvert.Serialize(catalog); JsonAssert.AreEqual(json, catalog2json); }
public void CanDeserializeS2CogSample() { var json = GetJson("Item"); ValidateJson(json); var item = StacConvert.Deserialize <StacItem>(json); Assert.NotNull(item); Assert.NotNull(item.Properties); Assert.Equal("1.0.0", item.StacVersion); }
public void StacObjectLink() { var simpleJson = GetJson("Exceptions", "MinimalSample"); ValidateJson(simpleJson); StacItem simpleitem = StacConvert.Deserialize <StacItem>(simpleJson); StacObjectLink stacObjectLink = (StacObjectLink)StacLink.CreateObjectLink(simpleitem, new Uri("file:///test")); Assert.Throws <InvalidOperationException>(() => stacObjectLink.Title = "test"); Assert.Throws <InvalidOperationException>(() => stacObjectLink.ContentType = new System.Net.Mime.ContentType("text/plain")); Assert.Equal(simpleitem, stacObjectLink.StacObject); StacLink nullStacLink = null; Assert.Throws <ArgumentNullException>(() => new StacLink(nullStacLink)); }
public void ReadCoordinateSystem() { var k3CompleteJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G"); ValidateJson(k3CompleteJson); StacItem k3Complete = StacConvert.Deserialize <StacItem>(k3CompleteJson); k3Complete.ProjectionExtension().SetCoordinateSystem(4326); Assert.Equal("GEOGCS[\"WGS 84\", DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\", \"7030\"]], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.01745329251994328, AUTHORITY[\"EPSG\", \"9122\"]], AUTHORITY[\"EPSG\", \"4326\"]]", k3Complete.ProjectionExtension().Wkt2); ValidateJson(StacConvert.Serialize(k3Complete)); }
public void LoadRootChildren() { IEnumerable <IStacObject> children = catalog.GetChildrenLinks() .Select(l => { Uri childUri = new Uri(GetUseCaseFileUri("catalog.json"), l.Uri.OriginalString); var childJson = File.ReadAllText(childUri.ToString().Replace("file://", "")); ValidateJson(childJson); return(StacConvert.Deserialize <IStacObject>(childJson)); }); Assert.Equal(1, children.Count()); Assert.IsAssignableFrom <StacCollection>(children.First()); }
// [Fact] public void CanDeserializeResto() { var json = GetJson("Extensions"); ValidateJson(json); var stacObject = StacConvert.Deserialize <IStacObject>(json); Assert.IsAssignableFrom <ItemCollection>(stacObject); ItemCollection itemCollection = stacObject as ItemCollection; Assert.Equal("1.0.0", itemCollection.StacVersion); Assert.NotEmpty(itemCollection.Features); }
public void SetCoordinateSystem() { var k3CompleteJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G"); ValidateJson(k3CompleteJson); StacItem k3Complete = StacConvert.Deserialize <StacItem>(k3CompleteJson); k3Complete.ProjectionExtension().SetCoordinateSystem(ProjNet.CoordinateSystems.GeocentricCoordinateSystem.WGS84); string k3newProjJson = StacConvert.Serialize(k3Complete); var expectedJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G_newproj"); ValidateJson(expectedJson); JsonAssert.AreEqual(expectedJson, k3newProjJson); }
public void ItemProviders() { var simpleJson = GetJson("Item", "ItemProvidersIn"); ValidateJson(simpleJson); StacItem simpleItem = StacConvert.Deserialize <StacItem>(simpleJson); simpleItem.Providers.Add(new StacProvider("ESA", new StacProviderRole[] { StacProviderRole.licensor })); Assert.Contains <string, object>("providers", simpleItem.Properties); simpleItem.Providers.RemoveAt(0); Assert.DoesNotContain <string, object>("providers", simpleItem.Properties); var newJson = StacConvert.Serialize(simpleItem); ValidateJson(newJson); }
private static async Task <IStacObject> CreateStacObject(this StacLink stacLink, Uri baseUri = null, ICredentials credentials = null) { if (stacLink is StacObjectLink) { return((stacLink as StacObjectLink).StacObject); } Uri linkUri = stacLink.Uri; if (!linkUri.IsAbsoluteUri) { if (baseUri == null) { throw new RoutingException(string.Format("relative route without base Url : {0}", linkUri)); } linkUri = new Uri(baseUri, linkUri); } var webRoute = WebRoute.Create(linkUri, stacLink.Length, credentials); return(StacConvert.Deserialize <IStacObject>(await webRoute.GetStreamAsync())); }
public void SetVersion() { var simpleJson = GetJson("Extensions", "MinimalSample"); ValidateJson(simpleJson); StacItem simpleitem = StacConvert.Deserialize <StacItem>(simpleJson); simpleitem.VersionExtension().Version = "1"; Assert.Equal("1", simpleitem.Properties["version"]); string actualJson = JsonConvert.SerializeObject(simpleitem); ValidateJson(actualJson); string expectedJson = GetJson("Extensions"); JsonAssert.AreEqual(expectedJson, actualJson); }
public void CanDeserializeMinimalSample() { var json = GetJson("Item"); ValidateJson(json); var item = StacConvert.Deserialize <StacItem>(json); Assert.NotNull(item); Assert.NotNull(item.Properties); Assert.Equal("1.0.0", item.StacVersion); Assert.Empty(item.StacExtensions); Assert.Equal(GeoJSONObjectType.Feature, item.Type); Assert.Equal("CS3-20160503_132130_04", item.Id); Assert.IsType <Polygon>(item.Geometry); Assert.Equal(new double[4] { -122.59750209, 37.48803556, -122.2880486, 37.613537207 }, item.BoundingBoxes); Assert.Equal("CS3", item.Collection); Assert.Equal(DateTime.Parse("2016-05-03T13:21:30.040Z").ToUniversalTime(), item.Properties["datetime"]); Assert.Contains <StacLink>(item.Links, l => l.RelationshipType == "self" && l.Uri.ToString() == "http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json"); Assert.Contains <StacLink>(item.Links, l => l.RelationshipType == "collection" && l.Uri.ToString() == "http://cool-sat.com/catalog.json"); Assert.Equal("relative-path/to/analytic.tif", item.Assets["analytic"].Uri.ToString()); Assert.Equal("4-Band Analytic", item.Assets["analytic"].Title); Assert.Equal("http://cool-sat.com/catalog/CS3-20160503_132130_04/thumbnail.png", item.Assets["thumbnail"].Uri.ToString()); Assert.Equal("Thumbnail", item.Assets["thumbnail"].Title); Assert.Contains("thumbnail", item.Assets["thumbnail"].Roles); }
public void CanDeserializeSentinel2Sample() { var json = GetJson("Collection"); ValidateJson(json); byte[] byteArray = Encoding.ASCII.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); var item = StacConvert.Deserialize <StacCollection>(stream); Assert.NotNull(item); Assert.NotNull(item.Summaries); Assert.Equal("1.0.0", item.StacVersion); Assert.Empty(item.StacExtensions); Assert.NotEmpty(item.Summaries); Assert.True(item.Summaries.ContainsKey("datetime")); Assert.True(item.Summaries.ContainsKey("platform")); Assert.True(item.Summaries.ContainsKey("constellation")); Assert.True(item.Summaries.ContainsKey("view:off_nadir")); Assert.True(item.Summaries.ContainsKey("eo:bands")); Assert.IsType <StacSummaryRangeObject <DateTime> >(item.Summaries["datetime"]); Assert.Equal <DateTime>(DateTime.Parse("2015-06-23T00:00:00Z").ToUniversalTime(), (item.Summaries["datetime"] as StacSummaryRangeObject <DateTime>).Min); Assert.Equal <long>(32601, (item.Summaries["proj:epsg"] as StacSummaryValueSet <long>).Min()); Assert.Equal <long>(32660, (item.Summaries["proj:epsg"] as StacSummaryValueSet <long>).Max()); Assert.Equal <long>(60, (item.Summaries["proj:epsg"] as StacSummaryValueSet <long>).Count); Assert.Equal(13, item.Summaries["eo:bands"].LongCount()); Assert.Equal("B1", item.Summaries["eo:bands"][0]["name"]); Assert.Equal(4.439, item.Summaries["eo:bands"][0]["center_wavelength"]); Assert.Equal(2, item.Summaries["view:sun_elevation"].LongCount()); }
public void CatalogClone() { var simpleJson = GetJson("Catalog", "CanDeserializeMinimalSample"); ValidateJson(simpleJson); StacCatalog simpleCollection = StacConvert.Deserialize <StacCatalog>(simpleJson); StacCatalog simpleCollectionClone = new StacCatalog(simpleCollection); var clonedJson = JsonConvert.SerializeObject(simpleCollectionClone); ValidateJson(clonedJson); JsonAssert.AreEqual(simpleJson, clonedJson); simpleCollectionClone = (StacCatalog)simpleCollection.Clone(); clonedJson = JsonConvert.SerializeObject(simpleCollectionClone); ValidateJson(clonedJson); JsonAssert.AreEqual(simpleJson, clonedJson); }
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()); }
public void CollectionClone() { var simpleJson = GetJson("Collection"); ValidateJson(simpleJson); StacCollection simpleCollection = StacConvert.Deserialize <StacCollection>(simpleJson); StacCollection simpleCollectionClone = new StacCollection(simpleCollection); var clonedJson = StacConvert.Serialize(simpleCollectionClone); ValidateJson(clonedJson); JsonAssert.AreEqual(simpleJson, clonedJson); simpleCollectionClone = (StacCollection)simpleCollection.Clone(); clonedJson = StacConvert.Serialize(simpleCollectionClone); ValidateJson(clonedJson); JsonAssert.AreEqual(simpleJson, clonedJson); }