From 0a0f5a3430501dc09799db913134228eb3c93f7e Mon Sep 17 00:00:00 2001 From: Matt Lethargic Date: Thu, 13 Aug 2020 09:29:17 +0100 Subject: [PATCH 1/4] Create main.yml --- .github/workflows/main.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..2f87995d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: .NET Core + +on: + push: + branches: [ v2 ] + pull_request: + branches: [ v2 ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Install dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-restore --verbosity normal From 4a10d5b913b238d2931fb245aeb0c8309111ab5d Mon Sep 17 00:00:00 2001 From: Matt Lethargic Date: Thu, 13 Aug 2020 09:30:19 +0100 Subject: [PATCH 2/4] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2f87995d..f99d7fc0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: .NET Core +name: Build and Tests on: push: From 67110b59a8edb3a79fe0aab07d828e6b3c8322e2 Mon Sep 17 00:00:00 2001 From: Martin Carpentier Date: Fri, 28 Jan 2022 11:00:24 +0100 Subject: [PATCH 3/4] Feature/update readme (#157) * Create dotnet.yml * Updated the readme to point to geojson.text for system.text.json support Co-authored-by: Martin Boje Carpentier --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b518018..2bf76685 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,17 @@ Point point = JsonConvert.DeserializeObject(json); See the [Tests](https://github.com/GeoJSON-Net/GeoJSON.Net/tree/master/src/GeoJSON.Net.Tests) for more examples. -## Special considerations for ASP.Net Core 3+ +## Special considerations for ASP.Net Core 3.1+ -System.Text.Json is the default (recommended) serializer. GeoJSON.Net **does not play well with System.Text.Json**. Here are the recommended steps as a workaround: +System.Text.Json is the default (recommended) serializer. GeoJSON.Net **does not play well with System.Text.Json** and only supports Newtonsoft.Json + +[GeoJSON.Text](https://github.com/GeoJSON-Net/GeoJSON.Text) is a fork of this repository and have been developed to support System.Text.Json. + +If you still need to use Newtonsoft.Json in ASP.Net Core 3.1+, you must overwrite the default serializer. - add the "Microsoft.AspNetCore.Mvc.NewtonsoftJson" NuGet Package - add "services.AddControllers().AddNewtonsoftJson();" to your service configuration. -(Thanks for @jrowe88 for pointing this out) - ## Contributing Highly welcome! Just fork away and send a pull request. We try and review most pull requests within a couple of days. There is now a version 2.0.0 branch. I've created this ready for any breaking changes and any extra features and would encourage anything that isn't a bug fix to go in there. From 7993a6f8ada4eadea384f110a73c9d12a45e74c5 Mon Sep 17 00:00:00 2001 From: Yaroslav Kormushyn Date: Sat, 30 Apr 2022 22:57:49 +0300 Subject: [PATCH 4/4] add generic FeatureCollection --- src/GeoJSON.Net/Feature/Feature.cs | 16 ++- src/GeoJSON.Net/Feature/FeatureCollection.cs | 111 +++++++++++++++++++ src/GeoJSON.Net/GeoJSON.Net.csproj | 6 +- 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/GeoJSON.Net/Feature/Feature.cs b/src/GeoJSON.Net/Feature/Feature.cs index 5624cbcf..bf529415 100644 --- a/src/GeoJSON.Net/Feature/Feature.cs +++ b/src/GeoJSON.Net/Feature/Feature.cs @@ -12,6 +12,20 @@ namespace GeoJSON.Net.Feature { + /// + /// A GeoJSON Feature Object; generic version for strongly typed + /// and + /// + /// + /// See https://tools.ietf.org/html/rfc7946#section-3.2 + /// + public interface IFeature where TGeometry : IGeometryObject + { + string Id { get; } + TGeometry Geometry { get; } + TProps Properties { get; } + } + /// /// A GeoJSON Feature Object; generic version for strongly typed /// and @@ -19,7 +33,7 @@ namespace GeoJSON.Net.Feature /// /// See https://tools.ietf.org/html/rfc7946#section-3.2 /// - public class Feature : GeoJSONObject, IEquatable> + public class Feature : GeoJSONObject, IFeature, IEquatable> where TGeometry : IGeometryObject { [JsonConstructor] diff --git a/src/GeoJSON.Net/Feature/FeatureCollection.cs b/src/GeoJSON.Net/Feature/FeatureCollection.cs index a1db7979..9a9e253c 100644 --- a/src/GeoJSON.Net/Feature/FeatureCollection.cs +++ b/src/GeoJSON.Net/Feature/FeatureCollection.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using System.Linq; +using GeoJSON.Net.Geometry; namespace GeoJSON.Net.Feature { @@ -119,4 +120,114 @@ public int GetHashCode(FeatureCollection other) #endregion } + + public class FeatureCollection : FeatureCollection, IEqualityComparer>, IEquatable> + { + /// + /// Initializes a new instance of the class. + /// + public FeatureCollection() : this(new List>()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The features. + public FeatureCollection(List> features) + { + if (features == null) + { + throw new ArgumentNullException(nameof(features)); + } + + Features = features; + } + + public override GeoJSONObjectType Type => GeoJSONObjectType.FeatureCollection; + + /// + /// Gets the features. + /// + /// The features. + [JsonProperty(PropertyName = "features", Required = Required.Always)] + new public List> Features { get; private set; } + + #region IEqualityComparer, IEquatable + + /// + /// Determines whether the specified object is equal to the current object + /// + public override bool Equals(object obj) + { + return Equals(this, obj as FeatureCollection); + } + + /// + /// Determines whether the specified object is equal to the current object + /// + public bool Equals(FeatureCollection other) + { + return Equals(this, other); + } + + /// + /// Determines whether the specified object instances are considered equal + /// + public bool Equals(FeatureCollection left, FeatureCollection right) + { + if (base.Equals(left, right)) + { + return left.Features.SequenceEqual(right.Features); + } + return false; + } + + /// + /// Determines whether the specified object instances are considered equal + /// + public static bool operator ==(FeatureCollection left, FeatureCollection right) + { + if (ReferenceEquals(left, right)) + { + return true; + } + if (ReferenceEquals(null, right)) + { + return false; + } + return left != null && left.Equals(right); + } + + /// + /// Determines whether the specified object instances are not considered equal + /// + public static bool operator !=(FeatureCollection left, FeatureCollection right) + { + return !(left == right); + } + + /// + /// Returns the hash code for this instance + /// + public override int GetHashCode() + { + int hash = base.GetHashCode(); + foreach (var feature in Features) + { + hash = (hash * 397) ^ feature.GetHashCode(); + } + return hash; + } + + /// + /// Returns the hash code for the specified object + /// + public int GetHashCode(FeatureCollection other) + { + return other.GetHashCode(); + } + + #endregion + } } \ No newline at end of file diff --git a/src/GeoJSON.Net/GeoJSON.Net.csproj b/src/GeoJSON.Net/GeoJSON.Net.csproj index 1786d76c..02d86071 100644 --- a/src/GeoJSON.Net/GeoJSON.Net.csproj +++ b/src/GeoJSON.Net/GeoJSON.Net.csproj @@ -5,15 +5,15 @@ .Net types for the GeoJSON RFC to be used with Json.Net Matt Hunt;Joerg Battermann;Xavier Fischer GeoJSON.Net - Copyright © Joerg Battermann, Matt Hunt, Xavier Fischer and Contributors, 2014 - 2019 + Copyright © Joerg Battermann, Matt Hunt, Xavier Fischer and Contributors, 2014 - 2022 true - 1.2.16 + 1.2.17 https://github.com/GeoJSON-Net/GeoJSON.Net https://github.com/GeoJSON-Net/GeoJSON.Net.git git geojson;geo;json;geolocation MIT - Fixes exception when serializing polygons + Add generic FeatureCollection