开发者

GeoModel with Google App Engine - queries

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.


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]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜