diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..f99d7fc0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: Build and Tests + +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 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. 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