Skip to content

Commit

Permalink
Extensible raster object
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 20, 2021
1 parent f482c68 commit 7dfa59d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Root fields accessor for Stac Item
- Extensible raster object

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion src/DotNetStac/Extensions/Raster/RasterBandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Stac.Extensions.Raster
/// of the Raster extension
/// </summary>
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class RasterBand
public class RasterBand : IStacPropertiesContainer
{

IDictionary<string, object> properties;
Expand Down Expand Up @@ -104,5 +104,6 @@ public RasterBand()
[JsonExtensionData]
public IDictionary<string, object> Properties { get => properties; set => properties = value; }

public IStacObject StacObjectContainer => null;
}
}
11 changes: 9 additions & 2 deletions src/DotNetStac/StacAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Stac.Converters;
using Newtonsoft.Json;
using System.Net.Mime;
using System.Runtime.Serialization;

namespace Stac
{
Expand Down Expand Up @@ -85,7 +86,7 @@ public static StacAsset CreateMetadataAsset(IStacObject stacObject, Uri uri, Con
internal StacAsset()
{
properties = new Dictionary<string, object>();
Roles = new Collection<string>();
Roles = new SortedSet<string>();
}

/// <summary>
Expand Down Expand Up @@ -157,7 +158,7 @@ public ContentType MediaType
/// </summary>
/// <value></value>
[JsonProperty("roles")]
public Collection<string> Roles
public ICollection<string> Roles
{
get;
private set;
Expand Down Expand Up @@ -236,5 +237,11 @@ public bool ShouldSerializeStacExtensions()
// don't serialize the Manager property if an employee is their own manager
return Roles.Count > 0;
}

[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
Roles = new SortedSet<string>(Roles);
}
}
}
20 changes: 16 additions & 4 deletions src/DotNetStac/StacItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public StacItem(string id,
Links = new ObservableCollection<StacLink>();
(Links as ObservableCollection<StacLink>).CollectionChanged += LinksCollectionChanged;
Assets = new Dictionary<string, StacAsset>();

}

public StacItem(StacItem stacItem) : base(Preconditions.CheckNotNull(stacItem, "stacItem").Geometry,
Expand All @@ -46,7 +46,6 @@ public StacItem(StacItem stacItem) : base(Preconditions.CheckNotNull(stacItem, "
(Links as ObservableCollection<StacLink>).CollectionChanged += LinksCollectionChanged;
this.Assets = new Dictionary<string, StacAsset>(stacItem.Assets);
this.Collection = stacItem.Collection;

}

private void LinksCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -113,7 +112,14 @@ public ICollection<StacLink> Links
/// The id of the STAC Collection this Item references to
/// </summary>
/// <value>gets the collection id</value>
public string Collection { get => Root.GetProperty<string>("collection"); set => Root.SetProperty("collection", value); }
public string Collection
{
get => Root.GetProperty<string>("collection");
set
{
if (value != null) Root.SetProperty("collection", value);
}
}

/// <summary>
/// Item root extended data
Expand All @@ -135,14 +141,15 @@ internal void OnDeserializedMethod(StreamingContext context)
{
asset.ParentStacObject = this;
}
StacExtensions = new SortedSet<string>(StacExtensions);
}

[OnSerializing]
internal void OnSerializingMethod(StreamingContext context)
{
if (BoundingBoxes == null)
BoundingBoxes = this.GetBoundingBoxFromGeometryExtent();
StacExtensions = new SortedSet<string>(StacExtensions);

}

public bool ShouldSerializeStacExtensions()
Expand All @@ -153,5 +160,10 @@ public bool ShouldSerializeStacExtensions()

[JsonIgnore]
public IStacObject StacObjectContainer => this;

public object RasterExtension()
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions src/DotNetStac/StacObjectLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ public override Uri Uri
set;
}

public IStacObject StacObject => stacObject;
}
}

0 comments on commit 7dfa59d

Please sign in to comment.