如何对框搜索的纬度/经度进行编码?
我正在 Google App Engine 上开发一个应用程序,需要找到框中的所有点。
基本的 SQL 搜索是:
最小纬度 <纬度 AND 最大纬度 >纬度和最小经度 <经度 AND 最大经度 >经度
在 Google App Engine 上既低效又被禁止(您不能在 2 个不同的字段上使用不等式)。
因此,我使用分层顺序编码纬度/经度 http://en.wikipedia.org/wiki/Geohash< /a>.
但使用 Geohash 存在一些问题: 是的,它会找到盒子里的所有分数,但它也会找到盒子外的分数。
让我们举个例子:
左下角为(1, 1)的盒子-> geohash1 = s00twy01mtw0
和右上角 (10, 10) -> geohash2 = s1z0gs3y0zh7
将接受点 P,如 (2, 11) -> geohashP = s0rg6k1fye42
因为 geohash1 < geohashP < geohash2
即使P不在盒子里。
知道如何有效地获取框中的所有点(并且仅获取它们)吗?
我现在正在考虑在请求后对额外的错误点进行后处理。
I'm developing an application on Google App Engine and needs to find all the points that are in a box.
A basic SQL search would be:
minlatitude < latitude AND maxlatitude > latitude AND minlongitude < longitude AND maxlongitude > longitude
But, this request is both inefficient and forbidden (you cannot use inequality on 2 different fields) on Google App Engine.
So, I encoded latitude/longitude with hierarchical order http://en.wikipedia.org/wiki/Geohash.
But using Geohash has some issues:
Yes, it will find all your points that are in the box, but it will also find points out-of the box.
Let’s take an example:
A box with a lower-left corner of (1, 1) -> geohash1 = s00twy01mtw0
and a upper right corner (10, 10) -> geohash2 = s1z0gs3y0zh7
will accept point P like (2, 11) -> geohashP = s0rg6k1fye42
because geohash1 < geohashP < geohash2
even if P is not in the box.
Any idea about an efficient way to get all the points that are in the box (and only them)?
I'm now thinking about post-processing the additional wrong points after the request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要重新发明轮子!空间查询是一个棘手的问题,但几个第三方库已经解决了这个问题。其中最好的可能是地理模型库。
Don't reinvent the wheel! Spatial queries are a tough problem, but one that's already been solved by several third-party libraries. The best of those is probably the geomodel library.
地理模型可以完成这项工作。
我将python库移植到java中。
如果有兴趣,请查看:http://code.google.com/p/javageomodel/
Geomodel does the job.
I ported the python library into java.
For those who are interested in, check: http://code.google.com/p/javageomodel/
理论上,您可以使用 Cantor 配对函数 将矩形的四个坐标映射到单个值,但是我不确定是否(容易)可以对这些值进行包含测试。
You can theoretical use Cantor pairing function to map the four coordinates of your rectangle to a single value but I am not sure if it is (easily) possible to perform inclusion test on such values.