【发布时间】:2016-01-07 11:28:01
【问题描述】:
我创建了一个函数来返回 MS-SQL 中多点地理字段中的点字符串。我想知道是否有更好的方法来做到这一点?我想要的是将点列表作为纬度/经度坐标提供给不使用 SQL 地理数据类型(他们使用 SQL Lite)的外部客户端。
Create FUNCTION [dbo].GetLatLongForPolygon
(
@Perimeter GEOGRAPHY
)
RETURNS Varchar(max)
AS
BEGIN
declare @NumPoints as Int
declare @OutputString as varchar(max)
declare @latpoint as varchar(max)
declare @longpoint as varchar(max)
set @NumPoints = @Perimeter.STNumPoints()
while @NumPoints >0
begin
set @LatPoint = @Perimeter.STPointN(@NumPoints).Lat
set @longpoint = @Perimeter.STPointN(@NumPoints).Long
set @OutputString = concat (@OutputString, '(' , @latpoint, ',', @longpoint , '), ')
set @NumPoints = @NumPoints -1
End
RETURN left (@OutputString, len(@outputstring)-1)
GO
【问题讨论】: