我正在尝试使用 GeoModel python 模块快速访问我的 Google App Engine 应用程序的地理空间数据。 对于我遇到的问题,我只有几个一般性问题。 有两种主要方法,proximity_fetch 和 bounding_box_fetch,您可以使用它们来返回查询。它们实际上返回的是结果集,而不是过滤查询,这意味着您需要在将过滤查询传入之前对其进行充分准备。它还限制您迭代查询集,因为结果已获取,而您没有在提取中输入偏移量的选项。
如果不修改代码,谁能推荐一种在查询中指定偏移量的解决方案?我的问题是我需要根据变量检查每个结果以查看是否可以使用它,否则将其丢弃并测试下一个。我可能会遇到需要额外获取数据但从偏移量开始的情况。
最佳答案
您还可以直接使用模型的 location_geocells
。
from geospatial import geomodel, geocell, geomath
# query is a db.GqlQuery
# location is a db.GeoPt
# A resolution of 4 is box of environs 150km
bbox = geocell.compute_box(geocell.compute(geo_point.location, resolution=4))
cell = geocell.best_bbox_search_cells (bbox, geomodel.default_cost_function)
query.filter('location_geocells IN', cell)
# I want only results from 100kms.
FETCHED=200
DISTANCE=100
def _func (x):
x.dist = geomath.distance(geo_point.location, x.location)
return x.dist
results = sorted(query.fetch(FETCHED), key=_func)
results = [x for x in results if x.dist <= DISTANCE]
关于python - GeoModel with Google App Engine - 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2248341/