将空间数据发送到C#应用程序:

问题描述:

我可以将空间数据发送到我的应用程序(在C#.NET中)吗?如果是这样,我怎么能实现呢?例如,我在SQL中有以下代码:SET @geom = geometry :: STGeomFromText('POLYGON((3 -6,8 -3,8 2 2,5 5,-2 0,3 -6))',4326如果我将
@geom发送到C#应用程序会发生什么?谢谢,Santosh

Hi, Can I send spatial data to my application (which is in C#.NET)? If so, how can I achieve that? For example I've the following code in SQL: SET @geom = geometry::STGeomFromText('POLYGON((3 -6, 8 -3, 8 2, 2 5, -2 0, 3 -6))', 4326) What happens if I send @geom to C# application? Thanks, Santosh

SQL Server中的空间功能由两个DLL库提供 - Microsoft.SqlServer.Types.dll(托管)和SqlServerSpatial.dll(非托管)。将Microsoft.SqlServer.Types.dll导入到C#项目中,您可以使用SqlGeography / SqlGeometry
类型,其方式与SQL Server中的地理/几何类型完全相同。所以你上面的例子就会变成ie

Spatial functionality in SQL Server is provided by two DLL libraries - Microsoft.SqlServer.Types.dll (managed) and SqlServerSpatial.dll (unmanaged). Import Microsoft.SqlServer.Types.dll into your C# project and you can use the SqlGeography/SqlGeometry type in exactly the same way as the geography/geometry type within SQL Server. So your example above would become i.e.


SqlGeometry geom = SqlGeometry.STGeomFromText(new SqlChars("POLYGON((3 -6, 8 -3, 8 2, 2 5, -2 0, 3 -6))"), 4326);