Home > Database > Mysql Tutorial > 通过区域坐标获取sqlserver中的geometry 的区域范围内的坐标

通过区域坐标获取sqlserver中的geometry 的区域范围内的坐标

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:18:44
Original
2506 people have browsed it

sqlserver目前已经可以支持地理空间字段了,也就是 geometry API地址: http://msdn.microsoft.com/zh-cn/LIBRARY/cc280487.aspx 创建表和geometry字段以及插入点,线,多边形的sql如下: IF OBJECT_ID ( dbo.SpatialTable, U ) IS NOT NULL DROP TABLE dbo.Sp


sqlserver目前已经可以支持地理空间字段了,也就是 geometry 


API地址:

http://msdn.microsoft.com/zh-cn/LIBRARY/cc280487.aspx


创建表和geometry字段以及插入点,线,多边形的sql如下:

IF OBJECT_ID ( 'dbo.SpatialTable', 'U' ) IS NOT NULL 
    DROP TABLE dbo.SpatialTable;
GO

CREATE TABLE SpatialTable 
    ( id int IDENTITY (1,1),
    geom geometry, 
    adress varchar );
GO

INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('POINT (20 180)', 4326));

INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 4326));

INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 4326));
GO
Copy after login


ps: 4326是空间引用标识符 (SRID)    一般写0或者4326



存入表中的geom字段如下:

通过区域坐标获取sqlserver中的geometry 的区域范围内的坐标



查询语句

假如我们在数据库中存了很多坐标点的地址 


选取圆形区域范围的 地址---也就是 圆心到半径范围内的所有点

DECLARE @g geometry;
set @g = geometry::STGeomFromText('POINT(104.12765 30.60445)', 4326)
SELECT address,geom.STY,geom.STX from SpatialTable  where geom.STDistance(@g)

<pre class="brush:php;toolbar:false">
Copy after login

PS:这里diatance的单位是 英里

查询出的结果如图

通过区域坐标获取sqlserver中的geometry 的区域范围内的坐标

选取多边形

DECLARE @g geometry;
set @g = geometry::STGeomFromText('POLYGON ((104.12189573049204 30.608145728994504,104.12223905324595 30.60282680842528,104.13262456655161 30.603122311674902,104.13176625966685 30.610066378528995,104.12189573049204 30.608145728994504,104.12189573049204 30.608145728994504))',4326)
SELECT address  from  SpatialTable
where    geom.STIntersects(@g)=1
Copy after login

查询出的结果如图

通过区域坐标获取sqlserver中的geometry 的区域范围内的坐标






Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template