Having trouble serializing NetTopologySuite FeaturesCollection to GeoJSON
Update
GeoJsonSerializer
has been moved to NetTopologySuite.IO.GeoJSON
and now has its own static Create()
method:
/// <summary> /// Factory method to create a (Geo)JsonSerializer /// </summary> /// <remarks>Calls <see cref="GeoJsonSerializer.CreateDefault()"/> internally</remarks> /// <returns>A <see cref="JsonSerializer"/></returns> public new static JsonSerializer Create() { return CreateDefault(); }
Use of the direct constructor has been deprecated:
[Obsolete("Use GeoJsonSerializer.Create...() functions")] public GeoJsonSerializer() : this(Wgs84Factory) { }
The code in the question should now work as expected.
Original Answer
Use the default constructor for the GeoJsonSerializer
class:
var jsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
That attaches a CoordinateConverter
which prevents the problem.
GeoJsonSerializer
does not actually have a static Create()
method, so you are falling back on the base class's JsonSerializer.Create()
. In fact the following would have resulted in a compiler error:
GeoJsonSerializer jsonSerializer = NTS.IO.GeoJsonSerializer.Create();