6

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

谢谢!

回答

6

我与geomodel有同样的问题。 为了更正它,我使用了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 
2

我不能指出你现有的库有更好的性能,但我记得,GeoModel是开源的,代码不难理解。我们发现,通过调整代码以适应我们的场景,我们可以提高速度。例如,如果您不需要nearest-n,您只需要在特定的边界框或半径范围内获得X个结果,那么您可能会提高GeoModel的速度,因为GeoModel当前必须获取适当的geohash中的每条记录然后在内存中排序最接近。 (该实现的细节留给读者练习。)

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

(我现在不是在查看GeoModel源,而是回想起当我最后在几个月前使用过,因此请带上一点盐,然后自己下载源代码。)