我需要找到位于给定半径内的点。现在我有两个选择,第一个是为它编写我自己的算法(或使用现有的库)第二个是使用 postgresql earth_box 实用程序,我可以使用存储过程直接从数据库中选择它。在 Web 应用程序的上下文中,两者的优缺点是什么?
最佳答案
我认为在 postgres 中使用 earth_box 过程会更好,原因如下:
- 数据库已经包含数据和使用它的过程
- 数据库服务器,给定一个正确索引的表,应该非常有效地对自己的空间数据执行空间查询
- 使用服务器,无需查询空间信息、将其传输到您处理它的任何地方、创建树结构和其他开销(与第一个项目符号相关)
- 您使用的代码已经存在并且大概已经过全面测试和审查
- 您可以在报告等更多应用程序的其他服务器端 SQL 中重用代码
我肯定会建议首先尝试 earthbox 方法,只有当 earthbox 在性能方面绝对糟糕时才使用自定义解决方案。
这是来自 a blog post you may want to check out 的更简洁的元推理:
[...] the earthbox function allows us to perform a simple compare to find all records in a certain radius. This is done by the function by returning the great circle distance between the points, a more thorough explanation is located at http://en.wikipedia.org/wiki/Greatcircle.
(通过元推理,我的意思是 earthbox 的简单使用使得使用它变得轻而易举。)
关于performance - Scala 与 Earth Box 中基于树的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22369645/