简体   繁体   English

如何将 Microsoft.SqlServer.Types 导入 Microsoft SQL Server 2012?

[英]How to import Microsoft.SqlServer.Types into Microsoft SQL Server 2012?

I just finished importing census block shape files into Microsoft SQL Server 2012 and am now having issues when trying to use some of the geography features (STContains, STWithin, UnionAggregate, etc) on the data I've brought in. I checked the .prj file before importing my .shp files and I'm sure it is geogrpahy and not geometry type.我刚刚将人口普查块形状文件导入 Microsoft SQL Server 2012 中,现在在尝试对我带来的数据使用某些地理特征(STContains、STWithin、UnionAggregate 等)时遇到问题。我检查了 .prj文件之前导入我的 .shp 文件,我确定它是 geogrpahy 而不是几何类型。

This is the example I've been trying, just to test it out (which comes straight from the MSDN website):这是我一直在尝试的示例,只是为了对其进行测试(直接来自 MSDN 网站):

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::Parse('CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (-122.200928    47.454094, -122.810669 47.00648, -122.942505 46.687131, -121.14624 45.786679, -119.119263  46.183634), (-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.200928 47.454094)))');
SET @h = geography::Parse('POINT(-121.703796 46.893985)');

select @g.stcontains(@h)

This is the error I receive:这是我收到的错误:

Msg 6506, Level 16, State 10, Line 6
Could not find method 'stcontains' for type 'Microsoft.SqlServer.Types.SqlGeography' in  assembly 'Microsoft.SqlServer.Types'

I have done some research on the subject and it appears as though I need to install some sort of add on feature.我对该主题进行了一些研究,似乎我需要安装某种附加功能。 I checked my C: folder because I saw a recommendation to install it via Program Files/Microsoft SQL Server/100/SDK/Assemblies/Microsoft.SqlServer.Types.dll but got stumped because I couldn't find an 'Assemblies' folder.我检查了我的 C: 文件夹,因为我看到了通过 Program Files/Microsoft SQL Server/100/SDK/Assemblies/Microsoft.SqlServer.Types.dll 安装它的建议,但因为找不到“Assemblies”文件夹而被难住了。 I also saw a recommendation to download the Microsoft SQL Server 2012 feature pack ( http://www.microsoft.com/en-us/download/details.aspx?id=29065 ) but I wasn't sure what exactly I needed, if that was even the right spot to look.我还看到了下载 Microsoft SQL Server 2012 功能包 ( http://www.microsoft.com/en-us/download/details.aspx?id=29065 ) 的建议,但我不确定我到底需要什么,如果那是正确的看点。

Any help that you may offer would be greatly appreciated.您可能提供的任何帮助将不胜感激。 Thanks in advance.提前致谢。

For a lot of my projects I create a folder at the project level (Visual Studio) called "libraries" where I put DLL's of this nature and other third party stuff.对于我的许多项目,我在项目级别 (Visual Studio) 创建了一个名为“库”的文件夹,我将这种性质的 DLL 和其他第三方内容放在其中。 I don't know if that's standard practice, but everyone I work with has done this for a while and it's worked well in TFS and Subversion before that.我不知道这是否是标准做法,但与我一起工作的每个人都已经这样做了一段时间,并且在此之前它在 TFS 和 Subversion 中运行良好。

Anyway, mine is sitting in this directory (SQL 2012 / Win 7 / 64 bit OS):无论如何,我的就在这个目录中(SQL 2012 / Win 7 / 64 位操作系统):

C:\\Program Files (x86)\\Microsoft SQL Server\\110\\Shared C:\\Program Files (x86)\\Microsoft SQL Server\\110\\Shared

I copy it from that directory to the library folder in my project.我将它从该目录复制到我项目中的库文件夹中。

I've encountered the same issue working with SQL Server 2016 LocalDB:我在使用 SQL Server 2016 LocalDB 时遇到了同样的问题:

Could not find method 'STCrosses' for type 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types'在程序集“Microsoft.SqlServer.Types”中找不到类型“Microsoft.SqlServer.Types.SqlGeography”的方法“STCrosses”

It took me a while to understand that STCrosses is for geometry data type, while for geography I should use STIntersects .我花了一段时间才明白STCrosses是针对几何数据类型的,而对于地理我应该使用STIntersects

The method name is case sensitive and expects STContains rather than stcontains方法名称区分大小写,并且需要 STContains 而不是 stcontains

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::Parse('CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (-122.200928    47.454094, -122.810669 47.00648, -122.942505 46.687131, -121.14624 45.786679, -119.119263  46.183634), (-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.200928 47.454094)))');
SET @h = geography::Parse('POINT(-121.703796 46.893985)');

select @g.STContains(@h)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM