使用.NET创建sqlGeography LINESTRING

时间:2013-04-17 12:14:07

标签: sql-server gis geospatial sqlgeography

我正在构建一个解析各种外部地图文件格式(即ShapeFiles,MapPoint,KML等)的应用程序,并将这些形状存储在一个集中式数据库中,该数据库将用于中央映射/报告库。我有一个例程,现在有一个由抽象数组点表示的行,我正在尝试将其转换为将存储在我的数据库中的sqlGeography对象(目前是SQL2012 Express)。

这是我的LINESTRING语句的一个例子(存储在字符串strGeo中):

    LINESTRING(41.942587758675 -85.636084221926,41.9425261573997 -85.6360833224383,41.9423450573927 -85.6360807217602,41.9423035553449 -85.6360801225198,41.9421639573891 -85.6360781210972,41.9421098574371 -85.6360773225739,41.9420307561342 -85.6360762213003)

然后我对该字符串(VB.NET)执行此操作

    Dim strSql As New SqlChars(New SqlString(strGeo))
    Dim geo As SqlGeography = SqlGeography.STLineFromText(strSql, 4326)

我已经从SQL Server 2012功能包中添加了对Microsoft.SqlServer.Types的适当引用,但是当我的调试器访问SqlGeography行时,我得到了这个:

    System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial110.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoMarshalData g, Double eccentricity, Boolean forceKatmai, Boolean& result, Boolean& isSmallerThanAHemisphere)
    at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoData& g, Double eccentricity, Boolean forceKatmai)
    at Microsoft.SqlServer.Types.SqlGeography.IsValidExpensive(Boolean forceKatmai)
    at Microsoft.SqlServer.Types.SqlGeography..ctor(GeoData g, Int32 srid)
    at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
    at Microsoft.SqlServer.Types.SqlGeography.STLineFromText(SqlChars lineStringTaggedText, Int32 srid)
    at ShpFileProcessor.Module1.ProcessFile(FileInfo fil) in C:\Users\Chet Cromer\documents\visual studio 2010\Projects\NorthernLights\ShpFileProcessor\ShpFileProcessor\Module1.vb:line 180

我在计算机上的任何地方都找不到SqlServerSpatial110.dll。我安装了SQL Express 2012,可以在SYSTEM32和SYSWOW64中找到SqlerverSpatial.dll,但VS不会让我注册这些文件。

我注意到如果我在LINESTRING中使用两个括号,我会得到一个不同的错误:

    LINESTRING((41.942587758675 -85.636084221926,41.9425261573997 -85.6360833224383,41.9423450573927 -85.6360807217602,41.9423035553449 -85.6360801225198,41.9421639573891 -85.6360781210972,41.9421098574371 -85.6360773225739,41.9420307561342 -85.6360762213003))

    System.FormatException: 24141: A number is expected at position 27 of the input. The input has (41.942587758675.
    at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeDouble()
    at Microsoft.SqlServer.Types.WellKnownTextReader.ParseLineStringText()
    at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
    at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
    at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)
    at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
    at Microsoft.SqlServer.Types.SqlGeography.STLineFromText(SqlChars lineStringTaggedText, Int32 srid)
    at ShpFileProcessor.Module1.ProcessFile(FileInfo fil) in C:\Users\Chet Cromer\documents\visual studio 2010\Projects\NorthernLights\ShpFileProcessor\ShpFileProcessor\Module1.vb:line 180

(在计算字符之前,第27位是第一个lat / lon组合之间的空格)

我希望我的第一个字符串格式是正确的格式,但此时我不确定,而且我不确定如何处理SqlServerSpatial110.dll问题。

有人走过这条路吗?我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

我知道的第二个错误:

LINESTRING((41.942587758675

两个左括号。唯一一次我得到这个错误(“一个数字是预期的”的事情)是当我从拷贝/粘贴中随机有两个开括号。

关于库中的错误,SQL Server Spatial DLL是非托管代码。您可以在此处找到更多信息,但请确保您的项目中具有正确的版本(32/64)并选择“copy to output direct = always”选项。

http://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/