Skip to content

Commit

Permalink
overhaul WIP #3
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Mar 30, 2021
1 parent 8ded3dd commit 8092322
Show file tree
Hide file tree
Showing 44 changed files with 545 additions and 858 deletions.
1 change: 0 additions & 1 deletion src/DotNetStac.Test/DotNetStac.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="GeoJSON.Net" Version="1.2.19"/>
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DotNetStac\DotNetStac.csproj"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Stac.Item;

namespace Stac
namespace Stac.Collection
{
[JsonObject]
public class StacExtent
Expand All @@ -15,7 +13,7 @@ public class StacExtent
[JsonProperty("temporal")]
public StacTemporalExtent Temporal { get; set; }

public static StacExtent Create(IEnumerable<IStacItem> items)
public static StacExtent Create(IEnumerable<StacItem> items)
{
return new StacExtent()
{
Expand Down
31 changes: 31 additions & 0 deletions src/DotNetStac/Converters/StacExtensionsConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Stac.Collection;
using Stac.Extensions;
using Stac.Extensions;

namespace Stac.Converters
{
internal class StacExtensionsConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(IEnumerable<string>));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
IEnumerable<string> extensions = serializer.Deserialize<IEnumerable<string>>(reader);

return new StacExtensions(extensions);
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Dictionary<string, IStacSummaryItem> summaries = (Dictionary<string, IStacSummaryItem>)value;

serializer.Serialize(writer, summaries.ToDictionary(k => k.Key, k => k.Value.AsJToken));
}
}
}
4 changes: 3 additions & 1 deletion src/DotNetStac/DotNetStac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="2.0.2"/>
<PackageReference Include="GeoJSON.Net" Version="1.2.19"/>
<PackageReference Include="TimePeriodLibrary.NET" Version="2.1.1"/>
<PackageReference Include="System.Net.Http" Version="4.3.4"/>
<PackageReference Include="MathNet.Numerics" Version="4.12.0"/>
<PackageReference Include="ProjNet" Version="2.0.0"/>
<PackageReference Include="semver" Version="2.0.6"/>
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14"/>
<PackageReference Include="System.Reflection" Version="4.3.0"/>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0"/>
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
Expand Down
25 changes: 25 additions & 0 deletions src/DotNetStac/Exceptions/DuplicateKeyException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace Stac.Extensions
{
[Serializable]
internal class DuplicateKeyException : Exception
{
public DuplicateKeyException()
{
}

public DuplicateKeyException(string message) : base(message)
{
}

public DuplicateKeyException(string message, Exception innerException) : base(message, innerException)
{
}

protected DuplicateKeyException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.Serialization;

namespace Stac.Extensions
namespace Stac.Exceptions
{
[Serializable]
public class ExtensionNotAssignedException : Exception
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetStac/Exceptions/InvalidStacDataException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.Serialization;

namespace Stac
namespace Stac.Exceptions
{
[Serializable]
internal class InvalidStacDataException : Exception
Expand Down
25 changes: 25 additions & 0 deletions src/DotNetStac/Exceptions/InvalidStacSchemaException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace Stac.Exceptions
{
[Serializable]
internal class InvalidStacSchemaException : Exception
{
public InvalidStacSchemaException()
{
}

public InvalidStacSchemaException(string message) : base(message)
{
}

public InvalidStacSchemaException(string message, Exception innerException) : base(message, innerException)
{
}

protected InvalidStacSchemaException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
80 changes: 0 additions & 80 deletions src/DotNetStac/Extensions/AssignableStacExtension.cs

This file was deleted.

12 changes: 12 additions & 0 deletions src/DotNetStac/Extensions/DummyStacExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Stac.Extensions
{
internal class DummyStacExtension : IStacExtension
{
public DummyStacExtension(string identifier)
{
Identifier = identifier;
}

public string Identifier { get; private set; }
}
}
60 changes: 25 additions & 35 deletions src/DotNetStac/Extensions/Eo/EoStacExtension.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Stac;
using Stac.Extensions;
using Stac.Item;

namespace Stac.Extensions.Eo
{
public class EoStacExtension : AssignableStacExtension, IStacExtension
public class EoStacExtension : StacPropertiesContainerExtension, IStacExtension
{
private static IDictionary<string, Type> itemFields;

public const string Prefix = "eo";
public const string BandsField = "bands";
public const string CloudCoverField = "cloud_cover";
public const string JsonSchemaUrl = "https://stac-extensions.github.io/eo/v1.0.0/schema.json";
public const string BandsField = "eo:bands";
public const string CloudCoverField = "eo:cloud_cover";

public double CloudCover
{
get { return base.GetField<double>(CloudCoverField); }
set { base.SetField(CloudCoverField, value); }
}

public EoStacExtension(IStacObject stacObject) : base(Prefix, stacObject)
public EoStacExtension(IStacPropertiesContainer stacpropertiesContainer) : base(JsonSchemaUrl, stacpropertiesContainer)
{
itemFields = new Dictionary<string, Type>();
itemFields.Add(BandsField, typeof(EoBandObject[]) );
itemFields.Add(CloudCoverField, typeof(double) );
}

public EoStacExtension(StacAsset stacAsset) : base(Prefix, stacAsset)
public double CloudCover
{
get { return StacPropertiesContainer.GetProperty<double>(CloudCoverField); }
set { StacPropertiesContainer.SetProperty(CloudCoverField, value); }
}

public EoBandObject[] Bands
{
get { return base.GetField<EoBandObject[]>(BandsField); }
set { base.SetField(BandsField, value); }
get { return StacPropertiesContainer.GetProperty<EoBandObject[]>(BandsField); }
set { StacPropertiesContainer.SetProperty(BandsField, value); }
}

public EoBandObject[] GetAssetBandObjects(StacAsset stacAsset)
public override IDictionary<string, Type> ItemFields => itemFields;
}

public static class EoStacExtensionExtensions
{
public static EoStacExtension EoExtension(this StacItem stacItem)
{
string key = Id + ":" + BandsField;
if (stacAsset.Properties.ContainsKey(key))
return stacAsset.GetProperty<EoBandObject[]>(key);
return null;
return new EoStacExtension(stacItem);
}

public StacAsset GetAsset(EoBandCommonName commonName)
public static EoStacExtension EoExtension(this StacAsset stacAsset)
{
StacItem item = null;
try { item = StacObject as StacItem; }
catch { }
if (item != null)
return item.Assets.Values.FirstOrDefault(a => GetAssetBandObjects(a).Any(b => b.CommonName == commonName));
return null;
return new EoStacExtension(stacAsset);
}

public void SetAssetBandObjects(StacAsset stacAsset, EoBandObject[] eoBandObjects)
public static StacAsset GetAsset(this StacItem stacItem, EoBandCommonName commonName)
{
string key = Id + ":" + BandsField;
if (stacAsset.Properties.ContainsKey(key))
stacAsset.Properties.Remove(key);
stacAsset.Properties.Add(key, eoBandObjects);
return stacItem.Assets.Values.FirstOrDefault(a => a.EoExtension().Bands.Any(b => b.CommonName == commonName));
}
}
}
8 changes: 0 additions & 8 deletions src/DotNetStac/Extensions/Eo/EoStacExtensionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Stac;
using Stac.Extensions;
using Stac.Item;

namespace Stac.Extensions.Eo
{
public static class EoStacExtensionExtensions
Expand Down
8 changes: 4 additions & 4 deletions src/DotNetStac/Extensions/GenericStacExtension.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using Stac.Item;
using Newtonsoft.Json.Schema;

namespace Stac.Extensions
{
public class GenericStacExtension : AssignableStacExtension
public class GenericStacExtension : StacPropertiesContainerExtension
{
public GenericStacExtension(string prefix, IStacObject stacObject) : base(prefix, stacObject)
public GenericStacExtension(JSchema jsonSchema, string fieldNamePrefix) : base(jsonSchema, fieldNamePrefix)
{
}

// TODO helpers to dicover automatically the fields
}
}
5 changes: 3 additions & 2 deletions src/DotNetStac/Extensions/IStacExtension.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Stac.Item;
using System;
using System.Collections.Generic;

namespace Stac.Extensions
{
public interface IStacExtension
{
string Id { get; }
string Identifier { get; }

}
}
6 changes: 6 additions & 0 deletions src/DotNetStac/Extensions/ITypeStacExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Stac.Extensions
{
internal interface ITypeStacExtension
{
}
}
Loading

0 comments on commit 8092322

Please sign in to comment.