如何通过两对拉长的方式创建地理对象?

时间:2014-04-29 19:29:58

标签: tsql spatial

我是第一次尝试T-SQL的空间类型而问题是我不知道如何验证点属于由两对点定义的圆(lat1,long1; lat2,long2)

我尝试创建地理对象:

declare @p1 geography = geography::STGeomFromText('POINT(51,067222 -114,110043)',4326);

这些代码都不起作用:

声明@ p1 geography = geography :: STGeomFromText('POINT(51,067222 -114,110043)',4326); 声明@ p2 geography = geography :: STGeomFromText('POINT(51,100004 -113,850491)',4326);

declare @g, @g2 Geometry
set @g = 'Point(51,067222 -114,110043)';
set @g2 = 'Point(51,100004  -113,850491)';
select @g.STBuffer(@g2)

但没有成功。

请不要杀我,我是第一次尝试;)

2 个答案:

答案 0 :(得分:0)

最终找到了答案。 (注意:STContains仅适用于MS SQL Server 2012或更高版本)

-- First point
declare @p1 geography = geography::STGeomFromText('POINT(-114.110043 51.067222)', 4326);

-- Second point
declare @p2 geography = geography::STGeomFromText('POINT(-113.850491 51.100004)', 4326);

-- Find the distance between points in meters
declare @distanceInMeters float = @p1.STDistance(@p2);

-- Create circle geography object
declare @cicleGeography geography = @p1.STBuffer(@distanceInMeters)


declare @p3 geography = geography::STGeomFromText('POINT(-112.850491 51.100004)', 4326);

-- Returns true if the third point is inside the circle
select Id, @cicleGeography.STContains(@p3)

非常简单:)

答案 1 :(得分:0)

很高兴你找到了自己的答案。作为替代方案,您还可以使用STIntersects()或STWithin()。为了进一步阅读/学习,我还使用了一种替代方法,使用纬度/长期订单来创建点数。

-- First point
declare @p1 geography = geography::Point(51.067222, -114.110043, 4326);

-- Second point
declare @p2 geography = geography::Point(51.100004, -113.850491, 4326);

-- Find the distance between points in meters
declare @distanceInMeters float = @p1.STDistance(@p2);

-- Create circle geography object
declare @cicleGeography geography = @p1.STBuffer(@distanceInMeters)


declare @p3 geography = geography::Point(51.100004, -112.850491, 4326);

-- Returns true if the third point is inside the circle
select @id, @cicleGeography.STIntersects(@p3)

-- OR Alternatively
select @id, @cicleGeography.STWithin(@p3)
相关问题