Search code examples
pythongoogle-app-enginegoogle-cloud-datastoregisgeohashing

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!


Solution

  • 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