Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ Point point = JsonConvert.DeserializeObject<Point>(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.

Expand Down
16 changes: 15 additions & 1 deletion src/GeoJSON.Net/Feature/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@

namespace GeoJSON.Net.Feature
{
/// <summary>
/// A GeoJSON Feature Object; generic version for strongly typed <see cref="Geometry"/>
/// and <see cref="Properties"/>
/// </summary>
/// <remarks>
/// See https://tools.ietf.org/html/rfc7946#section-3.2
/// </remarks>
public interface IFeature<out TGeometry, TProps> where TGeometry : IGeometryObject
{
string Id { get; }
TGeometry Geometry { get; }
TProps Properties { get; }
}

/// <summary>
/// A GeoJSON Feature Object; generic version for strongly typed <see cref="Geometry"/>
/// and <see cref="Properties"/>
/// </summary>
/// <remarks>
/// See https://tools.ietf.org/html/rfc7946#section-3.2
/// </remarks>
public class Feature<TGeometry, TProps> : GeoJSONObject, IEquatable<Feature<TGeometry, TProps>>
public class Feature<TGeometry, TProps> : GeoJSONObject, IFeature<TGeometry, TProps>, IEquatable<Feature<TGeometry, TProps>>
where TGeometry : IGeometryObject
{
[JsonConstructor]
Expand Down
111 changes: 111 additions & 0 deletions src/GeoJSON.Net/Feature/FeatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
using GeoJSON.Net.Geometry;

namespace GeoJSON.Net.Feature
{
Expand Down Expand Up @@ -119,4 +120,114 @@ public int GetHashCode(FeatureCollection other)

#endregion
}

public class FeatureCollection<TProps> : FeatureCollection, IEqualityComparer<FeatureCollection<TProps>>, IEquatable<FeatureCollection<TProps>>
{
/// <summary>
/// Initializes a new instance of the <see cref="FeatureCollection" /> class.
/// </summary>
public FeatureCollection() : this(new List<IFeature<IGeometryObject, TProps>>())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="FeatureCollection" /> class.
/// </summary>
/// <param name="features">The features.</param>
public FeatureCollection(List<IFeature<IGeometryObject, TProps>> features)
{
if (features == null)
{
throw new ArgumentNullException(nameof(features));
}

Features = features;
}

public override GeoJSONObjectType Type => GeoJSONObjectType.FeatureCollection;

/// <summary>
/// Gets the features.
/// </summary>
/// <value>The features.</value>
[JsonProperty(PropertyName = "features", Required = Required.Always)]
new public List<IFeature<IGeometryObject, TProps>> Features { get; private set; }

#region IEqualityComparer, IEquatable

/// <summary>
/// Determines whether the specified object is equal to the current object
/// </summary>
public override bool Equals(object obj)
{
return Equals(this, obj as FeatureCollection<TProps>);
}

/// <summary>
/// Determines whether the specified object is equal to the current object
/// </summary>
public bool Equals(FeatureCollection<TProps> other)
{
return Equals(this, other);
}

/// <summary>
/// Determines whether the specified object instances are considered equal
/// </summary>
public bool Equals(FeatureCollection<TProps> left, FeatureCollection<TProps> right)
{
if (base.Equals(left, right))
{
return left.Features.SequenceEqual(right.Features);
}
return false;
}

/// <summary>
/// Determines whether the specified object instances are considered equal
/// </summary>
public static bool operator ==(FeatureCollection<TProps> left, FeatureCollection<TProps> right)
{
if (ReferenceEquals(left, right))
{
return true;
}
if (ReferenceEquals(null, right))
{
return false;
}
return left != null && left.Equals(right);
}

/// <summary>
/// Determines whether the specified object instances are not considered equal
/// </summary>
public static bool operator !=(FeatureCollection<TProps> left, FeatureCollection<TProps> right)
{
return !(left == right);
}

/// <summary>
/// Returns the hash code for this instance
/// </summary>
public override int GetHashCode()
{
int hash = base.GetHashCode();
foreach (var feature in Features)
{
hash = (hash * 397) ^ feature.GetHashCode();
}
return hash;
}

/// <summary>
/// Returns the hash code for the specified object
/// </summary>
public int GetHashCode(FeatureCollection<TProps> other)
{
return other.GetHashCode();
}

#endregion
}
}
6 changes: 3 additions & 3 deletions src/GeoJSON.Net/GeoJSON.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<Description>.Net types for the GeoJSON RFC to be used with Json.Net</Description>
<Authors>Matt Hunt;Joerg Battermann;Xavier Fischer</Authors>
<Company>GeoJSON.Net</Company>
<Copyright>Copyright © Joerg Battermann, Matt Hunt, Xavier Fischer and Contributors, 2014 - 2019</Copyright>
<Copyright>Copyright © Joerg Battermann, Matt Hunt, Xavier Fischer and Contributors, 2014 - 2022</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.2.16</Version>
<Version>1.2.17</Version>
<PackageProjectUrl>https://github.com/GeoJSON-Net/GeoJSON.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/GeoJSON-Net/GeoJSON.Net.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>geojson;geo;json;geolocation</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>Fixes exception when serializing polygons</PackageReleaseNotes>
<PackageReleaseNotes>Add generic FeatureCollection</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down