Skip to content

Serializer ignores the PrecisionModel of geometries (STJ) #135

@MizardX

Description

@MizardX

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions