在矩形(多边形)中查找sql​​地理点 [英] finding sql geography point within rectangular (polygon)

查看:189
本文介绍了在矩形(多边形)中查找sql​​地理点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在矩形边界内找到纬度和经度的地标时,我遇到了一个有趣的问题. 我相信我的两个点都在矩形边界内.但正如您可以测试自己那样,第一个选择的结果为false而不是true!

I have an interesting/annoying issue with finding lat and long of land marks inside the rectangular boundary. I believe my two points are inside my rectangular boundary. but as you can test yourself the result of the the first select is false instead of true!

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) 

为了给您提供背景,我列出了要加载到Google地图上的地标(纬度,经度)列表.由于地标数量过多,因此我无法一次将所有地标归还.我需要返回用户可见区域中的地标,位于它们的查看边界内.我正在获取Google地图边界的西北(最大纬度,最小长度)和东南(最小纬度,最大长度),并将其发送到我的存储过程中,以返回该边界内的地标列表.但是,如上所述,我遇到了问题,列表中缺少一些地标.

To give you background, I have list of land marks (lat,long) that I want to load on google maps. Since the number of landmarks are too many, I cannot return all of them at once. I need to return the landmarks that are in the areas that are visible to user , in their viewing boundary. I'm getting north west (max lat,min long) and south east (min lat, max long) of google maps boundary and sending it to my stored procedure to return back the list of the land marks within that boundary. However, as I explained above I have issues and some land marks are missing in list.

推荐答案

实际上,地理多边形不是矩形:

Actually, geography polygon isn't rectangle:

如果要使用矩形,则可以使用几何多边形:

If you want rectangle, you can use geometry polygon:

这篇关于在矩形(多边形)中查找sql​​地理点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆