先看看sql server 2008 spatial的函数定义 http://msdn.microsoft.com/zh-cn/library/bb933917(v=SQL.100).aspx

所有的空间计算是以这些函数为基础的

 

搜索距离内的地理对象(几何形状),其实就是电子地图的"显示视野内 酒店/商场..." 功能, 这里可以有两种方式来实现.

  

 方法1: 使用 STDistance

STDistance(geography 数据类型)

返回一个 geography 实例中的点与另一个 geography 实例中的点之间的最短距离。


语法

.STDistance ( other_geography ) 

 

算法

代码
1 declare @urplace = geometry::STPointFromText('POINT(nnnn mmmm)',4326);
2  
3 select
4   name,lng,lat,location.STDistance(@urplaceas distance
5 from
6   geotable
7 where
8   location.STDistance(@urplace)<1000
9 

 

这个方法计算精度高(STDistance返回精确的距离),但是作为where条件,也因此导致效率低,一般推荐在查询的数据量比较少的情况下(几百)使用

 

方法2:使用STBuffer 

 STBuffer(geography 数据类型)

返回一个地理对象,该对象表示所有与 geography 实例的距离小于或等于指定值的点的并集。


语法


.STBuffer ( distance )

 

算法

1 declare @urplace = geometry::STPointFromText('POINT(nnnn mmmm)',4326);
2 declare @bufArea = @urplace.STBuffer(1000)
3 
4 select
5    name,lng,lat,location.STDistance(@urplaceas distance
6 from
7    geotable
8 where
9   location.Filter(@bufArea= 1

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2021-06-10
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-12-18
  • 2021-08-03
  • 2021-06-23
  • 2022-12-23
  • 2021-06-09
  • 2022-02-27
相关资源
相似解决方案