I have a model named Layer.cs and it has a property named Geometry like:
public NetTopologySuite.Geometries.Geometry Geometry { get; set; }
I want to convert a sample GeoJson file (you can find it HERE) to feature collection (NetTopologySuite.Features.FeatureCollection):
// create NetTopology JSON reader
var reader = new NetTopologySuite.IO.GeoJsonReader();
// pass geoJson's FeatureCollection to read all the features
var featureCollection = reader.Read<NetTopologySuite.Features.FeatureCollection>(josnData);
and then save it to Layer.Geomerty using:
layer.Geometry =
NetTopologySuite.Geometries.Geometry.DefaultFactory.CreateGeometryCollection(featureCollection.Select(c => c.Geometry).ToArray());
or
layer.Geometry =
NetTopologySuite.Geometries.Geometry.DefaultFactory.BuildGeometry(featureCollection.Select(c => c.Geometry));
but after calling save change (in both situations) I got the fallowing error:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 3 ("@p2"): The supplied value is not a valid instance of data type geography. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
Is there any clean solution to save a GeoJson file as NetTopologySuite.Geometries.Geometry using EF Core 5?