使用 Google App Engine 的 GeoModel - 查询

发布于 2024-08-21 09:38:42 字数 341 浏览 4 评论 0原文

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

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

I'm trying to use GeoModel python module to quickly access geospatial data for my Google App Engine app.
I just have a few general questions for issues I'm running into.
There's two main methods, proximity_fetch and bounding_box_fetch, that you can use to return queries. They actually return a result set, not a filtered query, which means you need to fully prepare a filtered query before passing it in. It also limits you from iterating over the query set, since the results are fetched, and you don't have the option to input an offset into the fetch.

Short of modifying the code, can anyone recommend a solution for specifying an offset into the query? My problem is that I need to check each result against a variable to see if I can use it, otherwise throw it away and test the next. I may run into cases where I need to do an additional fetch, but starting with an offset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情仇皆在手 2024-08-28 09:38:42

您还可以直接使用模型的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]

You can also work directly with the location_geocells of your model.

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]
红颜悴 2024-08-28 09:38:42

没有实际的方法可以做到这一点,因为对 geoquery 的调用会分解为多个数据存储查询,并将这些查询合并到一个结果集中。如果您能够指定偏移量,geoquery 在返回您请求的结果之前仍然必须获取并丢弃所有前 n 个结果。

更好的选择可能是修改 geoquery 以支持游标,但每个查询都必须返回一组游标,而不是单个游标。

There's no practical way to do this, because a call to geoquery devolves into multiple datastore queries, which it merges together into a single result set. If you were able to specify an offset, geoquery would still have to fetch and discard all the first n results before returning the ones you requested.

A better option might be to modify geoquery to support cursors, but each query would have to return a set of cursors, not a single one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文