我试图使用c# asp将数据添加到sql中的地理字段。net开发工具。
当添加POINt或LINESTRING时,我没有错误,但是当添加多边形时,我得到了以下错误;
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))
存储的proc:
@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
不幸的是,无论我在哪里看,我都找不到错误的原因,在我的数据。
我的问题是,是什么导致了这个错误?
我可以提供更多的信息,如果必要,对不起,如果这是太含糊(缺乏信息)。
发布于 2014-09-15 06:41:18
好吧我想明白了。它不喜欢当你的多边形线相交。不知道为什么,但这是拯救未交叉的和不交叉的。
发布于 2014-09-15 06:17:32
您可以尝试传递字符串表示并在脚本中解析它,类似于以下内容:
SET @g = geometry::Parse('POLYGON((1 3, 1 3, 1 3, 1 3))');
我已经从MSDN多边形页面取走了这一行。
发布于 2017-12-26 10:42:52
根据这个博客,环定向SQL空间是左撇子。有许多方法来检查该特性的有效性。下面是一个例子
if (polygon.MakeValidIfInvalid().EnvelopeAngle() > 90)
{
region.Shape = polygon.ReorientObject().Serialize().Value;
}
else
{
region.Shape = polygon.Serialize().Value;
}
在SQLGeography中序列化,用于通过网络发送空间数据。因此,它将一个实例转换为可以在数据库中持久化的bytes[]。
https://stackoverflow.com/questions/25850071
复制