1

I work with a SQL Server 2008 R2 and I need convert one column Multipoint to Line. I tried various geographic features, but without success...

For example:

declare @f varchar(max);
declare @g geography;
set @f = (SELECT replace((SUBSTRING(T.ROUTEM.ToString(),11,9999999)),'(','' ) 
          FROM dbo.TRAVELS T WHERE T.ID_TRAVEL = 74063);
set @f = (SELECT replace(@f,')', ''));
set @f = (SELECT 'LINESTRING (' + @f + ')');
set @g = geography::STLineFromText(@f,4326);
select @g;

The return from SQL Server is:

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)*

If someone help me, I would be grateful.

PS: Is there a limit of points for the STLineFromText?

4

2 回答 2

0

我解决了我的问题。CodePlex 存在此包 SQL 空间工具。包上存在 MakeValidValidGeographicFromText() 函数。

了解更多:http ://sqlspatialtools.codeplex.com/wikipage?title=Current%20Contents

于 2013-07-11T20:21:11.570 回答
0

查看传递给 SQL Server 的 LINESTRING WKT 会很有帮助。但是,虽然您的算法将多点转换为线可能在大多数情况下都有效,但它不能保证点的任何顺序,除非您知道多点是以特定方式生成的。因此,可能会生成一个自相交的线串,这将导致此错误。

MakeValid 正在通过移动点为您解决问题,以使线不会自交叉。

关于 LineString 中最大点数的问题,请参阅Sql Server 2008 geography LineString size limits

于 2013-07-11T20:23:31.233 回答