【问题标题】:Python GeoModel alternativePython GeoModel 替代品
【发布时间】:2011-04-28 23:25:04
【问题描述】:

我正在为应用程序引擎数据存储寻找一个替代库,该库将执行最近 n 或盒装地理查询,目前我使用的是 GeoModel 0.2,它运行速度很慢(在某些情况下 > 1.5 秒)。有人有什么建议吗?

谢谢!

【问题讨论】:

    标签: python google-app-engine google-cloud-datastore gis geohashing


    【解决方案1】:

    不要使用geomodel 0.2.0 版本,而是使用withasync 分支(参见

    http://code.google.com/p/geomodel/source/browse/#svn/branches/withasync)。这将允许您使用 asynctools 并行运行查询,这对于许多查询来说将明显更快。

    确保您的 app/pythonpath 中也有 asynctools。

    【讨论】:

      【解决方案2】:

      我对地理模型有同样的问题。 为了更正它,我使用 4 的分辨率,并使用 python 排序和过滤。

      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
      

      【讨论】:

        【解决方案3】:

        我无法为您指出性能更好的现有库,但我记得,GeoModel 是开源的,代码不难理解。我们发现我们可以通过调整代码以适应我们的场景来提高速度。

        例如,如果您不需要最近 n,您只需要来自特定边界框或半径内的 X 个结果,您可能可以提高 GeoModel 的速度,因为 GeoModel 当前必须在适当的 geohash 中获取每条记录和然后排序在内存中最接近。 (该实现的细节留给读者作为练习。)

        您还可以考虑调整您使用的 geohash 级别。如果您有大量密集数据并在小范围内进行查询,则可以通过保持 16 级而不是 8 或 12 级来显着提高性能。

        (我现在不是在看 GeoModel 源代码,而是回想起几个月前我上次使用它的时间,所以请谨慎对待它并自己深入研究源代码。)

        【讨论】:

          猜你喜欢
          • 2014-05-17
          • 2010-11-29
          • 2017-01-18
          • 2018-08-27
          • 2021-02-11
          • 2023-03-26
          • 2010-12-24
          • 2015-04-29
          • 2013-04-14
          相关资源
          最近更新 更多