-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GeoJSONMultiLineString / GeoJSONLineString WR-725
- Loading branch information
1 parent
fced53f
commit bda37fc
Showing
6 changed files
with
239 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/Be.Vlaanderen.Basisregisters.GrAr.Legacy/SpatialTools/GeoJSONLineString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Be.Vlaanderen.Basisregisters.GrAr.Legacy.SpatialTools | ||
{ | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Een GeoJSON linestring. | ||
/// </summary> | ||
public class GeoJSONLineString | ||
{ | ||
/// <summary> | ||
/// Coördinaten volgens Lambert-72 (EPSG:31370). | ||
/// </summary> | ||
[JsonConverter(typeof(LineStringCoordinatesConverter))] | ||
[JsonProperty(Required = Required.DisallowNull)] | ||
public double[][] Coordinates { get; set; } | ||
|
||
/// <summary> | ||
/// GeoJSON-geometrietype. | ||
/// </summary> | ||
[JsonProperty(Required = Required.DisallowNull)] | ||
public string Type { get; } | ||
|
||
public GeoJSONLineString() | ||
{ | ||
Type = "LineString"; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Be.Vlaanderen.Basisregisters.GrAr.Legacy/SpatialTools/GeoJSONMultiLineString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Be.Vlaanderen.Basisregisters.GrAr.Legacy.SpatialTools | ||
{ | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Een GeoJSON multi linestring. | ||
/// </summary> | ||
public class GeoJSONMultiLineString | ||
{ | ||
/// <summary> | ||
/// Coördinaten volgens Lambert-72 (EPSG:31370). | ||
/// </summary> | ||
[JsonConverter(typeof(PolygonCoordinatesConverter))] | ||
[JsonProperty(Required = Required.DisallowNull)] | ||
public double[][][] Coordinates { get; set; } | ||
|
||
/// <summary> | ||
/// GeoJSON-geometrietype. | ||
/// </summary> | ||
[JsonProperty(Required = Required.DisallowNull)] | ||
public string Type { get; } | ||
|
||
public GeoJSONMultiLineString() | ||
{ | ||
Type = "MultiLineString"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...sregisters.GrAr.Legacy/SpatialTools/GeometryCoordinates/LineStringCoordinatesConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Be.Vlaanderen.Basisregisters.GrAr.Legacy.SpatialTools | ||
{ | ||
using System; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
|
||
public class LineStringCoordinatesConverter : JsonConverter<double[][]> | ||
{ | ||
private static readonly object Lock = new object(); | ||
|
||
public override void WriteJson( | ||
JsonWriter writer, | ||
double[][] lineString, | ||
JsonSerializer serializer) | ||
{ | ||
lock (Lock) | ||
{ | ||
if (!serializer.Converters.Any(converter => converter is GeometryCoordinateValueConverter)) | ||
serializer.Converters.Add(new GeometryCoordinateValueConverter()); | ||
} | ||
|
||
serializer.Serialize( | ||
writer, | ||
lineString.Select(points => | ||
points.Select(coordinateValue => new LineStringGeometryCoordinateValue(coordinateValue))), | ||
typeof(GeometryCoordinateValueConverter)); | ||
} | ||
|
||
public override double[][] ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
double[][] existingValue, | ||
bool hasExistingValue, | ||
JsonSerializer serializer) | ||
=> throw new NotImplementedException($"Json deserialization of LineStringCoordinates is not supported"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...n.Basisregisters.GrAr.Tests/GeometryCoordinates/LineStringGeometryCoordinateValueTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
namespace Be.Vlaanderen.Basisregisters.GrAr.Tests.GeometryCoordinates | ||
{ | ||
using System; | ||
using System.Globalization; | ||
using AutoFixture; | ||
using FluentAssertions; | ||
using Infrastructure; | ||
using Legacy.SpatialTools; | ||
using Xunit; | ||
|
||
public class WhenConvertingACreatingALineStringGeometryCoordinateValueBackToADouble | ||
{ | ||
private readonly double _originalValue; | ||
private readonly GeometryCoordinateValue _coordinateValue; | ||
|
||
public WhenConvertingACreatingALineStringGeometryCoordinateValueBackToADouble() | ||
{ | ||
_originalValue = new Fixture().CreateDoubleWithPrecision(12, 25); | ||
|
||
_coordinateValue = new LineStringGeometryCoordinateValue(_originalValue); | ||
} | ||
|
||
[Fact] | ||
public void ThenOriginalPrecisionShouldBeMaintained() | ||
{ | ||
_coordinateValue | ||
.Should() | ||
.Be(_originalValue); | ||
} | ||
|
||
} | ||
|
||
public class WhenWritingALineStringGeometryCoordinateValueWithLessPrecisionThanExpected | ||
{ | ||
private readonly double _originalValue; | ||
private readonly string _printedValue; | ||
|
||
public WhenWritingALineStringGeometryCoordinateValueWithLessPrecisionThanExpected() | ||
{ | ||
_originalValue = new Fixture().CreateDoubleWithPrecision(0, 10); | ||
|
||
_printedValue = new LineStringGeometryCoordinateValue(_originalValue).ToString(); | ||
} | ||
|
||
[Fact] | ||
public void ThenTheDecimalPrecisionShouldBeExtendedToShowElevenDecimals() | ||
{ | ||
_printedValue | ||
.Should() | ||
.MatchRegex(@"^-?\d+\.\d{11}$"); | ||
} | ||
|
||
[Fact] | ||
public void ThenPrintedValueShouldBeEqualToTheOriginal() | ||
{ | ||
double.Parse(_printedValue, CultureInfo.InvariantCulture) | ||
.Should() | ||
.Be(_originalValue); | ||
} | ||
} | ||
|
||
public class WhenWritingALineStringGeometryCoordinateValueWithMorePrecisionThanSupported | ||
{ | ||
private readonly double _originalValue; | ||
private readonly string _printedValue; | ||
|
||
public WhenWritingALineStringGeometryCoordinateValueWithMorePrecisionThanSupported() | ||
{ | ||
_originalValue = new Fixture().CreateDoubleWithPrecision(12, 20); | ||
|
||
_printedValue = new LineStringGeometryCoordinateValue(_originalValue).ToString(); | ||
} | ||
|
||
[Fact] | ||
public void ThenTheDecimalPrecisionShouldBeReducedToElevenDecimals() | ||
{ | ||
_printedValue | ||
.Should() | ||
.MatchRegex(@"^-?\d+\.\d{11}$"); | ||
} | ||
|
||
[Fact] | ||
public void ThenThePrintedValueShouldBeRoundedToElevenDecimalsPrecision() | ||
{ | ||
var roundedValue = Math.Round(_originalValue, 11); | ||
double.Parse(_printedValue, CultureInfo.InvariantCulture) | ||
.Should() | ||
.Be(roundedValue); | ||
} | ||
} | ||
|
||
public class WhenParsingAValidDoubleStringAsLineStringGeometryCoordinateValue | ||
{ | ||
[Fact] | ||
public void ThenAGeometryCoordinateValueShouldBeReturned() | ||
{ | ||
var value = new Fixture().CreateDoubleWithPrecision(15); | ||
LineStringGeometryCoordinateValue | ||
.TryParse(value.ToString(CultureInfo.InvariantCulture)) | ||
.Should() | ||
.NotBeNull() | ||
.And.BeOfType<LineStringGeometryCoordinateValue>() | ||
.And.Be(value); | ||
} | ||
} | ||
|
||
public class WhenParsingAnInvalidDoubleStringAsLineStringGeometryCoordinateValue | ||
{ | ||
[Fact] | ||
public void ThenNothingShouldBeReturned() | ||
{ | ||
LineStringGeometryCoordinateValue | ||
.TryParse(new Fixture().Create<string>()) | ||
.Should() | ||
.BeNull(); | ||
} | ||
} | ||
} |