spatial-index - 哪个 NetTopologySuite 索引最适合包含和排除矩形搜索
问题描述
我有以下问题:大量的点和大量的查询需要尽可能快地提供包含矩形(红色)和外部排除矩形(绿色)的任何点。由于点的数量很大并且矩形可以有各种大小,因此最好使用一些空间索引,但据我所知, NetTopologySuite.Index中的所有查询函数都返回包含所有结果的列表,我需要任何单个结果等等当带有许多点的大矩形出现时,查询太昂贵了。
我是否错过了一些可以解决我的问题的空间索引?或者一些快速解决问题的好方法?我可以使用访问者,但他们会针对每个节点进行评估,我可以在找到元素时使用异常来突破,但这看起来很难看。
解决方案
IItemVisitor{T}
您可以使用排除与绿色矩形相交的项目的自定义查询索引。沿着这些思路:
/// <summary>
/// Item visitor that specifically excludes a predefined area.
/// </summary>
/// <typeparam name="T">The type of the items to visit</typeparam>
public class ExcludingItemVisitor<T> : IItemVisitor<T> where T:Geometry
{
private readonly Envelope _exclude;
private readonly List<T> _items = new List<T>();
/// <summary>
/// Initialize with <paramref name="exclude"/>
/// </summary>
/// <param name="exclude"></param>
public ExcludingItemVisitor(Envelope exclude)
{
_exclude = exclude;
}
/// <inheritdoc cref="IItemVisitor{T}.VisitItem"/>>
public void VisitItem(T item)
{
// If we have no intersection with _exclude, add it.
if (!_exclude.Intersects(item.EnvelopeInternal))
_items.Add(item);
}
/// <summary>
/// Get a value indicating the gathered items
/// </summary>
public IList<T> Items => _items;
}
推荐阅读
- java - 有没有办法在 Windows 上的 Eclipse 中暂停/恢复正在运行的 Java 程序的执行?
- bootstrap-4 - 如何为导航品牌设置背景颜色?
- python - 从熊猫中的字符串中提取最多三个数字
- javascript - 自定义 HTML 元素不会对属性更改做出反应
- javascript - 防止在 Firefox 中拖动图像
- ios - Kotlin 数据类型和 Swift 数据类型的映射和使用
- android - 使用导航组件时,如何在运行时为通过导航视图菜单访问的目的地设置参数?
- python - Kivy & Python:如何在一个应用程序运行期间多次用图像填充画布?
- c# - 如何在点后返回带有 2 个零的双整数?
- python - conda 包列表中的所有这些版本是什么?