Create geography polyline from points in T-SQL

前端 未结 1 1477
情歌与酒
情歌与酒 2020-12-19 12:56

I have a table schema that looks like this:

CREATE TABLE [dbo].[LongAndLats](
[Longitude] [decimal](9, 6) NULL,
[Latitude] [decimal](9, 6) NULL,
[SortOrder]          


        
相关标签:
1条回答
  • 2020-12-19 13:02

    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
    
    0 讨论(0)
提交回复
热议问题