如何将浮动纬度和经度值转换为地理类型值?我有@lat
和@lon
个变量。
答案 0 :(得分:18)
使用案例陈述:
CASE
WHEN ((@Latitude IS NOT NULL) AND (@Longitude IS NOT NULL))
THEN geography::Point(@Latitude, @Longitude, 4326)
ELSE NULL
END
或if:
的变体 DECLARE @Location geography = NULL
IF (@Latitude IS NOT NULL AND @Longitude IS NOT NULL)
SET @Location = geography::Point(@Latitude, @Longitude, 4326);
答案 1 :(得分:2)
我自己找到了解决方案:
geography::STPointFromText(
'POINT(' + CAST(@lon AS VARCHAR(20)) + ' ' + CAST(@lat AS VARCHAR(20)) + ')', 4326)