NetTopologySuite.IO.GeoJSON icon indicating copy to clipboard operation
NetTopologySuite.IO.GeoJSON copied to clipboard

Serializer ignores the PrecisionModel of geometries (STJ)

Open MizardX opened this issue 1 year ago • 1 comments

This is very similar to #27, but now for System.Text.Json.

Example:

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)
};

// Creating the polygon with PrecisionModels.Fixed
var polygon = GeometryFactory.Fixed.CreatePolygon(coords);

var str = polygon.ToString();
// The precision is one decimal place as expected
// POLYGON ((0 0, 10.1 0, 10 10.1, 0.1 10, 0 0))

var json1 = JsonSerializer.Serialize(polygon, new JsonSerializerOptions
{
	Converters = { new GeoJsonConverterFactory() }
});
// The precision is ignored
// {"type":"Polygon","coordinates":[[[0.001,0.001],[10.1,0.002],[10.0,10.1],[0.05,9.999],[0.001,0.001]]]}


var json2 = JsonSerializer.Serialize(polygon, new JsonSerializerOptions
{
	Converters = { new GeoJsonConverterFactory(GeometryFactory.Fixed) }
});
// The precision is ignored
// {"type":"Polygon","coordinates":[[[0.001,0.001],[10.1,0.002],[10.0,10.1],[0.05,9.999],[0.001,0.001]]]}

NetTopologySuite.IO.GeoJSON4STJ version: 4.0.0

MizardX avatar Oct 23 '23 17:10 MizardX

When serializing, it supports setting decimal places, which has a significant impact on the length of the result

gitlsl avatar Mar 26 '24 01:03 gitlsl