【问题标题】:Export SQL Server geography to kml with altitude将 SQL Server 地理导出到带高度的 kml
【发布时间】:2021-07-24 02:58:21
【问题描述】:

我需要将一堆地理对象导出到 kml,其中包括第三个元素,高度。幸运的是,它可以硬编码为 0。

This tutorial 表示坐标需要采用 lat,long,alt 格式

<coordinates>
    -77.05788457660967,38.87253259892824,100 
    -77.05465973756702,38.87291016281703,100 
    -77.05315536854791,38.87053267794386,100 
    -77.05552622493516,38.868757801256,100 
    -77.05844056290393,38.86996206506943,100 
    -77.05788457660967,38.87253259892824,100
</coordinates>

如何从我的地理对象中提取坐标列表?

是否可以包括注入高度?

【问题讨论】:

  • “lat,long,alt 的格式”不正确,教程/参考说:&lt;coordinates&gt;(required) floating point values for **longitude, latitude, and altitude**. The altitude component is optional. Do not include spaces within a tuple.

标签: sql-server kml sqlgeography


【解决方案1】:

我真正在寻找的部分是 .Lat 和 .Long。它们仅适用于 POINT,而不适用于 POLYGON,因此您必须将 @input 分解为点

这会返回一个 varchar(MAX) 字符串,例如 long,lat,altcr/lf

CREATE FUNCTION [dbo].[uf_ConvertGeographyToCoordinates]
(
    @input geography
)
RETURNS nvarchar(MAX)
AS
BEGIN
    -- Declare the return variable here
    DECLARE @result nvarchar(max) = '' -- Out needs to be not null
    DECLARE @long nvarchar(25)
    DECLARE @lat nvarchar(25)
    DECLARE @alt nvarchar(25)
    DECLARE @altitude nvarchar(1) = '0'
    DECLARE @i int = 1 
    DECLARE @crlf nvarchar(2) = char(13) + char(10)


    WHILE @i <@input.STNumPoints() 
    BEGIN 

        SET @long = ISNULL(LTRIM(STR(@input.STPointN(@i).Long, 25, 8)), 'null_long') 
    
        SET @lat = ISNULL(LTRIM(STR(@input.STPointN(@i).Lat, 25, 8)), 'null_lat') 
    
        SET @alt = ISNULL(@altitude, 'null_alt')

        SET @result = @result + @long + ',' + @lat + ',' + @alt + @crlf

        SET @i = @i + 1; 
    END 

    return @result
END
GO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多