-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ded3dd
commit 8092322
Showing
44 changed files
with
545 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tensions/ExtensionNotAssignedException.cs → ...ceptions/ExtensionNotAssignedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Stac.Extensions | ||
{ | ||
internal interface ITypeStacExtension | ||
{ | ||
} | ||
} |
Oops, something went wrong.