Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer ignores the PrecisionModel of geometries (STJ) #135

Open
MizardX opened this issue Oct 23, 2023 · 1 comment · May be fixed by #136
Open

Serializer ignores the PrecisionModel of geometries (STJ) #135

MizardX opened this issue Oct 23, 2023 · 1 comment · May be fixed by #136

Comments

@MizardX
Copy link

MizardX commented Oct 23, 2023

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 added a commit to MizardX/NetTopologySuite.IO.GeoJSON that referenced this issue Oct 29, 2023
@MizardX MizardX changed the title Serializer ignores the IPrecisionModel of geometries (STJ) Serializer ignores the PrecisionModel of geometries (STJ) Oct 29, 2023
@gitlsl
Copy link

gitlsl commented Mar 26, 2024

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

MizardX added a commit to MizardX/NetTopologySuite.IO.GeoJSON that referenced this issue Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants