Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nettopologysuite/nettopologysuite.io.sqlserverbytes
A SQL Server IO module for NTS which works directly with the serialization format
https://github.com/nettopologysuite/nettopologysuite.io.sqlserverbytes
c-sharp csharp dotnet geo library mssql nettopologysuite nts sql-server sqlserver
Last synced: 2 days ago
JSON representation
A SQL Server IO module for NTS which works directly with the serialization format
- Host: GitHub
- URL: https://github.com/nettopologysuite/nettopologysuite.io.sqlserverbytes
- Owner: NetTopologySuite
- License: bsd-3-clause
- Created: 2018-10-04T19:24:27.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-03T22:03:28.000Z (4 months ago)
- Last Synced: 2024-12-21T20:06:01.798Z (2 days ago)
- Topics: c-sharp, csharp, dotnet, geo, library, mssql, nettopologysuite, nts, sql-server, sqlserver
- Language: C#
- Homepage:
- Size: 106 KB
- Stars: 16
- Watchers: 13
- Forks: 12
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NetTopologySuite.IO.SqlServerBytes
A SQL Server IO module for NTS which works directly with the serialization format| License | Actions | NuGet | MyGet (pre-release) |
| ------- | ------ | ----- | ------------------- |
| [![License](https://img.shields.io/github/license/NetTopologySuite/NetTopologySuite.IO.SqlServerBytes.svg)](https://github.com/NetTopologySuite/NetTopologySuite.IO.SqlServerBytes/blob/master/LICENSE) | [![.NET](https://github.com/NetTopologySuite/NetTopologySuite.IO.SqlServerBytes/actions/workflows/dotnet.yml/badge.svg)](https://github.com/NetTopologySuite/NetTopologySuite.IO.SqlServerBytes/actions/workflows/dotnet.yml) | [![NuGet](https://img.shields.io/nuget/v/NetTopologySuite.IO.SqlServerBytes.svg)](https://www.nuget.org/packages/NetTopologySuite.IO.SqlServerBytes/) | [![MyGet](https://img.shields.io/myget/nettopologysuite/vpre/NetTopologySuite.IO.SqlServerBytes.svg?style=flat)](https://myget.org/feed/nettopologysuite/package/nuget/NetTopologySuite.IO.SqlServerBytes) |## Usage
### Reading
Read geography and geometry columns like this.``` csharp
var geometryReader = new SqlServerBytesReader { IsGeography = true };
var bytes = dataReader.GetSqlBytes(columnOrdinal).Value;
var geometry = geometryReader.Read(bytes);
```### Writing
Write parameters like this.``` csharp
var geometry = new Point(-122.129797, 47.640049) { SRID = 4326 };
var geometryWriter = new SqlServerBytesWriter { IsGeography = true };
var bytes = geometryWriter.Write(geometry);
var parameter = command.Parameters
.AddWithValue(parameterName, new SqlBytes(bytes));// TODO: Set these if you're using Microsoft.Data.SqlClient
//parameter.SqlDbType = SqlDbType.Udt;
//parameter.UdtTypeName = "geography";
```## Known limitations
### Validity
SqlServer and NetTopologySuite have a slightly different notion of a geometry's validity. SqlServer stores this
information along with the geometry data and the `SqlServerBytesWriter` uses NetTopologySuite's `Geometry.IsValid` value.
You might get SqlServer geometries that return `STIsValid() = true` but `STIsValidReason() = false`.### Fullglobe
SqlServer geography types include `FULLGLOBE`, basically a polygon where the globe is the outer ring (shell)
and the interior rings (holes) define areas that are excluded. To achive this, SqlServer is rigid about
ring orientations for geographies.
Kind | requested Orientation
--- | ---
outer rings | **counter clockwise**
inner rings | **clockwise**
**This is _currently_ not representable using NetTopologySuite geometries** and the `SqlServerBytesWriter`
throws an `ArgumentException` if writing a geometry is requested that has an exterior ring oriented **clockwise**.#### Measures
SqlServer geography types use the metric system for measures like length, distance and area.
For NetTopologySuite geometries everything is planar and thus all return values are in the unit of the input
coordinates. In case the coordinates are geographic these values are mostly useless.
Furthermore you can easily create buffers of geometries that exceed the extent of a hemisphere. SqlServer rejects these.