我有一个有趣/恼人的问题,就是在矩形边界内找到lat和long标记。 我相信我的两点在我的矩形边界内。但是你可以测试自己第一个选择的结果是假的而不是真的!
DECLARE @boundingRect varchar(1000)
DECLARE @maxLat VARCHAR(20)
DECLARE @minLong VARCHAR(20)
DECLARE @minLat VARCHAR(20)
DECLARE @maxLong VARCHAR(20)
set @maxLat ='-36.06631759541187'
set @minLong ='125.23310677812492'
set @minLat ='-44.43329881450396'
set @maxLong='167.04707162187492'
SET @boundingRect = 'POLYGON((' + @minLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @minLat + '))'
DECLARE @Bounds AS Geography =GEOGRAPHY::STPolyFromText(@boundingRect,4326)
DECLARE @point1 AS GEOGRAPHY = GEOGRAPHY::Point(-37.81502, 144.94601, 4326)
DECLARE @point2 AS GEOGRAPHY = GEOGRAPHY::Point(-38.81502, 144.94601, 4326)
SELECT @Bounds.STIntersects(@point1)
SELECT @Bounds.STIntersects(@point2)
为了给你背景,我有一些我想在谷歌地图上加载的地标(lat,long)列表。由于地标的数量太多,我无法立刻归还所有地标。我需要在其查看边界内返回用户可见区域中的地标。我正在向北西(max lat,min long)和google地图边界的东南(min lat,max long)并将其发送到我的存储过程以返回该边界内的地标列表。但是,正如我上面解释的那样,我有问题,列表中缺少一些地标。
答案 0 :(得分:7)
@ point1不相交这可以通过以下方式验证:
DECLARE @boundingRect varchar(1000)
DECLARE @maxLat VARCHAR(20)
DECLARE @minLong VARCHAR(20)
DECLARE @minLat VARCHAR(20)
DECLARE @maxLong VARCHAR(20)
set @maxLat ='-36.06631759541187'
set @minLong ='125.23310677812492'
set @minLat ='-44.43329881450396'
set @maxLong='167.04707162187492'
SET @boundingRect = 'POLYGON((' + @minLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @minLat + '))'
DECLARE @Bounds AS Geography =GEOGRAPHY::STPolyFromText(@boundingRect,4326);
DECLARE @point1 AS GEOGRAPHY = GEOGRAPHY::Point(-37.81502, 144.94601, 4326);
DECLARE @point2 AS GEOGRAPHY = GEOGRAPHY::Point(-38.81502, 144.94601, 4326);
SELECT @Bounds.STIntersects(@point1);
SELECT @Bounds.STIntersects(@point2);
SELECT @point1, 'Point 1'
UNION ALL
SELECT @Point2, 'Point 2'
UNION ALL
SELECT @BoundingRect, 'Rect'
答案 1 :(得分:3)