Skip to content

Commit

Permalink
More helpers for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Nov 9, 2020
1 parent 251129d commit c7c900a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/DotNetStac/Extensions/AssignableStacExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using Newtonsoft.Json.Linq;
using Stac.Item;

Expand Down Expand Up @@ -54,7 +55,9 @@ protected T GetField<T>(string fieldName)
if (@object == null) return default(T);
if (@object is JToken)
return (@object as JToken).ToObject<T>();
return (T)@object;
if (typeof(T).GetTypeInfo().IsEnum)
return (T)Enum.Parse(typeof(T), @object.ToString());
return (T)Convert.ChangeType(@object, typeof(T));
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetStac/Item/StacItem.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Itenso.TimePeriod.ITimePeriod DateTime
}
}
}
return null;
return Itenso.TimePeriod.TimeInterval.Anytime;
}
set
{
Expand Down
1 change: 1 addition & 0 deletions src/DotNetStac/Item/StacItem.Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public StacItem(StacItem stacItem) : this(stacItem.Geometry, stacItem.Properties
this.assets = stacItem.assets;
this.collection = stacItem.collection;
this.sourceUri = stacItem.sourceUri;
this.extensions = stacItem.extensions;
}

[JsonProperty("stac_extensions")]
Expand Down
16 changes: 16 additions & 0 deletions src/DotNetStac/StacExtent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Stac.Item;

namespace Stac
{
Expand All @@ -10,5 +14,17 @@ public class StacExtent

[JsonProperty("temporal")]
public StacTemporalExtent Temporal { get; set; }

public static StacExtent Create(IEnumerable<StacItem> items)
{
return new StacExtent()
{
Spatial = new StacSpatialExtent(items.Min(i => i.GetBoundingBoxFromGeometryExtent()[0]),
items.Min(i => i.GetBoundingBoxFromGeometryExtent()[1]),
items.Max(i => i.GetBoundingBoxFromGeometryExtent()[2]),
items.Max(i => i.GetBoundingBoxFromGeometryExtent()[3])),
Temporal = new StacTemporalExtent(items.Min(i => i.DateTime.Start), items.Max(i => i.DateTime.End))
};
}
}
}

0 comments on commit c7c900a

Please sign in to comment.