Python GeoModel 替代方案

发布于 2024-09-29 01:17:15 字数 116 浏览 2 评论 0原文

我正在寻找一个用于应用程序引擎数据存储的替代库,它将执行最近的 n 或盒装地理查询,目前我正在使用 GeoModel 0.2,它运行得很慢(在某些情况下> 1.5 秒)。有人有什么建议吗?

谢谢!

I'm looking for an alternative library for the app engine datastore that will do nearest-n or boxed geo-queries, currently i'm using GeoModel 0.2 and it runs quite slow ( > 1.5s in some cases). Does anyone have any suggestions?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

客…行舟 2024-10-06 01:17:15

我对地理模型也有同样的问题。
为了纠正它,我使用分辨率 4,并使用 python 排序和过滤器。

SEARCHED_LOCATION = db.GeoPt("48.8566667, 2.3509871") # Location of Paris.
DISTANCE = 50000 #Between 10000 and 150000.
MAX_RESULTS = 300

# Resolution '4' is about 150 kilometers i suppose it's a good compromise.                                                                                                                            
bbox = geocell.compute_box(geocell.compute(SEARCHED_LOCATION, resolution=4))
cell = geocell.best_bbox_search_cells(bbox, geomodel.default_cost_function)

query.filter('location_geocells IN', cell)

# Python filters
def _func(x):
  """Private method used to set the distance of the model to the searched location
  and return this distance.
  """
  x.dist = geomath.distance(SEARCHED_LOCATION, x.location)
  return x.dist

results = sorted(query.fetch(MAX_RESULTS), key=_func) # Order the result by distance
results = [x for x in results if x.dist <= DISTANCE]  # Filter the result

I have a same problem with geomodel.
For correct it, i use a resolution of 4 and i use a python sorted and filter.

SEARCHED_LOCATION = db.GeoPt("48.8566667, 2.3509871") # Location of Paris.
DISTANCE = 50000 #Between 10000 and 150000.
MAX_RESULTS = 300

# Resolution '4' is about 150 kilometers i suppose it's a good compromise.                                                                                                                            
bbox = geocell.compute_box(geocell.compute(SEARCHED_LOCATION, resolution=4))
cell = geocell.best_bbox_search_cells(bbox, geomodel.default_cost_function)

query.filter('location_geocells IN', cell)

# Python filters
def _func(x):
  """Private method used to set the distance of the model to the searched location
  and return this distance.
  """
  x.dist = geomath.distance(SEARCHED_LOCATION, x.location)
  return x.dist

results = sorted(query.fetch(MAX_RESULTS), key=_func) # Order the result by distance
results = [x for x in results if x.dist <= DISTANCE]  # Filter the result
债姬 2024-10-06 01:17:15

不要使用 geomodel 0.2.0 版本,而是使用 withasync 分支(请参阅

http://code.google.com/p/geomodel/source/browse/#svn/branches/withasync)。这将允许您使用 asynctools 并行运行查询,这对于许多查询来说将显着加快。

确保您的 app/pythonpath 中也有 asynctools。

Instead of using the geomodel 0.2.0 release, use the withasync branch (see

http://code.google.com/p/geomodel/source/browse/#svn/branches/withasync). This will let you run the queries in parallel using asynctools, which will be significantly faster for many queries.

Be sure you have asynctools in your app/pythonpath as well.

一直在等你来 2024-10-06 01:17:15

我无法向您指出具有更好性能的现有库,但我记得,GeoModel 是开源的,并且代码并不难理解。我们发现可以通过调整代码以适应我们的场景来提高速度。

例如,如果您不需要nearest-n,您只需要特定边界框或半径内的X结果,您可能可以提高GeoModel的速度,因为GeoModel当前必须获取适当的geohash中的每条记录,然后进行排序记忆中最接近的。 (该实现的详细信息留给读者作为练习。)

您还可以考虑调整正在使用的 geohash 级别。如果您有大量密集数据并且正在小范围内查询,则可以通过保留 16 个级别而不是 8 个或 12 个级别来显着提高性能。

(我现在没有查看 GeoModel 源代码,但回想起我上次使用它时的情况)几个月前,所以请对此持保留态度并亲自深入研究源代码。)

I can't point you to an existing library that has better performance, but as I recall, GeoModel is open source and the code isn't difficult to understand. We found that we could make some speed improvements by adjusting the code to fit our scenario.

For example, if you don't need nearest-n, you just need X results from within a particular bounding box or radius, you can probably improve GeoModel's speed, as GeoModel has to currently get every record in the appropriate geohash and then sorts for closest in memory. (Details of that implementation left as an exercise for the reader.)

You might also consider tuning how many levels of geohash you're using. If you have a lot of dense data and are querying over small areas, you might considerably increase performance by keeping 16 levels instead of 8 or 12.

(I'm not looking at the GeoModel source right now but recalling when I last used it several months ago, so take this with a grain of salt and dive into the source code yourself.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文