Skip to content

Commit

Permalink
More properties and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Jun 23, 2020
1 parent 3efbf55 commit d7b2e67
Show file tree
Hide file tree
Showing 9 changed files with 801 additions and 19 deletions.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
DotNetStac
[![Build Status](https://travis-ci.com/Terradue/DotNetStac.svg?branch=develop)](https://travis-ci.com/Terradue/DotNetStac)

# DotNetStac
.Net library for working with any SpatioTemporal Asset Catalog (STAC)

18 changes: 17 additions & 1 deletion src/DotNetStac.Test/Collection/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,28 @@ public void CanSerializeSentinel2Sample()
StacCollection collection = new StacCollection("COPERNICUS/S2",
"Sentinel-2 is a wide-swath, high-resolution, multi-spectral\nimaging mission supporting Copernicus Land Monitoring studies,\nincluding the monitoring of vegetation, soil and water cover,\nas well as observation of inland waterways and coastal areas.\n\nThe Sentinel-2 data contain 13 UINT16 spectral bands representing\nTOA reflectance scaled by 10000. See the [Sentinel-2 User Handbook](https://sentinel.esa.int/documents/247904/685211/Sentinel-2_User_Handbook)\nfor details. In addition, three QA bands are present where one\n(QA60) is a bitmask band with cloud mask information. For more\ndetails, [see the full explanation of how cloud masks are computed.](https://sentinel.esa.int/web/sentinel/technical-guides/sentinel-2-msi/level-1c/cloud-masks)\n\nEach Sentinel-2 product (zip archive) may contain multiple\ngranules. Each granule becomes a separate Earth Engine asset.\nEE asset ids for Sentinel-2 assets have the following format:\nCOPERNICUS/S2/20151128T002653_20151128T102149_T56MNN. Here the\nfirst numeric part represents the sensing date and time, the\nsecond numeric part represents the product generation date and\ntime, and the final 6-character string is a unique granule identifier\nindicating its UTM grid reference (see [MGRS](https://en.wikipedia.org/wiki/Military_Grid_Reference_System)).\n\nFor more details on Sentinel-2 radiometric resoltuon, [see this page](https://earth.esa.int/web/sentinel/user-guides/sentinel-2-msi/resolutions/radiometric).\n",
extent);


collection.Title = "Sentinel-2 MSI: MultiSpectral Instrument, Level-1C";

collection.Links.Add(StacLink.CreateSelfLink(new Uri("https://storage.cloud.google.com/earthengine-test/catalog/COPERNICUS_S2.json")));
collection.Links.Add(StacLink.CreateParentLink(new Uri("https://storage.cloud.google.com/earthengine-test/catalog/catalog.json")));
collection.Links.Add(StacLink.CreateRootLink(new Uri("https://storage.cloud.google.com/earthengine-test/catalog/catalog.json")));
collection.Links.Add(new StacLink(new Uri("https://scihub.copernicus.eu/twiki/pub/SciHubWebPortal/TermsConditions/Sentinel_Data_Terms_and_Conditions.pdf"), "license", "Legal notice on the use of Copernicus Sentinel Data and Service Information", null));

collection.Keywords = new System.Collections.ObjectModel.Collection<string>(new string[] {
"copernicus",
"esa",
"eu",
"msi",
"radiance",
"sentinel"});

collection.Providers = new System.Collections.ObjectModel.Collection<StacProvider>(
new StacProvider[]{new StacProvider("European Union/ESA/Copernicus"){
Roles = new List<StacProviderRole>() { StacProviderRole.producer, StacProviderRole.licensor},
Uri = new Uri("https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi")
}});

var actualJson = JsonConvert.SerializeObject(collection);

Console.WriteLine(actualJson);
Expand Down
32 changes: 31 additions & 1 deletion src/DotNetStac.Test/JsonAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,40 @@ private static JObject SortProperties(this JObject jObject)
{
value = value.SortProperties();
result.Add(property.Name, value);
continue;
}

var avalues = property.Value as JArray;

if (avalues != null)
{
avalues = avalues.SortProperties();
result.Add(property.Name, avalues);
continue;
}

result.Add(property.Name, property.Value);
}

return result;
}

private static JArray SortProperties(this JArray jArray)
{
var result = new JArray();

foreach (var item in jArray)
{
var value = item as JObject;

if (value != null)
{
value = value.SortProperties();
result.Add(value);
}
else
{
result.Add(property.Name, property.Value);
result.Add(item);
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/DotNetStac/Catalog/StacCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class StacCatalog : IStacObject
private Collection<IStacExtension> extensions;

private string description;
private Collection<string> keywords;

private string title;

[JsonConstructor]
public StacCatalog(string id, string description, IEnumerable<StacLink> links = null)
Expand Down Expand Up @@ -80,6 +83,21 @@ public Collection<StacLink> Links
}
}

[JsonProperty("keywords", DefaultValueHandling = DefaultValueHandling.Ignore)]
public Collection<string> Keywords
{
get
{
if (keywords == null)
keywords = new Collection<string>();
return keywords;
}
set
{
keywords = value;
}
}

[JsonProperty("description")]
public string Description
{
Expand All @@ -95,5 +113,7 @@ public string Description

[JsonProperty("id")]
public string Id => id;

public string Title { get => title; set => title = value; }
}
}
18 changes: 16 additions & 2 deletions src/DotNetStac/Collection/StacCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ namespace Stac.Collection
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class StacCollection : StacCatalog, IStacObject
{
private readonly string license;
private string license;
private StacExtent extent;
private Dictionary<string, IStacSummaryItem> summaries;

private Collection<StacProvider> providers;

[JsonConstructor]
public StacCollection(string id, string description, StacExtent extent, IEnumerable<StacLink> links = null, string license = "proprietary"):
public StacCollection(string id, string description, StacExtent extent, IEnumerable<StacLink> links = null, string license = "proprietary") :
base(id, description, links)
{
this.license = license;
Expand All @@ -44,5 +46,17 @@ public Dictionary<string, IStacSummaryItem> Summaries
}
}

[JsonProperty("license")]
public string License { get => license; set => license = value; }

[JsonProperty("providers")]
public Collection<StacProvider> Providers
{
get { return providers; }
set
{
providers = value;
}
}
}
}
35 changes: 35 additions & 0 deletions src/DotNetStac/Collection/StacProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Stac.Collection
{
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class StacProvider
{
private string name;

private string description;

private List<StacProviderRole> roles;
private Uri uri;

public StacProvider(string name)
{
this.name = name;
}

[JsonProperty("name")]
public string Name { get => name; set => name = value; }

[JsonProperty("description")]
public string Description { get => description; set => description = value; }

[JsonProperty("roles")]
public List<StacProviderRole> Roles { get => roles; set => roles = value; }

[JsonProperty("url")]
public Uri Uri { get => uri; set => uri = value; }
}
}
15 changes: 15 additions & 0 deletions src/DotNetStac/Collection/StacProviderRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Stac.Collection
{
[JsonConverter(typeof(StringEnumConverter))]
public enum StacProviderRole
{
licensor,
producer,
processor,
host

}
}
15 changes: 1 addition & 14 deletions src/DotNetStac/StacLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static StacLink CreateAlternateLink(Uri uri, string mediaType = null)

#endregion

Uri base_uri, href;
Uri href;
string rel, title, type;

public StacLink()
Expand All @@ -65,25 +65,12 @@ public StacLink(StacLink source)
{
if (source == null)
throw new ArgumentNullException("source");
base_uri = source.base_uri;
href = source.href;
rel = source.rel;
title = source.title;
type = source.type;
}

[JsonIgnore]
public Uri BaseUri
{
get { return base_uri; }
set
{
if (value != null && !value.IsAbsoluteUri)
throw new ArgumentException("Base URI must not be relative");
base_uri = value;
}
}

[JsonProperty("type")]
public string MediaType
{
Expand Down

0 comments on commit d7b2e67

Please sign in to comment.