有效存储和查询GPS坐标 [英] Storing and Querying GPS Coordinates Effectively

查看:194
本文介绍了有效存储和查询GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个GPS坐标的大型数据库,可以通过说返回[这个坐标]内n米内的所有坐标。

I want to create a large database of GPS coordinates that can be queried by saying "Return all coordinates that are within 'n' metres of [this coordinate]".

我需要它尽可能高效,所以循环遍历数据库中的所有坐标,并计算坐标是否在n米内不会是一个所需的解决方案。

I need it to be as efficient as possible so looping through all the coordinates in the database and calculating whether a coordinate is within 'n' metres wouldn't be a desired solution.

有更容易的解决方案吗?

Is there an easier solution?

感谢

推荐答案

我通常使用lat / lon做这种查询。使用球面几何体,您可以围绕特定点放置边界框。例如,假设你有一个点(X,Y),你想要所有的坐标在1英里(转换为米,我将留下作为一个练习为读者)。您可以确定(X-1,Y-1),(X + 1,Y + 1)的边界框。然后使用BETWEEN运算符(SELECT foo FROM bar WHERE LAT BETWEEN X-1 AND X + 1 AND LON BETWEEN Y-1 AND Y + 1)查询点数据库。然后你将你的细节距离计算包围边界的边界框。

I typically do this sort of query using lat/lon. Using spherical geometry, you can put a bounding box around a specific point. For example, say you have a point (X,Y) that you want all coordinates within 1 mile (conversion to meters I'll leave as an exercise for the reader). You can determine a bounding box of (X-1,Y-1),(X+1,Y+1). Then you query your points database using the BETWEEN operator (SELECT foo FROM bar WHERE LAT BETWEEN X-1 AND X+1 AND LON BETWEEN Y-1 AND Y+1). Then you do your detail distance calculation to "round the corners" of your bounding box.

注意,经度线在球体顶部更接近,所以你会得到偏离的结果离你更远的赤道。但它仍然可以快速过滤结果集。

The caveat is that longitude lines are closer together at the top of the sphere, so you'll get skewed results the further away you are from the equator. But it still serves to quickly filter down your results sets.

Google大圆距离用于计算。

Google "Great Circle Distance" for the calculations.

EDIT:每英里有0.167469度的经度(实际范围为0.167469到0.014564),每英里的纬度为0.014483度。所以你的边框是(lat - (miles * 0.014483),lon - (miles * 0.167469)),(lat +(miles * 0.014483),lon +(miles * 0.167469))

There are 0.167469 degrees of longitude per mile (it actually ranges from 0.167469 to 0.014564), and 0.014483 degrees of latitude per mile. So your bounding box is (lat - (miles * 0.014483), lon - (miles * 0.167469)), (lat + (miles * 0.014483), lon + (miles * 0.167469))

这篇关于有效存储和查询GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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