如何根据地理空间数据类型获取长和纬度?



我遇到的问题是我正在尝试根据位置字段获取长值和纬度值,我有地理列,但我总是收到如下所示的错误:

Msg 403,级别 16,状态 1,第 9 行
数据类型的运算符无效。运算符等于等于,类型等于地理。

这基本上是查询:

select Loc.Lat, Loc.Long  from VideoGamesLocation
where  Loc= '0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0'

你们知道如何根据上述查询获取纬度和经度的值吗?

好的。然后转换为geography并使用 STEquals 或其他函数之一进行比较。 EG

drop table if exists VideoGamesLocation
create table VideoGamesLocation(id int, Loc geography)
DECLARE @g geography;   
SET @g = cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0 as geography)
insert into VideoGamesLocation(id, Loc) values (1,@g)

select Loc.Lat, Loc.Long  from VideoGamesLocation
where  1=Loc.STEquals(cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0 as geography))

使用 .STEquals 运算符而不是 = 。 如果相等成立,此函数将返回 1。

还可以使用强制转换函数将"0xE61000.."转换为地理数据类型。

所以,SQL查询应该是: 从视频游戏位置中选择Loc.Lat,Loc.Long 其中 1=Loc.STEquals(cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0 as geography((

最新更新