Google App Engine 地理哈希
我正在使用 GWT 和 App Engine 编写一个 Web 应用程序。我的应用程序需要根据纬度、经度发布和查询项目。
由于谷歌的分布式数据库设计,你不能简单地查询一组不等式。相反,他们建议进行地理哈希。本页描述了该方法。
http://code.google.com/appengine/articles/geosearch.html
本质上,您预先计算一个边界框,以便您可以查询已用该边界框标记的项目。
这个过程中有一部分我不明白。 “切片”属性是什么意思?
感谢您的帮助!
I am writing a web application using GWT and App Engine. My application will need to post and query items based on their latitude, longitude.
As a result of google's distributed database design you can't simple query a set of inequalities. Instead they suggest doing geohashing. The method is described on this page.
http://code.google.com/appengine/articles/geosearch.html
Essentially you pre compute a bounding box so that you can query items that have been tagged with that bounding box.
There is one part of the process that I don't understand. What does the "slice" attribute mean?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
有关 Geomodel 的完整 Java 移植,请参阅 http://code.google.com/p/javageomodel/ 。
有一个演示课程可以向您解释如何使用它。
For a complete java portage of Geomodel, please see http://code.google.com/p/javageomodel/.
There is a demo class to explain you how to use it.
您可能对 GeoModel 开源项目感兴趣,而不是自己实现 geohash,该项目实现了Google App Engine 上类似 geohash 的系统。您无需了解所有细节,只需导入该库并进行诸如
proximity_fetch()
和bounding_box_fetch()
之类的调用即可。这篇最新文章介绍了它的工作原理并提供了使用它的示例。
Rather than implementing the geohash yourself, you might be interested in the GeoModel open source project that implements a geohash-like system on Google App Engine. Rather than understanding all the details, you can just import this library and make calls like
proximity_fetch()
andbounding_box_fetch()
.This more recent article describes how it works and provides an example that uses it.
您可以使用框西北角的坐标以及两个参数来定义边界框,而不是使用 4 个坐标(最小和最大纬度、最小和最大经度)来定义边界框:分辨率和切片。
分辨率定义了框的比例,它被实现为小数点以下的位数。
切片是盒子的宽度和高度,使用最低有效数字作为单位。
geobox.py 中的注释对此进行了更多解释详细信息,有很好的例子:
Instead of defining a bounding box with 4 coordinates (min and max latitude, min and max longitude), you can define it with the coordinates of the North-West corner of the box, and two parameters : resolution and slice.
The resolution defines the scale of the box, it is implemented as the number of figures below the decimal-point.
The slice is the width and height of the box, using the least significant figure as its unit.
The comments in geobox.py explain this in more details, with good examples :
我正在开发一个 GWT/GAE 项目,并且遇到了同样的问题。我的解决方案是使用 Geohash 类,我对其进行了稍微修改以使其适合 GWT。这非常适合我的邻近搜索需求。
如果您从未见过 Geohashes 的实际应用,请查看 Dave Troy 的 JS 演示页面。
I'm working on a GWT/GAE project and had the same problem. My solution was to use a Geohash class that I modified slightly to be GWT-friendly. It's great for my needs of proximity searches.
If you've never seen Geohashes in action, check out Dave Troy's JS demo page.
在 App Engine 中进行地理空间搜索的另一种方法是搜索 Api。您无需担心地理散列或实施细节,并且您将能够搜索靠近地理点的元素。
https://developers.google.com/appengine/docs/python /search/overview#Performing_Location-Based_Searches
An alternative to do geo spatial searches in App Engine is the Search Api. You won't need to worry about geohashing or implementation details, and you'll be able to search for elements close to geo point.
https://developers.google.com/appengine/docs/python/search/overview#Performing_Location-Based_Searches
我正在使用 geohashing 开发一个 GAE 项目,这个 python 库为我解决了这个问题: http:// /mappinghacks.com/code/geohash.py.txt
I was working on a GAE project with geohashing and this python library did the trick for me: http://mappinghacks.com/code/geohash.py.txt
我还需要 Java 版本的 GeoModel。我之前使用过 Geohash,它允许我获取给定边界框中的位置。但是在排序方面存在相当大的限制:为了让 BigTable 接受像 geohash > 这样的过滤器, '" + 左下 + "' &&地理哈希< '" + topRight + "'",您还必须按
geohash
对列表进行排序,这使得无法按其他条件对其进行排序(特别是如果您想使用分页)同时,除了 Java 代码之外,我想不出一种按距离(从给定的用户位置,即边界框的中心)对结果进行排序的解决方案。 由于这些问题,我不得不使用不同的方法,而 GeoModel/Geoboxes 似乎就是这样,我将 Python 代码移植到了 Java,结果很好! :
I was also in need of a Java version of GeoModel. I was working with Geohash before, which allowed me to fetch locations in a given bounding box. But there are considerable limitations to this when it comes to sorting: in order to get BigTable to accept a filter like
geohash > '" + bottomLeft + "' && geohash < '" + topRight + "'"
, you have to order the list bygeohash
as well, which makes it impossible to sort it by other criteria (especially if you want to use pagination). At the same time, I just can't think of a solution to sort the results by distance (from a given user-position, i.e. the center of the bounding box), other than in Java-code. Again, this will not work if you need to have pagination.Because of these problems I had to use a different approach, and GeoModel/Geoboxes seemed to be the way. So, I ported the Python-code to Java and it's just working fine! Here is the result:
抱歉回复晚了,但我有一段时间没有返回此页面了。使用 Geobox 方法的 GeoDao 实现可能如下所示:
sorry for the late answer, but I didn't return to this page for some time. A GeoDao implementation using the Geobox approach could look like this: