python - GeoModel with Google App Engine - 查询

标签 python google-app-engine geolocation geospatial

我正在尝试使用 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/

相关文章:

python - Discord.py discord.NotFound 异常

python - 在 QStyledItemDelegate 中使用信号 closeEditor 的正确方法?

ruby-on-rails - 使用 HTML5 地理定位获取用户位置并保存到数据库的 Rails 应用程序

javascript - iOS6 Mobile Safari : Accuracy and update periods of geolocation. watchPosition

python - 拆分列表列表

定义 __init__ 辅助方法的 Pythonic 方法?

python - Google 应用引擎静态文件处理程序示例

spring-boot - Google App Engine 中的 Spring Boot 应用程序无法连接到 Cloud SQL

java - 如何在重建时不丢失本地 GAE 数据存储中的数据

android - android 上的 javascript 地理定位在离线模式下不起作用