forked from NetTopologySuite/NetTopologySuite.IO.GeoJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect the
PrecisionModel
grid when serializing coordinates. (NetT…
- Loading branch information
Showing
5 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
test/NetTopologySuite.IO.GeoJSON4STJ.Test/Issues/Issue135.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 @@ | ||
using NetTopologySuite.Geometries; | ||
using NetTopologySuite.IO.Converters; | ||
using NetTopologySuite.IO.GeoJSON4STJ.Test.Converters; | ||
using NUnit.Framework; | ||
using System.Text.Json; | ||
|
||
namespace NetTopologySuite.IO.GeoJSON4STJ.Test.Issues | ||
{ | ||
internal class Issue135 : SandDTest<Geometry> | ||
{ | ||
[Test, GeoJsonIssueNumber(135)] | ||
public void TestOutputPrecision() | ||
{ | ||
var coords = new[] | ||
{ | ||
new Coordinate(0.001, 0.001), | ||
new Coordinate(10.1, 0.002), | ||
new Coordinate(10, 10.1), | ||
new Coordinate(0.05, 9.999), | ||
new Coordinate(0.001, 0.001) | ||
}; | ||
var factory = new GeometryFactory(new PrecisionModel(10), 4326); | ||
var polygon = factory.CreatePolygon(coords); | ||
|
||
string json = JsonSerializer.Serialize(polygon, new JsonSerializerOptions | ||
{ | ||
ReadCommentHandling = JsonCommentHandling.Skip, | ||
Converters = | ||
{ | ||
new GeoJsonConverterFactory(factory) | ||
} | ||
}); | ||
|
||
Assert.That(json, Is.EqualTo("{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[10.1,0],[10,10.1],[0.1,10],[0,0]]]}")); | ||
} | ||
} | ||
} |