开发者

Python GeoModel alternative

开发者 https://www.devze.com 2023-01-22 00:13 出处:网络
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 s开发者_如何学Pythonlow ( > 1.5s i

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 s开发者_如何学Pythonlow ( > 1.5s in some cases). Does anyone have any suggestions?

Thanks!


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


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.


I can't point you to an existing library that has better performance, but as I recall, GeoModel is open source and the code isn't difficult to understand. We found that we could make some speed improvements by adjusting the code to fit our scenario.

For example, if you don't need nearest-n, you just need X results from within a particular bounding box or radius, you can probably improve GeoModel's speed, as GeoModel has to currently get every record in the appropriate geohash and then sorts for closest in memory. (Details of that implementation left as an exercise for the reader.)

You might also consider tuning how many levels of geohash you're using. If you have a lot of dense data and are querying over small areas, you might considerably increase performance by keeping 16 levels instead of 8 or 12.

(I'm not looking at the GeoModel source right now but recalling when I last used it several months ago, so take this with a grain of salt and dive into the source code yourself.)

0

精彩评论

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