使用Google App Engine的GeoModel - 查询

Sha*_*ram 5 python google-app-engine geolocation geospatial

我正在尝试使用GeoModel python模块快速访问我的Google App Engine应用程序的地理空间数据.对于我遇到的问题,我只有一些一般性问题.有两个主要方法,proximity_fetch和bounding_box_fetch,可用于返回查询.它们实际上返回一个结果集,而不是一个过滤的查询,这意味着你需要在传递之前完全准备一个过滤的查询.它还限制你迭代查询集,因为结果被提取,你没有在fetch中输入偏移量的选项.

如果没有修改代码,任何人都可以推荐一个解决方案来指定查询的偏移量吗?我的问题是我需要针对变量检查每个结果以查看是否可以使用它,否则将其丢弃并测试下一个.我可能遇到需要进行额外提取的情况,但是从偏移量开始.

sah*_*hid 2

您还可以直接使用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]
Run Code Online (Sandbox Code Playgroud)