在sql中保存地理数据类型

问题描述 投票:0回答:3

我正在尝试使用c#asp将数据添加到sql的地理字段中。净。

添加POINt或LINESTRING时我没有错误,但添加POLYGON时出现以下错误;

  Message: [DataConnection.HandleError]: Query: Proc_CSA_AssetUpdateLocation: caused exception: A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
System.ArgumentException: 24200: The specified input does not represent a valid geography instance.
System.ArgumentException: 
at Microsoft.SqlServer.Types.SqlGeography.ConstructGeographyFromUserInput(GeoData g, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.Parse(SqlString s)

我传递的数据是(例如);

POLYGON((54.40854093377361 -6.197662353515625, 54.422126065167866 -6.212425231933594, 54.43011521616425 -6.164703369140625, 54.41093863702367 -6.128997802734375, 54.40094728183984 -6.150970458984375, 54.40854093377361 -6.197662353515625))

存储过程:

@Name nvarchar(20),
    @ModifiedWhen DateTime,
    @itemGUID UniqueIdentifier,
    @GeoLocs nvarchar(max),
    @Type int

    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    UPDATE dbo.csa_AssetGeoData 
    Set ItemModifiedWhen = @ModifiedWhen,GeoCord = @GeoLocs,GeographyTypeItemID = @Type, Name = @Name
    WHERE ItemGUID = @itemGUID

不幸的是,无论我在哪里,我找不到我的数据错误的原因。

我的问题是可能导致此错误的原因是什么?

如果有必要,我可以提供更多信息,如果这太模糊(没有信息),我很抱歉。

c# sql asp.net .net geography
3个回答
0
投票

您可以尝试传递字符串表示并在脚本中解析它,类似于:

SET @g = geometry::Parse('POLYGON((1 3, 1 3, 1 3, 1 3))');

我从MSDN Polygon页面采取了这一行。


0
投票

好的,我想出来了。当多边形线彼此交叉时,它不喜欢。不知道为什么,但它保存未交叉的,而不是交叉。


0
投票

根据这篇博客,Ring Orientation SQL Spatial MSSQL是左撇子。有很多方法可以检查功能的有效性。这是一个例子

        if (polygon.MakeValidIfInvalid().EnvelopeAngle() > 90)
        {

            region.Shape = polygon.ReorientObject().Serialize().Value;
        }
        else
        {
            region.Shape = polygon.Serialize().Value;
        }

序列化in SQLGeography用于通过网络发送空间数据。因此它将实例转换为可以保存在数据库中的bytes []。

© www.soinside.com 2019 - 2024. All rights reserved.