Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python GeoModel alternative

I'm looking for an alternative library for the app engine datastore that will do nearest-n or boxed geo-queries, currently i'm using GeoModel 0.2 and it runs quite slow ( > 1.5s in some cases). Does anyone have any suggestions?

Thanks!

like image 728
Kyle Avatar asked Oct 22 '10 04:10

Kyle


2 Answers

I have a same problem with geomodel. For correct it, i use a resolution of 4 and i use a python sorted and filter.

SEARCHED_LOCATION = db.GeoPt("48.8566667, 2.3509871") # Location of Paris.
DISTANCE = 50000 #Between 10000 and 150000.
MAX_RESULTS = 300

# Resolution '4' is about 150 kilometers i suppose it's a good compromise.                                                                                                                            
bbox = geocell.compute_box(geocell.compute(SEARCHED_LOCATION, resolution=4))
cell = geocell.best_bbox_search_cells(bbox, geomodel.default_cost_function)

query.filter('location_geocells IN', cell)

# Python filters
def _func(x):
  """Private method used to set the distance of the model to the searched location
  and return this distance.
  """
  x.dist = geomath.distance(SEARCHED_LOCATION, x.location)
  return x.dist

results = sorted(query.fetch(MAX_RESULTS), key=_func) # Order the result by distance
results = [x for x in results if x.dist <= DISTANCE]  # Filter the result
like image 101
sahid Avatar answered Oct 09 '22 11:10

sahid


Instead of using the geomodel 0.2.0 release, use the withasync branch (see

http://code.google.com/p/geomodel/source/browse/#svn/branches/withasync). This will let you run the queries in parallel using asynctools, which will be significantly faster for many queries.

Be sure you have asynctools in your app/pythonpath as well.

like image 38
jlivni Avatar answered Oct 09 '22 11:10

jlivni