python - 寻找交叉点

标签 python performance algorithm optimization localization

假设存在数百万个宽度不超过 5 公里的可变尺寸的潜在重叠边界框。

使用参数 findIntersections(Longitude,Latitude,Radius) 创建一个快速函数,输出是这些边界框 ID 的列表,其中每个边界框原点位于函数参数维度的周长内。

如何优雅地解决这个问题?

最佳答案

这通常使用 R-tree 来完成数据结构

像 mysql 或 postgresql 这样的数据库具有 GIS 模块,这些模块在底层使用 r 树来快速检索 map 上某个点附近一定范围内的位置。

来自http://en.wikipedia.org/wiki/R-tree :

R-trees are tree data structures that are similar to B-trees, but are used for spatial access methods, i.e., for indexing multi-dimensional information; for example, the (X, Y) coordinates of geographical data. A common real-world usage for an R-tree might be: "Find all museums within 2 kilometres (1.2 mi) of my current location".

The data structure splits space with hierarchically nested, and possibly overlapping, minimum bounding rectangles (MBRs, otherwise known as bounding boxes, i.e. "rectangle", what the "R" in R-tree stands for).

Priority R-Tree (PR-tree)是一个变体,其最大运行时间为:

"O((N/B)^(1-1/d)+T/B) I/Os, where N is the number of d-dimensional (hyper-)
rectangles stored in the R-tree, B is the disk block size, and T is the output
size."

实际上,大多数实际查询的平均案例运行时间要快得多。

仅供引用,除了发布的其他很棒的代码之外,还有一些很酷的东西,例如 SpatiaLiteSQLite R-tree module

关于python - 寻找交叉点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2062325/

相关文章:

algorithm - 优化功能以将圆放置在不与其他圆重叠的位置

python - 关于 tkinter 中绑定(bind)标签的基本查询

python - 如何使用 groupby 计算数据框中先前使用的产品数量?

python - “SQLite”数据库被锁定错误

performance - 通过最小化着色器/状态更改来优化 WebGL 性能的指南

java - 如何实现滑动窗口或者减少这些嵌套循环?

python - Python 中的 xlsxwriter 库突然变得很慢

android - 将 36 MB JSON 文件写入 Realm 数据库时 UI 被阻塞,因此无法显示进度

android - RecyclerView onMeasure 性能问题

c# - 为什么此页面保持为零?这是范围/托管/引用/等吗?问题?