Does anyone know of a way to convert the JSON spit out by Geometry.ToJson to either WKT or SQL Geometry type? I need to store individual shapes in my database, for which the JSON string works great. However, I also need to query the geometry using a stored procedure, so I need to convert it to a SQL Geometry data type.
The following example uses the OPENJSON function that is supported since SQL Server 2016.
I've sourced a low res GeoJSON from https://github.com/johan/world.geo.json to keep this response short. This solution supports but Polygon and MultiPolygon GeoJSON geometry types.
I have posted this to Stack Overflow to increase reach of this discussion: convert geoJson data to sql server spatial data type (GIS)
MakeValid is necessary only for some sources, usually the high res stuff but its wise to leave it in there.
ReorientObject is only necessary for shapes that result in an inverted output, usually this is when the sequence of points is incorrect, so we use the EnvelopeAngle to determine if we should re-orient or not. (Reorient on everything can cause some shapes to become inverted.