From aaace214f6bf7bd8398a4ddfeb73057b9f8ea9f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 31 Oct 2023 15:55:06 +0100 Subject: [PATCH] StacLink clone --- README.md | 4 +- docs/docfx.json | 8 +- docs/index.md | 8 +- docs/{api => lib}/.gitignore | 0 docs/{api => lib}/index.md | 0 docs/toc.yml | 6 +- .../Common/StacAccessorsHelpersTests.cs | 93 +++++++++++++++++++ src/DotNetStac/StacLink.cs | 1 + 8 files changed, 107 insertions(+), 13 deletions(-) rename docs/{api => lib}/.gitignore (100%) rename docs/{api => lib}/index.md (100%) diff --git a/README.md b/README.md index bc61a4e1..431d4e07 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@

-![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=release/1.7.1) +![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=develop) [![NuGet](https://img.shields.io/nuget/vpre/DotNetStac)](https://www.nuget.org/packages/DotNetStac/) -[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/release/1.7.1/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac) +[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/develop/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac) [![Gitter](https://img.shields.io/gitter/room/SpatioTemporal-Asset-Catalog/Lobby?color=yellow)](https://gitter.im/SpatioTemporal-Asset-Catalog/Lobby) [![License](https://img.shields.io/badge/license-AGPL3-blue.svg)](LICENSE) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Terradue/DotNetStac/master?filepath=example.ipynb) diff --git a/docs/docfx.json b/docs/docfx.json index 8c31a08e..ff4db467 100644 --- a/docs/docfx.json +++ b/docs/docfx.json @@ -12,7 +12,7 @@ "src": ".." } ], - "dest": "api", + "dest": "lib", "disableGitFeatures": false, "disableDefaultFilter": false } @@ -21,8 +21,8 @@ "content": [ { "files": [ - "api/**.yml", - "api/index.md" + "lib/**.yml", + "lib/index.md" ] }, { @@ -44,7 +44,7 @@ "overwrite": [ { "files": [ - "apidoc/**.md" + "libdoc/**.md" ], "exclude": [ "obj/**", diff --git a/docs/index.md b/docs/index.md index ba6d564b..068a2b00 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,7 +19,7 @@ In a nutshell, the library allows serialization/desrialization of STAC JSON docu ## Reference API -Looking for the reference API docs, go directly to [https://terradue.github.io/DotNetStac/api/]. +Looking for the reference API docs, go directly to [https://terradue.github.io/DotNetStac/lib/]. ## Getting Started @@ -33,7 +33,7 @@ dotnet add package DotNetStac ### Deserialization of STAC documents -The (de)serialiation methods are wrapped in methods in [class `StacConvert`](https://terradue.github.io/DotNetStac/api/Stac.StacConvert.html) that is the main entry point from/to JSON/.Net. +The (de)serialiation methods are wrapped in methods in [class `StacConvert`](https://terradue.github.io/DotNetStac/lib/Stac.StacConvert.html) that is the main entry point from/to JSON/.Net. Let's start reading a STAC catalog online. Please note that DotNetStac does not provide with data access middleware. You can integrate own data access or you can test the [`Stars` SDK](https://github.com/Terradue/Stars) that provides with integrated functions to manipulate STAC objects and their storage. @@ -63,7 +63,7 @@ Please note the following: * `GetChildrenLinks` and `GetItemLinks` are the recommanded ways to get the links for navigating through the tree. * The previous functions as the rest of the library does not alter the `Uri`s. It is then up to the developer to resolve the relative ones. As in the code, Uri class provides with all the necessary methods to easily join a base Url with a relative one. -* The `StacConvert.Deserialize<>` methods allows to specify the interfaces to ease the deserialization when the STAC type is unknown: [`IStacObject`](https://terradue.github.io/DotNetStac/api/Stac.IStacObject.html) and [`IStacCatalog`](https://terradue.github.io/DotNetStac/api/Stac.IStacCatalog.html). +* The `StacConvert.Deserialize<>` methods allows to specify the interfaces to ease the deserialization when the STAC type is unknown: [`IStacObject`](https://terradue.github.io/DotNetStac/lib/Stac.IStacObject.html) and [`IStacCatalog`](https://terradue.github.io/DotNetStac/lib/Stac.IStacCatalog.html). ```csharp using System.Linq; @@ -281,7 +281,7 @@ using System.Collections.Generic; #### Collection generation from a set of Items -[`StacCollection` class](https://terradue.github.io/DotNetStac/api/Stac.StacCollection.html) has static methods allowing the automatic generation of a collection from a set of `StacItem`. The following code loads the items of [the examples folder from STAC repository](https://github.com/radiantearth/stac-spec/tree/master/examples) and generates the corresponding collection with +[`StacCollection` class](https://terradue.github.io/DotNetStac/lib/Stac.StacCollection.html) has static methods allowing the automatic generation of a collection from a set of `StacItem`. The following code loads the items of [the examples folder from STAC repository](https://github.com/radiantearth/stac-spec/tree/master/examples) and generates the corresponding collection with - **Spatial and temporal extent** from geometry and time merge of the items - **Fields summaries** with stats objects or value sets of the items' fields values diff --git a/docs/api/.gitignore b/docs/lib/.gitignore similarity index 100% rename from docs/api/.gitignore rename to docs/lib/.gitignore diff --git a/docs/api/index.md b/docs/lib/index.md similarity index 100% rename from docs/api/index.md rename to docs/lib/index.md diff --git a/docs/toc.yml b/docs/toc.yml index c06f5abf..cdfbfb59 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -1,5 +1,5 @@ - name: Articles href: articles/ -- name: Api Documentation - href: api/ - homepage: api/index.md +- name: Library Documentation + href: lib/ + homepage: lib/index.md diff --git a/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs b/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs index 6146c2b8..484e15a9 100644 --- a/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs +++ b/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs @@ -3,7 +3,10 @@ // File Name: StacAccessorsHelpersTests.cs using System.Collections.Generic; +using System.Runtime.Serialization; using GeoJSON.Net.Geometry; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Stac.Collection; using Stac.Common; using Xunit; @@ -88,5 +91,95 @@ public void LazyEnumParseTests() Assert.Equal(test3, StacAccessorsHelpers.LazyEnumParse(typeof(Enum3), "Cql2Json")); } + + [Fact] + public void EnumSerializationTest() + { + var coordinates = new[] + { + new List + { + 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(); + + properties.Add("collection", "CS3"); + + StacItem item = new StacItem("CS3-20160503_132130_04", geometry, properties); + + item.SetProperty("disaster:type", DisasterType.Volcano); + + var itemJson = StacConvert.Serialize(item); + + item = StacConvert.Deserialize(itemJson); + + Assert.Equal("volcano", item.GetProperty("disaster:type")); + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum DisasterType + { + + [EnumMember(Value = "earthquake")] + Earthquake, + + [EnumMember(Value = "fire")] + Fire, + + [EnumMember(Value = "flood")] + Flood, + + [EnumMember(Value = "flood_large")] + [System.Obsolete("Use Flood instead")] + FloodLarge, + + [EnumMember(Value = "flood_flash")] + [System.Obsolete("Use Flood instead")] + FloodFlash, + + [EnumMember(Value = "ice")] + Ice, + + [EnumMember(Value = "landslide")] + Landslide, + + [EnumMember(Value = "storm_hurricane")] + StormHurricane, + + [EnumMember(Value = "storm_hurricane_rural")] + [System.Obsolete("Use StormHurricane instead")] + StormHurricaneRural, + + [EnumMember(Value = "storm_hurricane_urban")] + [System.Obsolete("Use StormHurricane instead")] + StormHurricaneUrban, + + [EnumMember(Value = "tsunami")] + Tsunami, + + [EnumMember(Value = "oil_spill")] + OilSpill, + + [EnumMember(Value = "volcano")] + Volcano, + + /// + [EnumMember(Value = "snow_hazard")] + SnowHazard, + + [EnumMember(Value = "explosive_event")] + ExplosiveEvent, + + /// + Other, + } } } diff --git a/src/DotNetStac/StacLink.cs b/src/DotNetStac/StacLink.cs index 71fbe3dd..1e202cd9 100644 --- a/src/DotNetStac/StacLink.cs +++ b/src/DotNetStac/StacLink.cs @@ -67,6 +67,7 @@ public StacLink(StacLink source) this.ContentType = source.ContentType; this.Parent = source.Parent; this.Length = source.Length; + this.AdditionalProperties = source.AdditionalProperties; } ///