Allows you to use SQL Server spatial SqlHierarchy types on a machine without SQL Server installed and decode these UDT types in any .NET Standard client
$ dotnet add package dotMorten.Microsoft.SqlServer.Typesa .NET Standard implementation of the spatial types in Microsoft.SqlServer.Types.
The v1.x and v2.x versions are identical and kept in sync. The only difference is the dependency:
System.Data.SqlClient package.Microsoft.Data.SqlClient package.Input parameter
Assigning SqlGeometry or SqlGeography to a command parameter:
command.Parameters.AddWithValue("@GeographyColumn", mySqlGeography);
command.Parameters["@GeometryColumn"].UdtTypeName = "Geography";
command.Parameters.AddWithValue("@GeographyColumn", mySqlGeometry);
command.Parameters["@GeometryColumn"].UdtTypeName = "Geometry"
The geometry will automatically be correctly serialized.
Reading geometry and geography
Use the common methods for getting fields of specific types:
var geom1 = reader.GetValue(geomColumn) as SqlGeometry;
var geom2 = reader.GetFieldValue<SqlGeometry>(geomColumn);
var geom3 = SqlGeometry.Deserialize(reader.GetSqlBytes(geomColumn)); //Avoids any potential assembly-redirect issue. See https://docs.microsoft.com/en-us/sql/sql-server/install/warning-about-client-side-usage-of-geometry-geography-and-hierarchyid?view=sql-server-2014#corrective-action
The spatial operations like intersection, area etc are not included here. You can perform these as part of your query instead and get them returned in a column.