From e8b1aaac6276e1d14a0aaa7d18fb343acec6cb73 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Mon, 12 Dec 2022 16:15:25 +0100 Subject: [PATCH 1/2] fix stac extent creation with null geometries and infinite date --- README.md | 4 ++-- src/DotNetStac.Test/Item/ItemTests.cs | 3 +++ src/DotNetStac/Collection/StacExtent.cs | 7 ++++++- src/DotNetStac/StacGeometryHelpers.cs | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cdf92a68..03dc250e 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@

-![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=master) +![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=hotfix/1.6.5) [![NuGet](https://img.shields.io/nuget/vpre/DotNetStac)](https://www.nuget.org/packages/DotNetStac/) -[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/master/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac) +[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/hotfix/1.6.5/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac) [![Gitter](https://img.shields.io/gitter/room/SpatioTemporal-Asset-Catalog/Lobby?color=yellow)](https://gitter.im/SpatioTemporal-Asset-Catalog/Lobby) [![License](https://img.shields.io/badge/license-AGPL3-blue.svg)](LICENSE) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Terradue/DotNetStac/master?filepath=example.ipynb) diff --git a/src/DotNetStac.Test/Item/ItemTests.cs b/src/DotNetStac.Test/Item/ItemTests.cs index dcf60ff1..79c634a1 100644 --- a/src/DotNetStac.Test/Item/ItemTests.cs +++ b/src/DotNetStac.Test/Item/ItemTests.cs @@ -5,6 +5,7 @@ using GeoJSON.Net.Geometry; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Stac.Collection; using Stac.Exceptions; using Xunit; @@ -464,6 +465,8 @@ public void EmptyGeometry() Assert.NotNull(token.Children().FirstOrDefault(c => c.Path == "geometry")); + var extent = StacExtent.Create(new List() { item }); + } [Fact] diff --git a/src/DotNetStac/Collection/StacExtent.cs b/src/DotNetStac/Collection/StacExtent.cs index 2e09ec34..77ca75b3 100644 --- a/src/DotNetStac/Collection/StacExtent.cs +++ b/src/DotNetStac/Collection/StacExtent.cs @@ -55,12 +55,17 @@ public StacExtent(StacExtent extent) /// A that represents the spatio-temporal extent of all the items together public static StacExtent Create(IEnumerable items) { + DateTime? minDate = items.Where(i => i.DateTime != Itenso.TimePeriod.TimeInterval.Anytime).Min(i => i.DateTime.Start); + DateTime? maxDate = items.Where(i => i.DateTime != Itenso.TimePeriod.TimeInterval.Anytime).Max(i => i.DateTime.End); + minDate = minDate == DateTime.MinValue ? null : minDate; + maxDate = maxDate == DateTime.MaxValue ? null : maxDate; return new StacExtent( 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])), - new StacTemporalExtent(items.Min(i => i.DateTime.Start), items.Max(i => i.DateTime.End)) + + new StacTemporalExtent(minDate, maxDate) ); } diff --git a/src/DotNetStac/StacGeometryHelpers.cs b/src/DotNetStac/StacGeometryHelpers.cs index 395b7aa2..70b8e090 100644 --- a/src/DotNetStac/StacGeometryHelpers.cs +++ b/src/DotNetStac/StacGeometryHelpers.cs @@ -18,7 +18,9 @@ public static class StacGeometryHelpers /// public static double[] GetBoundingBoxFromGeometryExtent(this StacItem stacItem) { - var boundingBoxes = stacItem.Geometry.GetBoundingBox(); + var boundingBoxes = stacItem.Geometry?.GetBoundingBox(); + if (boundingBoxes == null) + return new double [] { -180, -90, 180, 90 }; if (boundingBoxes[0].Altitude.HasValue) return new double[] { boundingBoxes[0].Longitude, boundingBoxes[0].Latitude, boundingBoxes[0].Altitude.Value, From 2b9b39a53941ef2af434da4c9d90c81ea5af09fa Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Mon, 12 Dec 2022 16:16:23 +0100 Subject: [PATCH 2/2] ready to release 1.6.4 --- CHANGELOG.md | 9 ++++++++- src/DotNetStac/Collection/StacExtent.cs | 2 +- src/DotNetStac/DotNetStac.csproj | 2 +- src/DotNetStac/StacGeometryHelpers.cs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1af84a61..c71d2936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -## [1.6.3](https://github.com/Terradue/DotNetStac/compare/1.6.3...1.6.3) +## [1.6.4](https://github.com/Terradue/DotNetStac/compare/1.6.4...1.6.4) + +### Commits + +- throws on invalid date [`361716f`](https://github.com/Terradue/DotNetStac/commit/361716f9c3b5fca8c12b0611806dc22fde4876c2) +- fix stac extent creation with null geometries and infinite date [`e8b1aaa`](https://github.com/Terradue/DotNetStac/commit/e8b1aaac6276e1d14a0aaa7d18fb343acec6cb73) + +## [1.6.4](https://github.com/Terradue/DotNetStac/compare/1.6.3...1.6.4) - 2022-12-12 ### Commits diff --git a/src/DotNetStac/Collection/StacExtent.cs b/src/DotNetStac/Collection/StacExtent.cs index 77ca75b3..b8e1bfab 100644 --- a/src/DotNetStac/Collection/StacExtent.cs +++ b/src/DotNetStac/Collection/StacExtent.cs @@ -64,7 +64,7 @@ public static StacExtent Create(IEnumerable items) items.Min(i => i.GetBoundingBoxFromGeometryExtent()[1]), items.Max(i => i.GetBoundingBoxFromGeometryExtent()[2]), items.Max(i => i.GetBoundingBoxFromGeometryExtent()[3])), - + new StacTemporalExtent(minDate, maxDate) ); } diff --git a/src/DotNetStac/DotNetStac.csproj b/src/DotNetStac/DotNetStac.csproj index 8cd5312f..4437cda2 100644 --- a/src/DotNetStac/DotNetStac.csproj +++ b/src/DotNetStac/DotNetStac.csproj @@ -4,7 +4,7 @@ DotNetStac Terradue .Net library for working with any SpatioTemporal Asset Catalog LICENSE - 1.6.4 + 1.6.5 Emmanuel Mathot emmanuelmathot Terradue diff --git a/src/DotNetStac/StacGeometryHelpers.cs b/src/DotNetStac/StacGeometryHelpers.cs index 70b8e090..f5a4fceb 100644 --- a/src/DotNetStac/StacGeometryHelpers.cs +++ b/src/DotNetStac/StacGeometryHelpers.cs @@ -20,7 +20,7 @@ public static double[] GetBoundingBoxFromGeometryExtent(this StacItem stacItem) { var boundingBoxes = stacItem.Geometry?.GetBoundingBox(); if (boundingBoxes == null) - return new double [] { -180, -90, 180, 90 }; + return new double[] { -180, -90, 180, 90 }; if (boundingBoxes[0].Altitude.HasValue) return new double[] { boundingBoxes[0].Longitude, boundingBoxes[0].Latitude, boundingBoxes[0].Altitude.Value,