GeoModel with Google App Engine - Queries

I am trying to use the python GeoModel module for quick access to geospatial data for my Google App Engine application. I just have a few common questions for the problems I am facing. There are two main methods: proximity_fetch and bounding_box_fetch, which you can use to return requests. They actually return a result set, not a filtered query, which means that you need to fully prepare the filtered query before submitting it. It also limits you to repeating a set of queries, since the results are obtained, and you do not have the ability to enter an offset into the selection.

With the exception of the code change, can anyone recommend a solution for setting the offset in the request? My problem is that I need to check every result against a variable to see if I can use it, otherwise throw it away and test the following. I may encounter cases when I need to make additional sampling, but starting with an offset.

+5
source share
2 answers

You can also work directly with location_geocellsyour 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]
+2
source

, geoquery , . , n , .

, , .

+1

All Articles