Python GeoModel替代方案

时间:2010-10-22 04:22:42

标签: python google-app-engine google-cloud-datastore gis geohashing

我正在为app引擎数据存储区寻找替代库,它将执行最近n或盒装地理查询,目前我正在使用GeoModel 0.2并且运行速度非常慢(在某些情况下大于1.5秒)。有没有人有任何建议?

谢谢!

3 个答案:

答案 0 :(得分:6)

我对地理模型有同样的问题。 为了更正,我使用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

答案 1 :(得分:4)

使用withasync分支(参见

),而不是使用geomodel 0.2.0版本

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

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

答案 2 :(得分:2)

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

例如,如果你不需要nearest-n,你只需要在特定的边界框或半径内获得X结果,你就可以提高GeoModel的速度,因为GeoModel目前必须获得相应geohash中的每条记录。然后排序为最接近的内存。 (该实施的细节留给读者练习。)

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

(我现在不是在看GeoModel的来源,而是在回忆几个月前我最后一次使用它的时候,所以请花一点时间来深入了解源代码。)