日期:2014-05-16  浏览次数:20593 次

f_geolatlng.STDistance(geography::Point(@lat,@lng, 4326))怎解释
f_geolatlng.STDistance(geography::Point(@lat,@lng, 4326)) 这个怎么解释?急
------解决方案--------------------
空间数据库 是从某处到某处的距离。
------解决方案--------------------
@lat  --维度
@lng  --经度


------解决方案--------------------
这个geography::Point(@lat,@lng, 4326)是构造一个经纬度

然后和f_geolatlng字段的值,通过函数STDistance,来计算两个经纬度之间的,距离
------解决方案--------------------
可以看看这个例子:
--1.空间数据
with Geo
as
(
select id,
       lon,
       lat,
       geography::Parse('POINT('+lon+space(1)+lat+')') as g       
from 
(
select 1 as id,'-16.96732' as lon,'36.943' as lat
union all
select 1,'-16.58963','36.943'
       
)a
where lon is not null and
      lat is not null
)


--2.计算坐标之间的距离
select 
       s.ID,
       g.STDistance(geography::Parse('POINT('+r.LON+SPACE(1)+r.LAT+')'))
from Geo s
inner join 
(
select 1 as id,'-116.26598' as lon,'39.27763' as lat
union all
select 1,'-16.32683','36.94673'
) r
        on s.ID  = r.ID


--3.建立有空间数据的表
create table x
(
v int not null identity(1,1) primary key,
geog geography not null,
geogWKT as geog.STAsText()
)


--4.添加空间数据
insert into x(geog)
values(geography::Parse('POLYGON(
                                  (-93.123 36.943,
                                   -93.126 36.953,
                                   -94.129 36.986,
                                   -93.123 36.943)
                                 )'
                       )
         ),   --多边形,开始坐标和结束坐标必须相同,注意polygon中必须包含2层括号,否则报错
       
       (geography::Parse('POINT(-93.123 36.943)')),    --点坐标
       
       (geography::Parse('LINESTRING(-93.123