码迷,mamicode.com
首页 > 其他好文 > 详细

STDistance的使用及geometry和geography的区别

时间:2015-05-26 18:49:58      阅读:789      评论:0      收藏:0      [点我收藏+]

标签:stdistance   geometry   geography   unit   4326   

1、先说说Sql Server中geometry和geography的区别:

        geometry:planar    平面坐标系【supported by SQL Server conforms to the Open Geospatial Consortium (OGC) Simple Features for SQL Specification version 1.1.0.

        geography: terrestrial   地理坐标系【stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates.

        如果要计算两个lat/lon点之间的实际距离就需要将geometry类型转成geography类型,不然结果肯定不正确。

2、geometry转geography的方法:

       geography::STGeomFromText(boundary.ToString(), 4326)

       boundary是geometry类型的,4326是坐标系的参数,4326代表GCS-WGS-1984坐标系,是系统默认的坐标系。

       可以通过这个sql获得系统的坐标系(Sql server中):Select * from sys.spatial_reference_systems where authorized_spatial_reference_id=4326

3、STDistance的用法:

       https://msdn.microsoft.com/zh-cn/library/bb933952(v=sql.110).aspx

       按照里面的例子能够计算出距离,但是如果输入的是经纬度的值,得出的结果总是觉得不对,值比较小,实际上需要按照第二步转化为geography类型再计算就可以了,4326坐标系默认返回距离的单位【unit】是米【meter】。

       STDistance也可以计算点到面的最短距离。          

STDistance的使用及geometry和geography的区别

标签:stdistance   geometry   geography   unit   4326   

原文地址:http://blog.csdn.net/jcx5083761/article/details/46010215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!