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

查看:13
本文介绍了有效存储和查询 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 "Great Circle Distance" for the calculations.

每英里有 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天全站免登陆