Tsql 如何通过两对长和长创建地理对象?
我第一次尝试T-SQL的空间类型,问题是我不知道如何验证点是否属于由两对点(lat1,long1;lat2,long2)定义的圆 我尝试创建地理对象:Tsql 如何通过两对长和长创建地理对象?,tsql,spatial,Tsql,Spatial,我第一次尝试T-SQL的空间类型,问题是我不知道如何验证点是否属于由两对点(lat1,long1;lat2,long2)定义的圆 我尝试创建地理对象: declare @p1 geography = geography::STGeomFromText('POINT(51,067222 -114,110043)',4326); 这两种代码都不起作用: 声明@p1 geography=geography::stgeomefromtext('POINT(51067222-114110043)'432
declare @p1 geography = geography::STGeomFromText('POINT(51,067222 -114,110043)',4326);
这两种代码都不起作用:
声明@p1 geography=geography::stgeomefromtext('POINT(51067222-114110043)'4326);
声明@p2 geography=geography::stgeomefromtext('POINT(511000004-113850491)'4326)
但是没有成功
请不要杀我,我是第一次尝试;) 最终找到了答案。(注意:STContains仅适用于MS SQL Server 2012或更高版本)
很简单:)很高兴你找到了自己的答案。或者,也可以使用STIntersects()或STWithin()。为了进一步阅读/学习,我还使用了另一种方法,即使用lat/long order创建点
-- 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)
使用
geography
时,最难记住的部分是点被定义为经度,纬度
,因为经度是X轴。至少在美国,我们总是认为coords是“lat/long”,很难忘记它。进一步注意:STContains()
仅在SQL Server 2012及更高版本中可用。我试过2008R2,但失败了。是的,我在Azure上使用了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)
-- 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)