diff --git a/README.md b/README.md index a02c467..3817122 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ AppyWay geojson model and json serialization converters. | Package | Latest Stable | | --- | --- | -| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | -| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | -| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | +| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | +| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | +| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | ## Contribute diff --git a/build.cake b/build.cake index 83e0e3c..60eb92d 100644 --- a/build.cake +++ b/build.cake @@ -1,7 +1,7 @@ -#addin nuget:?package=YamlDotNet&version=8.1.2 +#addin nuget:?package=YamlDotNet&version=13.7.1 #addin nuget:?package=System.Xml.XDocument&version=4.3.0 -#addin nuget:?package=Cake.MinVer&version=2.0.0 -#addin nuget:?package=Cake.Yaml&version=3.1.1 +#addin nuget:?package=Cake.MinVer&version=3.0.0 +#addin nuget:?package=Cake.Yaml&version=6.0.0 #load "./functions.cake" diff --git a/global.json b/global.json index 264dc52..90bf02c 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "projects": [ "src" ], "sdk": { - "version": "6.0.300", + "version": "8.0.100", "rollForward": "latestPatch" } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.Newtonsoft/Appy.Spatial.GeoJSON.Newtonsoft.csproj b/src/Appy.Spatial.GeoJSON.Newtonsoft/Appy.Spatial.GeoJSON.Newtonsoft.csproj index 07559c8..40b8203 100644 --- a/src/Appy.Spatial.GeoJSON.Newtonsoft/Appy.Spatial.GeoJSON.Newtonsoft.csproj +++ b/src/Appy.Spatial.GeoJSON.Newtonsoft/Appy.Spatial.GeoJSON.Newtonsoft.csproj @@ -1,7 +1,7 @@ - net5.0;net6.0;netstandard2.0 + net8.0;net6.0;netstandard2.0 latest @@ -10,7 +10,7 @@ - + diff --git a/src/Appy.Spatial.GeoJSON.Newtonsoft/Extensions.cs b/src/Appy.Spatial.GeoJSON.Newtonsoft/Extensions.cs index 20afaca..9d61916 100644 --- a/src/Appy.Spatial.GeoJSON.Newtonsoft/Extensions.cs +++ b/src/Appy.Spatial.GeoJSON.Newtonsoft/Extensions.cs @@ -1,32 +1,31 @@ using Newtonsoft.Json; -namespace Appy.Spatial.GeoJSON.Newtonsoft +namespace Appy.Spatial.GeoJSON.Newtonsoft; + +public static class Extensions { - public static class Extensions + public static JsonSerializerSettings UseGeoJsonConverters(this JsonSerializerSettings options) { - public static JsonSerializerSettings UseGeoJsonConverters(this JsonSerializerSettings options) - { - options.Converters.Add(new FeatureConverter()); - options.Converters.Add(new GeometryConverter()); - return options; - } + options.Converters.Add(new FeatureConverter()); + options.Converters.Add(new GeometryConverter()); + return options; + } - internal static T PopulateObject(this JsonSerializer serializer, JsonReader jsonReader, T target) - { - serializer.Populate(jsonReader, target); + internal static T PopulateObject(this JsonSerializer serializer, JsonReader jsonReader, T target) + { + serializer.Populate(jsonReader, target); - if (!serializer.CheckAdditionalContent) - return target; + if (!serializer.CheckAdditionalContent) + return target; - while (jsonReader.Read()) + while (jsonReader.Read()) + { + if (jsonReader.TokenType != JsonToken.Comment) { - if (jsonReader.TokenType != JsonToken.Comment) - { - throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object."); - } + throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object."); } - - return target; } + + return target; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.Newtonsoft/FeatureConverter.cs b/src/Appy.Spatial.GeoJSON.Newtonsoft/FeatureConverter.cs index cf9623e..057c85b 100644 --- a/src/Appy.Spatial.GeoJSON.Newtonsoft/FeatureConverter.cs +++ b/src/Appy.Spatial.GeoJSON.Newtonsoft/FeatureConverter.cs @@ -2,47 +2,46 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Appy.Spatial.GeoJSON.Newtonsoft +namespace Appy.Spatial.GeoJSON.Newtonsoft; + +public class FeatureConverter : JsonConverter { - public class FeatureConverter : JsonConverter - { - public override bool CanWrite => false; + public override bool CanWrite => false; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var token = JToken.Load(reader); + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var token = JToken.Load(reader); - if (token is not JObject obj) - return null; + if (token is not JObject obj) + return null; - var geometryToken = obj.GetValue("geometry", StringComparison.OrdinalIgnoreCase); + var geometryToken = obj.GetValue("geometry", StringComparison.OrdinalIgnoreCase); - if (!geometryToken!.HasValues) - return FeatureOf(obj, serializer); + if (!geometryToken!.HasValues) + return FeatureOf(obj, serializer); - var geometryType = (geometryToken as JObject)?.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value(); + var geometryType = (geometryToken as JObject)?.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value(); - return geometryType switch - { - GeoType.GeometryCollection => FeatureOf(obj, serializer), - GeoType.Polygon => FeatureOf(obj, serializer), - GeoType.LineString => FeatureOf(obj, serializer), - GeoType.MultiLineString => FeatureOf(obj, serializer), - GeoType.MultiPolygon => FeatureOf(obj, serializer), - GeoType.Point => FeatureOf(obj, serializer), - _ => throw new JsonException($"Unsupported geometry type: {geometryType}") - }; - } + return geometryType switch + { + GeoType.GeometryCollection => FeatureOf(obj, serializer), + GeoType.Polygon => FeatureOf(obj, serializer), + GeoType.LineString => FeatureOf(obj, serializer), + GeoType.MultiLineString => FeatureOf(obj, serializer), + GeoType.MultiPolygon => FeatureOf(obj, serializer), + GeoType.Point => FeatureOf(obj, serializer), + _ => throw new JsonException($"Unsupported geometry type: {geometryType}") + }; + } - public override bool CanConvert(Type objectType) => - typeof(Feature) == objectType; + public override bool CanConvert(Type objectType) => + typeof(Feature) == objectType; - static Feature FeatureOf(JToken input, JsonSerializer serializer) where T : Geometry - { - using var jsonReader = input.CreateReader(); - return serializer.PopulateObject(jsonReader, new Feature()); - } + static Feature FeatureOf(JToken input, JsonSerializer serializer) where T : Geometry + { + using var jsonReader = input.CreateReader(); + return serializer.PopulateObject(jsonReader, new Feature()); } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.Newtonsoft/GeometryConverter.cs b/src/Appy.Spatial.GeoJSON.Newtonsoft/GeometryConverter.cs index 9baa54d..1c8b2e7 100644 --- a/src/Appy.Spatial.GeoJSON.Newtonsoft/GeometryConverter.cs +++ b/src/Appy.Spatial.GeoJSON.Newtonsoft/GeometryConverter.cs @@ -2,42 +2,41 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Appy.Spatial.GeoJSON.Newtonsoft +namespace Appy.Spatial.GeoJSON.Newtonsoft; + +public class GeometryConverter : JsonConverter { - public class GeometryConverter : JsonConverter - { - public override bool CanWrite => false; + public override bool CanWrite => false; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var token = JToken.Load(reader); + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var token = JToken.Load(reader); - if (token is not JObject obj) - return null; + if (token is not JObject obj) + return null; - var geometryType = obj.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value(); + var geometryType = obj.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value(); - return geometryType switch - { - GeoType.GeometryCollection => GeometryAs(obj, serializer), - GeoType.Polygon => GeometryAs(obj, serializer), - GeoType.LineString => GeometryAs(obj, serializer), - GeoType.MultiLineString => GeometryAs(obj, serializer), - GeoType.MultiPolygon => GeometryAs(obj, serializer), - GeoType.Point => GeometryAs(obj, serializer), - _ => throw new JsonException($"Unsupported geometry type {geometryType}") - }; - } + return geometryType switch + { + GeoType.GeometryCollection => GeometryAs(obj, serializer), + GeoType.Polygon => GeometryAs(obj, serializer), + GeoType.LineString => GeometryAs(obj, serializer), + GeoType.MultiLineString => GeometryAs(obj, serializer), + GeoType.MultiPolygon => GeometryAs(obj, serializer), + GeoType.Point => GeometryAs(obj, serializer), + _ => throw new JsonException($"Unsupported geometry type {geometryType}") + }; + } - public override bool CanConvert(Type objectType) => - typeof(Geometry) == objectType; + public override bool CanConvert(Type objectType) => + typeof(Geometry) == objectType; - static T GeometryAs(JToken input, JsonSerializer serializer) where T : new() - { - using var jsonReader = input.CreateReader(); - return serializer.PopulateObject(jsonReader, new T()); - } + static T GeometryAs(JToken input, JsonSerializer serializer) where T : new() + { + using var jsonReader = input.CreateReader(); + return serializer.PopulateObject(jsonReader, new T()); } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.TextJson/Appy.Spatial.GeoJSON.TextJson.csproj b/src/Appy.Spatial.GeoJSON.TextJson/Appy.Spatial.GeoJSON.TextJson.csproj index 56ce001..addab36 100644 --- a/src/Appy.Spatial.GeoJSON.TextJson/Appy.Spatial.GeoJSON.TextJson.csproj +++ b/src/Appy.Spatial.GeoJSON.TextJson/Appy.Spatial.GeoJSON.TextJson.csproj @@ -1,7 +1,7 @@ - net5.0;net6.0;netstandard2.0 + net8.0;net6.0;netstandard2.0 latest @@ -13,16 +13,8 @@ - - - - - - - - - - + + diff --git a/src/Appy.Spatial.GeoJSON.TextJson/Extensions.cs b/src/Appy.Spatial.GeoJSON.TextJson/Extensions.cs index f25cfb8..00508af 100644 --- a/src/Appy.Spatial.GeoJSON.TextJson/Extensions.cs +++ b/src/Appy.Spatial.GeoJSON.TextJson/Extensions.cs @@ -1,14 +1,13 @@ using System.Text.Json; -namespace Appy.Spatial.GeoJSON.TextJson +namespace Appy.Spatial.GeoJSON.TextJson; + +public static class Extensions { - public static class Extensions + public static JsonSerializerOptions UseGeoJsonConverters(this JsonSerializerOptions options) { - public static JsonSerializerOptions UseGeoJsonConverters(this JsonSerializerOptions options) - { - options.Converters.Add(new FeatureConverter()); - options.Converters.Add(new GeometryConverter()); - return options; - } + options.Converters.Add(new FeatureConverter()); + options.Converters.Add(new GeometryConverter()); + return options; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.TextJson/FeatureConverter.cs b/src/Appy.Spatial.GeoJSON.TextJson/FeatureConverter.cs index da45486..6b8f0d1 100644 --- a/src/Appy.Spatial.GeoJSON.TextJson/FeatureConverter.cs +++ b/src/Appy.Spatial.GeoJSON.TextJson/FeatureConverter.cs @@ -2,56 +2,55 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Appy.Spatial.GeoJSON.TextJson +namespace Appy.Spatial.GeoJSON.TextJson; + +public class FeatureConverter : JsonConverter { - public class FeatureConverter : JsonConverter - { - public override bool CanConvert(Type typeToConvert) => - typeof(Feature) == typeToConvert; + public override bool CanConvert(Type typeToConvert) => + typeof(Feature) == typeToConvert; - public override Feature Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var readerClone = reader; + public override Feature Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var readerClone = reader; - if (readerClone.TokenType != JsonTokenType.StartObject) - throw new JsonException("TokenType is not StartObject"); + if (readerClone.TokenType != JsonTokenType.StartObject) + throw new JsonException("TokenType is not StartObject"); - var propertyName = string.Empty; - var initialDepth = readerClone.CurrentDepth + 2; + var propertyName = string.Empty; + var initialDepth = readerClone.CurrentDepth + 2; - while (propertyName.ToLower() != "type") - { - readerClone.Read(); + while (propertyName.ToLower() != "type") + { + readerClone.Read(); - if (readerClone.CurrentDepth != initialDepth) - continue; + if (readerClone.CurrentDepth != initialDepth) + continue; - if (readerClone.TokenType != JsonTokenType.PropertyName) - continue; - - propertyName = readerClone.GetString(); - } + if (readerClone.TokenType != JsonTokenType.PropertyName) + continue; - readerClone.Read(); - - var geometryType = readerClone.GetString(); - - return geometryType switch - { - GeoType.GeometryCollection => FeatureOf(ref reader, options), - GeoType.Polygon => FeatureOf(ref reader, options), - GeoType.LineString => FeatureOf(ref reader, options), - GeoType.MultiLineString => FeatureOf(ref reader, options), - GeoType.MultiPolygon => FeatureOf(ref reader, options), - GeoType.Point => FeatureOf(ref reader, options), - _ => throw new JsonException($"Unsupported geometry type: {geometryType}") - }; + propertyName = readerClone.GetString(); } - static Feature FeatureOf(ref Utf8JsonReader reader, JsonSerializerOptions options) where T : Geometry => - JsonSerializer.Deserialize>(ref reader, options); + readerClone.Read(); - public override void Write(Utf8JsonWriter writer, Feature feature, JsonSerializerOptions options) => - JsonSerializer.Serialize(writer, feature, feature.GetType(), options); + var geometryType = readerClone.GetString(); + + return geometryType switch + { + GeoType.GeometryCollection => FeatureOf(ref reader, options), + GeoType.Polygon => FeatureOf(ref reader, options), + GeoType.LineString => FeatureOf(ref reader, options), + GeoType.MultiLineString => FeatureOf(ref reader, options), + GeoType.MultiPolygon => FeatureOf(ref reader, options), + GeoType.Point => FeatureOf(ref reader, options), + _ => throw new JsonException($"Unsupported geometry type: {geometryType}") + }; } + + static Feature FeatureOf(ref Utf8JsonReader reader, JsonSerializerOptions options) where T : Geometry => + JsonSerializer.Deserialize>(ref reader, options); + + public override void Write(Utf8JsonWriter writer, Feature feature, JsonSerializerOptions options) => + JsonSerializer.Serialize(writer, feature, feature.GetType(), options); } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON.TextJson/GeometryConverter.cs b/src/Appy.Spatial.GeoJSON.TextJson/GeometryConverter.cs index b0cd308..9698337 100644 --- a/src/Appy.Spatial.GeoJSON.TextJson/GeometryConverter.cs +++ b/src/Appy.Spatial.GeoJSON.TextJson/GeometryConverter.cs @@ -2,56 +2,55 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Appy.Spatial.GeoJSON.TextJson +namespace Appy.Spatial.GeoJSON.TextJson; + +public class GeometryConverter : JsonConverter { - public class GeometryConverter : JsonConverter - { - public override bool CanConvert(Type typeToConvert) => - typeof(Geometry) == typeToConvert; + public override bool CanConvert(Type typeToConvert) => + typeof(Geometry) == typeToConvert; - public override Geometry Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var readerClone = reader; + public override Geometry Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var readerClone = reader; - if (readerClone.TokenType != JsonTokenType.StartObject) - throw new JsonException("TokenType is not StartObject"); + if (readerClone.TokenType != JsonTokenType.StartObject) + throw new JsonException("TokenType is not StartObject"); - var propertyName = string.Empty; - var initialDepth = readerClone.CurrentDepth + 1; + var propertyName = string.Empty; + var initialDepth = readerClone.CurrentDepth + 1; - while (propertyName.ToLower() != "type") - { - readerClone.Read(); + while (propertyName.ToLower() != "type") + { + readerClone.Read(); - if (readerClone.CurrentDepth != initialDepth) - continue; + if (readerClone.CurrentDepth != initialDepth) + continue; - if (readerClone.TokenType != JsonTokenType.PropertyName) - continue; + if (readerClone.TokenType != JsonTokenType.PropertyName) + continue; - propertyName = readerClone.GetString(); - } + propertyName = readerClone.GetString(); + } - readerClone.Read(); + readerClone.Read(); - var geometryType = readerClone.GetString(); + var geometryType = readerClone.GetString(); - return geometryType switch - { - GeoType.GeometryCollection => GeometryAs(ref reader, options), - GeoType.Polygon => GeometryAs(ref reader, options), - GeoType.LineString => GeometryAs(ref reader, options), - GeoType.MultiLineString => GeometryAs(ref reader, options), - GeoType.MultiPolygon => GeometryAs(ref reader, options), - GeoType.Point => GeometryAs(ref reader, options), - _ => throw new JsonException($"Unsupported geometry type: {geometryType}") - }; - } + return geometryType switch + { + GeoType.GeometryCollection => GeometryAs(ref reader, options), + GeoType.Polygon => GeometryAs(ref reader, options), + GeoType.LineString => GeometryAs(ref reader, options), + GeoType.MultiLineString => GeometryAs(ref reader, options), + GeoType.MultiPolygon => GeometryAs(ref reader, options), + GeoType.Point => GeometryAs(ref reader, options), + _ => throw new JsonException($"Unsupported geometry type: {geometryType}") + }; + } - public override void Write(Utf8JsonWriter writer, Geometry geometry, JsonSerializerOptions options) => - JsonSerializer.Serialize(writer, geometry, geometry.GetType(), options); + public override void Write(Utf8JsonWriter writer, Geometry geometry, JsonSerializerOptions options) => + JsonSerializer.Serialize(writer, geometry, geometry.GetType(), options); - static TGeometry GeometryAs(ref Utf8JsonReader reader, JsonSerializerOptions options) where TGeometry : Geometry => - JsonSerializer.Deserialize(ref reader, options); - } + static TGeometry GeometryAs(ref Utf8JsonReader reader, JsonSerializerOptions options) where TGeometry : Geometry => + JsonSerializer.Deserialize(ref reader, options); } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Appy.Spatial.GeoJSON.csproj b/src/Appy.Spatial.GeoJSON/Appy.Spatial.GeoJSON.csproj index 40c576b..bc50726 100644 --- a/src/Appy.Spatial.GeoJSON/Appy.Spatial.GeoJSON.csproj +++ b/src/Appy.Spatial.GeoJSON/Appy.Spatial.GeoJSON.csproj @@ -2,7 +2,6 @@ netstandard2.0 - enable latest @@ -18,7 +17,7 @@ - + 3.0.0 False diff --git a/src/Appy.Spatial.GeoJSON/BoundingBox.cs b/src/Appy.Spatial.GeoJSON/BoundingBox.cs index 9fde9b3..8b2233d 100644 --- a/src/Appy.Spatial.GeoJSON/BoundingBox.cs +++ b/src/Appy.Spatial.GeoJSON/BoundingBox.cs @@ -1,23 +1,24 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class BoundingBox { - public class BoundingBox - { - public LatLng TopLeft { get; set; } - public LatLng BottomRight { get; set; } - } + public LatLng TopLeft { get; set; } + public LatLng BottomRight { get; set; } +} - public class BoundingBoxComparer : IEqualityComparer - { - public bool Equals(BoundingBox x, BoundingBox y) => - x == null && y == null || - x != null && y != null && - new LatLngComparer().Equals(x.TopLeft, y.TopLeft) && - new LatLngComparer().Equals(x.BottomRight, y.BottomRight); +public class BoundingBoxComparer : IEqualityComparer +{ + public bool Equals(BoundingBox x, BoundingBox y) => + x == null && y == null || + x != null && y != null && + new LatLngComparer().Equals(x.TopLeft, y.TopLeft) && + new LatLngComparer().Equals(x.BottomRight, y.BottomRight); - public int GetHashCode(BoundingBox obj) => - obj.TopLeft?.Latitude.GetHashCode() ?? 0 + - obj.TopLeft?.Longitude.GetHashCode() ?? 0 + - obj.BottomRight?.Latitude.GetHashCode() ?? 0 + - obj.BottomRight?.Longitude.GetHashCode() ?? 0; - } + public int GetHashCode(BoundingBox obj) => + obj.TopLeft?.Latitude.GetHashCode() ?? 0 + + obj.TopLeft?.Longitude.GetHashCode() ?? 0 + + obj.BottomRight?.Latitude.GetHashCode() ?? 0 + + obj.BottomRight?.Longitude.GetHashCode() ?? 0; } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Crs.cs b/src/Appy.Spatial.GeoJSON/Crs.cs index 4674c26..5e977ef 100644 --- a/src/Appy.Spatial.GeoJSON/Crs.cs +++ b/src/Appy.Spatial.GeoJSON/Crs.cs @@ -1,49 +1,48 @@ -namespace Appy.Spatial.GeoJSON +namespace Appy.Spatial.GeoJSON; + +public class Crs { - public class Crs - { - public string Type { get; set; } - public CrsProperties Properties { get; set; } + public string Type { get; set; } + public CrsProperties Properties { get; set; } - public static readonly Crs Wgs84 = new() + public static readonly Crs Wgs84 = new() + { + Type = "name", + Properties = new CrsProperties { - Type = "name", - Properties = new CrsProperties - { - Name = "urn:ogc:def:crs:OGC:1.3:CRS84" - } - }; + Name = "urn:ogc:def:crs:OGC:1.3:CRS84" + } + }; - public static readonly Crs Osgb36 = new() + public static readonly Crs Osgb36 = new() + { + Type = "name", + Properties = new CrsProperties { - Type = "name", - Properties = new CrsProperties - { - Name = "urn:ogc:def:crs:EPSG::27700" - } - }; + Name = "urn:ogc:def:crs:EPSG::27700" + } + }; - public static readonly Crs Etrs89 = new() + public static readonly Crs Etrs89 = new() + { + Type = "name", + Properties = new CrsProperties { - Type = "name", - Properties = new CrsProperties - { - Name = "urn:ogc:def:crs:EPSG::4258" - } - }; + Name = "urn:ogc:def:crs:EPSG::4258" + } + }; - public static readonly Crs Epsg3857 = new() + public static readonly Crs Epsg3857 = new() + { + Type = "name", + Properties = new CrsProperties { - Type = "name", - Properties = new CrsProperties - { - Name = "urn:ogc:def:crs:EPSG::3857" - } - }; - } + Name = "urn:ogc:def:crs:EPSG::3857" + } + }; +} - public class CrsProperties - { - public string Name { get; set; } - } +public class CrsProperties +{ + public string Name { get; set; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Feature.cs b/src/Appy.Spatial.GeoJSON/Feature.cs index 2704b97..2ffcf44 100644 --- a/src/Appy.Spatial.GeoJSON/Feature.cs +++ b/src/Appy.Spatial.GeoJSON/Feature.cs @@ -1,29 +1,28 @@ -namespace Appy.Spatial.GeoJSON +namespace Appy.Spatial.GeoJSON; + +public abstract class Feature { - public abstract class Feature - { - public string Type { get; set; } = GeoType.Feature; - public string Id { get; set; } - } + public string Type { get; set; } = GeoType.Feature; + public string Id { get; set; } +} - public class Feature : Feature where TGeometry : Geometry - { - public TGeometry Geometry { get; set; } - } +public class Feature : Feature where TGeometry : Geometry +{ + public TGeometry Geometry { get; set; } +} - public class Feature : Feature where TGeometry : Geometry +public class Feature : Feature where TGeometry : Geometry +{ + public Feature() { - public Feature() - { - } - - public Feature(string id, TGeometry geometry, TProperties properties) - { - Id = id; - Geometry = geometry; - Properties = properties; - } + } - public TProperties Properties { get; set; } + public Feature(string id, TGeometry geometry, TProperties properties) + { + Id = id; + Geometry = geometry; + Properties = properties; } + + public TProperties Properties { get; set; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/FeatureCollection.cs b/src/Appy.Spatial.GeoJSON/FeatureCollection.cs index 052ee24..0bde7c2 100644 --- a/src/Appy.Spatial.GeoJSON/FeatureCollection.cs +++ b/src/Appy.Spatial.GeoJSON/FeatureCollection.cs @@ -1,23 +1,24 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class FeatureCollection { - public class FeatureCollection - { - public string Type { get; set; } = "FeatureCollection"; - public List Features { get; set; } - public dynamic Properties { get; set; } - } + public string Type { get; set; } = "FeatureCollection"; + public List Features { get; set; } + public dynamic Properties { get; set; } +} - public class FeatureCollection where T : Geometry - { - public string Type { get; set; } = "FeatureCollection"; - public List> Features { get; set; } - public dynamic Properties { get; set; } - } +public class FeatureCollection where T : Geometry +{ + public string Type { get; set; } = "FeatureCollection"; + public List> Features { get; set; } + public dynamic Properties { get; set; } +} - public class FeatureCollection where TGeometry : Geometry - { - public string Type { get; set; } = "FeatureCollection"; - public List> Features { get; set; } - public dynamic Properties { get; set; } - } +public class FeatureCollection where TGeometry : Geometry +{ + public string Type { get; set; } = "FeatureCollection"; + public List> Features { get; set; } + public dynamic Properties { get; set; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/GeoType.cs b/src/Appy.Spatial.GeoJSON/GeoType.cs index bb78517..aee7513 100644 --- a/src/Appy.Spatial.GeoJSON/GeoType.cs +++ b/src/Appy.Spatial.GeoJSON/GeoType.cs @@ -1,13 +1,12 @@ -namespace Appy.Spatial.GeoJSON +namespace Appy.Spatial.GeoJSON; + +public class GeoType { - public class GeoType - { - public const string Feature = "Feature"; - public const string Point = "Point"; - public const string Polygon = "Polygon"; - public const string MultiPolygon = "MultiPolygon"; - public const string LineString = "LineString"; - public const string MultiLineString = "MultiLineString"; - public const string GeometryCollection = "GeometryCollection"; - } + public const string Feature = "Feature"; + public const string Point = "Point"; + public const string Polygon = "Polygon"; + public const string MultiPolygon = "MultiPolygon"; + public const string LineString = "LineString"; + public const string MultiLineString = "MultiLineString"; + public const string GeometryCollection = "GeometryCollection"; } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Geometry.cs b/src/Appy.Spatial.GeoJSON/Geometry.cs index 405bd11..387c90e 100644 --- a/src/Appy.Spatial.GeoJSON/Geometry.cs +++ b/src/Appy.Spatial.GeoJSON/Geometry.cs @@ -1,28 +1,23 @@ -namespace Appy.Spatial.GeoJSON +namespace Appy.Spatial.GeoJSON; + +public abstract class Geometry +{ + public string Type { get; set; } + public Crs Crs { get; set; } +} + +public abstract class Geometry : Geometry { - public abstract class Geometry + protected Geometry(string type) { - public string Type { get; set; } - public Crs Crs { get; set; } + Type = type; } - public abstract class Geometry : Geometry + protected Geometry(string type, T coordinates) { - protected Geometry(string type) - { - Type = type; - } - - protected Geometry(string type, T coordinates) - { - Type = type; - Coordinates = coordinates; - } - - public T Coordinates { get; set; } + Type = type; + Coordinates = coordinates; } - - - - + + public T Coordinates { get; set; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/GeometryCollection.cs b/src/Appy.Spatial.GeoJSON/GeometryCollection.cs index e050775..d146599 100644 --- a/src/Appy.Spatial.GeoJSON/GeometryCollection.cs +++ b/src/Appy.Spatial.GeoJSON/GeometryCollection.cs @@ -1,12 +1,13 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class GeometryCollection : Geometry { - public class GeometryCollection : Geometry + public GeometryCollection() { - public GeometryCollection() - { - Type = GeoType.GeometryCollection; - } - - public List Geometries { get; set; } + Type = GeoType.GeometryCollection; } + + public List Geometries { get; set; } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/LatLng.cs b/src/Appy.Spatial.GeoJSON/LatLng.cs index 45bc59b..2aed527 100644 --- a/src/Appy.Spatial.GeoJSON/LatLng.cs +++ b/src/Appy.Spatial.GeoJSON/LatLng.cs @@ -1,21 +1,22 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class LatLng { - public class LatLng - { - public double Latitude { get; set; } - public double Longitude { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } - public Point AsPoint() => new(new[] { Longitude, Latitude }); - } + public Point AsPoint() => new(new[] { Longitude, Latitude }); +} + +public class LatLngComparer : IEqualityComparer +{ + public bool Equals(LatLng x, LatLng y) => + x == null && y == null || + x != null && y != null && x.Latitude.Equals(y.Latitude) && x.Longitude.Equals(y.Latitude); - public class LatLngComparer : IEqualityComparer - { - public bool Equals(LatLng x, LatLng y) => - x == null && y == null || - x != null && y != null && x.Latitude.Equals(y.Latitude) && x.Longitude.Equals(y.Latitude); - - public int GetHashCode(LatLng obj) => - obj.Latitude.GetHashCode() + - obj.Longitude.GetHashCode(); - } + public int GetHashCode(LatLng obj) => + obj.Latitude.GetHashCode() + + obj.Longitude.GetHashCode(); } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/LineString.cs b/src/Appy.Spatial.GeoJSON/LineString.cs index f42f4f3..5aa1ba7 100644 --- a/src/Appy.Spatial.GeoJSON/LineString.cs +++ b/src/Appy.Spatial.GeoJSON/LineString.cs @@ -1,15 +1,16 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class LineString : Geometry>> { - public class LineString : Geometry>> + public LineString() + : base(GeoType.LineString) { - public LineString() - : base(GeoType.LineString) - { - } + } - public LineString(IList> coordinates) - : base(GeoType.LineString, coordinates) - { - } + public LineString(IList> coordinates) + : base(GeoType.LineString, coordinates) + { } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/MultiLineString.cs b/src/Appy.Spatial.GeoJSON/MultiLineString.cs index 152c458..4ff4497 100644 --- a/src/Appy.Spatial.GeoJSON/MultiLineString.cs +++ b/src/Appy.Spatial.GeoJSON/MultiLineString.cs @@ -1,21 +1,23 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; +using System.Linq; + +namespace Appy.Spatial.GeoJSON; + +public class MultiLineString : Geometry>>> { - public class MultiLineString : Geometry>>> + public MultiLineString() + : base(GeoType.MultiLineString) { - public MultiLineString() - : base(GeoType.MultiLineString) - { - } + } - public MultiLineString(IList>> coordinates) - : base(GeoType.MultiLineString, coordinates) - { - } + public MultiLineString(IList>> coordinates) + : base(GeoType.MultiLineString, coordinates) + { + } + + public MultiLineString(IList lineStrings) + : base(GeoType.MultiLineString, lineStrings.Select(ls => ls.Coordinates).ToList()) + { - public MultiLineString(IList lineStrings) - : base(GeoType.MultiLineString, lineStrings.Select(ls => ls.Coordinates).ToList()) - { - - } } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/MultiPolygon.cs b/src/Appy.Spatial.GeoJSON/MultiPolygon.cs index e6e3bbe..cbdd723 100644 --- a/src/Appy.Spatial.GeoJSON/MultiPolygon.cs +++ b/src/Appy.Spatial.GeoJSON/MultiPolygon.cs @@ -1,20 +1,22 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; +using System.Linq; + +namespace Appy.Spatial.GeoJSON; + +public class MultiPolygon : Geometry>>>> { - public class MultiPolygon : Geometry>>>> + public MultiPolygon() + : base(GeoType.MultiPolygon) { - public MultiPolygon() - : base(GeoType.MultiPolygon) - { - } + } - public MultiPolygon(IList>>> coordinates) - : base(GeoType.MultiPolygon, coordinates) - { - } + public MultiPolygon(IList>>> coordinates) + : base(GeoType.MultiPolygon, coordinates) + { + } - public MultiPolygon(IEnumerable polygons) - : base(GeoType.MultiPolygon, polygons.Select(p => p.Coordinates).ToList()) - { - } + public MultiPolygon(IEnumerable polygons) + : base(GeoType.MultiPolygon, polygons.Select(p => p.Coordinates).ToList()) + { } } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Point.cs b/src/Appy.Spatial.GeoJSON/Point.cs index 9b590b0..6eb0007 100644 --- a/src/Appy.Spatial.GeoJSON/Point.cs +++ b/src/Appy.Spatial.GeoJSON/Point.cs @@ -1,17 +1,18 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class Point : Geometry> { - public class Point : Geometry> + public Point() + : base(GeoType.Point) { - public Point() - : base(GeoType.Point) - { - } + } - public Point(IList coordinates) - : base(GeoType.Point, coordinates) - { - } - - public LatLng ToLatLng() => new() {Latitude = Coordinates[1], Longitude = Coordinates[0]}; + public Point(IList coordinates) + : base(GeoType.Point, coordinates) + { } + + public LatLng ToLatLng() => new() {Latitude = Coordinates[1], Longitude = Coordinates[0]}; } \ No newline at end of file diff --git a/src/Appy.Spatial.GeoJSON/Polygon.cs b/src/Appy.Spatial.GeoJSON/Polygon.cs index 2d27595..2cbe813 100644 --- a/src/Appy.Spatial.GeoJSON/Polygon.cs +++ b/src/Appy.Spatial.GeoJSON/Polygon.cs @@ -1,15 +1,16 @@ -namespace Appy.Spatial.GeoJSON +using System.Collections.Generic; + +namespace Appy.Spatial.GeoJSON; + +public class Polygon : Geometry>>> { - public class Polygon : Geometry>>> + public Polygon() + : base(GeoType.Polygon) { - public Polygon() - : base(GeoType.Polygon) - { - } + } - public Polygon(IList>> coordinates) - : base(GeoType.Polygon, coordinates) - { - } + public Polygon(IList>> coordinates) + : base(GeoType.Polygon, coordinates) + { } -} +} \ No newline at end of file diff --git a/src/Appy.Spatial.Geojson.sln b/src/Appy.Spatial.Geojson.sln index 131a49f..edadb30 100644 --- a/src/Appy.Spatial.Geojson.sln +++ b/src/Appy.Spatial.Geojson.sln @@ -6,25 +6,26 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appy.Spatial.GeoJSON.Newton EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appy.Spatial.GeoJSON.TextJson", "Appy.Spatial.GeoJSON.TextJson\Appy.Spatial.GeoJSON.TextJson.csproj", "{CDFFB90F-9DE9-4EE6-B088-ABDCE0AFCE26}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D7D58114-E0A9-4F2F-96AE-598A4B359A7A}" - ProjectSection(SolutionItems) = preProject - appveyor.yml = appveyor.yml - build.ps1 = build.ps1 - config.yml = config.yml - functions.ps1 = functions.ps1 - tasks.ps1 = tasks.ps1 - version.props = version.props - global.json = global.json - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1. Project", "1. Project", "{09A46B69-0EEB-4CF7-8857-BFC27F600C45}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2. Extensions", "2. Extensions", "{12D32EB2-3BA6-4ECC-801A-C379BBE2C34F}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2. Packages", "2. Packages", "{12D32EB2-3BA6-4ECC-801A-C379BBE2C34F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "99. Tests", "99. Tests", "{F376B16D-2CBD-4D07-858E-7791A9FBAD4D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appy.Spatial.GeoJSON.Tests", "Appy.Spatial.GeoJSON.Tests\Appy.Spatial.GeoJSON.Tests.csproj", "{886A1237-45D1-4580-9B8F-0531B5CC297B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7F6AB84F-685C-4465-BB36-2832CB151EFF}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + ..\build.cake = ..\build.cake + ..\config.yml = ..\config.yml + ..\dotnet-tools.json = ..\dotnet-tools.json + ..\functions.cake = ..\functions.cake + ..\global.json = ..\global.json + Directory.Packages.props = Directory.Packages.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a55c028..d55bb4c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -24,7 +24,7 @@ https://github.com/YellowLineParking/Appy.Spatial.GeoJSON MIT https://github.com/YellowLineParking/Appy.Spatial.GeoJSON/releases - NET6;NETCore + NET8;NET6;NetStandard @@ -38,26 +38,8 @@ - - + + - - 1.0.0-alpha.160 - 1.2.1 - 13.0.1 - - - - 0.1.0 - 17.0.0 - 5.10.3 - 4.14.6 - 2.4.1 - 2.4.3 - 1.3.0 - 2.1.26 - 1.1.2 - - diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..16fefbf --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,24 @@ + + + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file