Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 20, 2021
1 parent c8c3a32 commit f482c68
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 45 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

### Added

- Root fields accessor for Stac Item

### Fixed

- gsd as double
- null value handling (e.g. proj:epsg)
- ObservationDirection as enum

### Changed

## [v0.8.0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"stac_version": "1.0.0-rc.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/processing/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/processing/v1.0.0/schema.json"
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"stac_version": "1.0.0-rc.4",
"links": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"stac_version": "1.0.0-rc.4",
Expand Down Expand Up @@ -181,8 +180,6 @@
"description": "dummy",
"eo:cloud_cover": 0.0,
"sat:absolute_orbit": 28267,
"proj:epsg": 32638,
"proj:wkt2": "PROJCS[\"WGS 84 / UTM zone 38N\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\", \"7030\"]], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.017453292519943295, AUTHORITY[\"EPSG\", \"9102\"]], AUTHORITY[\"EPSG\", \"4326\"]], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], PROJECTION[\"UTM38N\", AUTHORITY[\"EPSG\", \"32638\"]], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 45], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], AUTHORITY[\"EPSG\", \"32638\"], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]]",
"view:off_nadir": 0.0,
"view:incidence_angle": 2.140217373,
"view:azimuth": 82.308110583,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"stac_version": "1.0.0-rc.4",
Expand Down Expand Up @@ -181,7 +181,7 @@
"description": "dummy",
"eo:cloud_cover": 0.0,
"sat:absolute_orbit": 28267,
"proj:epsg": 32638,
"proj:epsg": null,
"proj:wkt2": "GEOCCS[\"WGS84 Geocentric\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\", \"7030\"]], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"X\", OTHER], AXIS[\"Y\", OTHER], AXIS[\"Z\", OTHER]]",
"view:off_nadir": 0.0,
"view:incidence_angle": 2.140217373,
Expand Down
1 change: 1 addition & 0 deletions src/DotNetStac/Common/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Stac.Common
/// <summary>
/// Statistics Object
/// </summary>
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class Statistics
{
private IDictionary<string, object> properties;
Expand Down
17 changes: 1 addition & 16 deletions src/DotNetStac/Extensions/Eo/EoBandCommonName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,21 @@ namespace Stac.Extensions.Eo
/// </summary>
public enum EoBandCommonName
{
unknow,
coastal,
blue,
green,
red,
yellow,
pan,
rededge,
rededge70,
rededge74,
rededge76,
rededge78,
nir,
nir08,
nir09,
swir12,
cirrus,
swir16,
swir155,
swir165,
swir173,
swir22,
swir215,
swir220,
swir225,
swir23,
swir37,
lwir,
lwir11,
lwir12,
alpha
lwir12
}
}
11 changes: 10 additions & 1 deletion src/DotNetStac/Extensions/Eo/EoStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ public double CloudCover
public EoBandObject[] Bands
{
get { return StacPropertiesContainer.GetProperty<EoBandObject[]>(BandsField); }
set { StacPropertiesContainer.SetProperty(BandsField, value); DeclareStacExtension(); }
set
{
if (value == null || value.Count() == 0)
StacPropertiesContainer.RemoveProperty(BandsField);
else
{
StacPropertiesContainer.SetProperty(BandsField, value);
DeclareStacExtension();
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public void SetCoordinateSystem(CoordinateSystem coordinateSystem)
{
if (coordinateSystem.AuthorityCode > 0)
Epsg = coordinateSystem.AuthorityCode;
else
Epsg = null;
Wkt2 = coordinateSystem.WKT;
}

Expand Down
8 changes: 4 additions & 4 deletions src/DotNetStac/Extensions/Raster/RasterBandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class RasterBand

IDictionary<string, object> properties;
private double? nodata;
private RasterSampling sampling;
private DataType dataType;
private RasterSampling? sampling;
private DataType? dataType;
private string unit;
private double? scale;
private double? offset;
Expand All @@ -41,15 +41,15 @@ public RasterBand()
/// </summary>
[JsonProperty("sampling")]
[JsonConverter(typeof(StringEnumConverter))]
public RasterSampling Sampling { get => sampling; set => sampling = value; }
public RasterSampling? Sampling { get => sampling; set => sampling = value; }

/// <summary>
/// The data type of the band.
/// </summary>
/// <value></value>
[JsonProperty("data_type")]
[JsonConverter(typeof(StringEnumConverter))]
public DataType DataType { get => dataType; set => dataType = value; }
public DataType? DataType { get => dataType; set => dataType = value; }

/// <summary>
/// The actual number of bits used for this band.
Expand Down
1 change: 1 addition & 0 deletions src/DotNetStac/Extensions/Raster/RasterHistogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Stac.Extensions.Raster
/// <summary>
/// The histogram object provides with distribution of pixel values in the band. Those values are sampled in buckets.
/// </summary>
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class RasterHistogram
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetStac/Extensions/Raster/RasterStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class RasterStacExtensionExtensions
/// <summary>
/// Initilize a EoStacExtension class from a STAC asset
/// </summary>
public static RasterStacExtension RasterStacExtension(this StacAsset stacAsset)
public static RasterStacExtension RasterExtension(this StacAsset stacAsset)
{
return new RasterStacExtension(stacAsset);
}
Expand Down
21 changes: 21 additions & 0 deletions src/DotNetStac/Extensions/Sar/ObservationDirection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Stac.Extensions.Sar
{
/// <summary>
/// Antenna obervation direction
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ObservationDirection
{
/// left
[EnumMember(Value = "left")]
Left,

/// right
[EnumMember(Value = "right")]
Right
}
}
4 changes: 2 additions & 2 deletions src/DotNetStac/Extensions/Sar/SarStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public double LooksEquivalentNumber
set { StacPropertiesContainer.SetProperty(LooksEquivalentNumberField, value); DeclareStacExtension(); }
}

public string ObservationDirection
public ObservationDirection? ObservationDirection
{
get { return StacPropertiesContainer.GetProperty<string>(ObservationDirectionField); }
get { return StacPropertiesContainer.GetProperty<ObservationDirection?>(ObservationDirectionField); }
set { StacPropertiesContainer.SetProperty(ObservationDirectionField, value); DeclareStacExtension(); }
}

Expand Down
10 changes: 10 additions & 0 deletions src/DotNetStac/StacAccessorsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public static T GetProperty<T>(this IDictionary<string, object> properties, stri
return (T)Convert.ChangeType(@object, typeof(T));
}

public static void RemoveProperty(this IStacPropertiesContainer propertiesContainer, string key)
{
propertiesContainer.Properties.RemoveProperty(key);
}

public static void RemoveProperty(this IDictionary<string, object> properties, string key)
{
properties.Remove(key);
}

public static IEnumerable<StacLink> GetChildrenLinks(this IStacParent stacCatalog)
{
return stacCatalog.Links.Where(l => l.RelationshipType == "child");
Expand Down
1 change: 1 addition & 0 deletions src/DotNetStac/StacCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ internal void OnDeserializedMethod(StreamingContext context)
{
link.Parent = this;
}
StacExtensions = new SortedSet<string>(StacExtensions);
}

public bool ShouldSerializeSummaries()
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetStac/StacCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Stac
/// <summary>
/// STAC Collection Object implementing STAC Collection spec (https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md)
/// </summary>
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class StacCollection : IStacObject, IStacParent, IStacCatalog
{
public const string MEDIATYPE = "application/json";
Expand Down Expand Up @@ -167,6 +166,7 @@ internal void OnDeserializedMethod(StreamingContext context)
{
link.Parent = this;
}
StacExtensions = new SortedSet<string>(StacExtensions);
}

#pragma warning disable 1591
Expand Down
10 changes: 6 additions & 4 deletions src/DotNetStac/StacCommonMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ public string Mission
}
}

public int Gsd
public double? Gsd
{
get
{
return stacPropertiesContainer.GetProperty<int>("gsd");
return stacPropertiesContainer.GetProperty<double>("gsd");
}
set
{
stacPropertiesContainer.SetProperty("gsd", value);
if (value == 0) stacPropertiesContainer.RemoveProperty("gsd");
else
stacPropertiesContainer.SetProperty("gsd", value);
}
}

Expand Down Expand Up @@ -148,7 +150,7 @@ public Itenso.TimePeriod.ITimePeriod DateTime
return new Itenso.TimePeriod.TimeInterval((DateTime)stacPropertiesContainer.Properties["start_datetime"],
(DateTime)stacPropertiesContainer.Properties["end_datetime"]);
throw new FormatException(string.Format("start_datetime and/or end_datetime are not a valid: {0}", e.Message), e);
}
}
throw new FormatException(string.Format("datetime is not a valid", e.Message), e);
}
}
Expand Down
Loading

0 comments on commit f482c68

Please sign in to comment.