本文介绍了从T-SQL中的点创建地理折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的表模式:
I have a table schema that looks like this:
CREATE TABLE [dbo].[LongAndLats](
[Longitude] [decimal](9, 6) NULL,
[Latitude] [decimal](9, 6) NULL,
[SortOrder] [int] NULL
)
样本数据如下:
如何使用TSQL将这些点转换为地理折线?
How can I convert these points into a geography polyline using TSQL?
推荐答案
请尝试以下操作:(注释:点的顺序对于正确生成线很重要.)
try this:(note: the ordering of the points is important for the line to be generated correctly.)
DECLARE @BuildString NVARCHAR(MAX)
SELECT @BuildString = COALESCE(@BuildString + ',', '') + CAST([Longitude] AS NVARCHAR(50)) + ' ' + CAST([Latitude] AS NVARCHAR(50))
FROM dbo.LongAndLats
ORDER BY SortOrder
SET @BuildString = 'LINESTRING(' + @BuildString + ')';
DECLARE @LineFromPoints geography = geography::STLineFromText(@BuildString, 4326);
SELECT @LineFromPoints
这篇关于从T-SQL中的点创建地理折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!