Table of Contents

Class STRtree<TItem>

Namespace
NetTopologySuite.Index.Strtree
Assembly
NetTopologySuite.dll

A query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm. For two-dimensional spatial data.

The STR packed R-tree is simple to implement and maximizes space utilization; that is, as many leaves as possible are filled to capacity. Overlap between nodes is far less than in a basic R-tree. However, the index is semi-static; once the tree has been built (which happens automatically upon the first query), items may not be added.
Items may be removed from the tree using Remove(Envelope, TItem).

Described in: P. Rigaux, Michel Scholl and Agnes Voisard. Spatial Databases With Application To GIS. Morgan Kaufmann, San Francisco, 2002.

Note that inserting items into a tree is not thread-safe. Inserting performed on more than one thread must be synchronized externally.

Querying a tree is thread-safe. The building phase is done synchronously, and querying is stateless.
public class STRtree<TItem> : AbstractSTRtree<Envelope, TItem>, ISpatialIndex<TItem>

Type Parameters

TItem
Inheritance
STRtree<TItem>
Implements
Inherited Members

Constructors

STRtree()

Constructs an STRtree with the default (10) node capacity.

public STRtree()

STRtree(int)

Constructs an STRtree with the given maximum number of child nodes that a node may have.

public STRtree(int nodeCapacity)

Parameters

nodeCapacity int

Remarks

The minimum recommended capacity setting is 4.

STRtree(int, AbstractNode<Envelope, TItem>)

Constructs an AbstractSTRtree with the specified maximum number of child nodes that a node may have, and the root node

public STRtree(int nodeCapacity, AbstractNode<Envelope, TItem> root)

Parameters

nodeCapacity int

The maximum number of child nodes in a node

root AbstractNode<Envelope, TItem>

The root node that links to all other nodes in the tree

STRtree(int, IList<IBoundable<Envelope, TItem>>)

Constructs an AbstractSTRtree with the specified maximum number of child nodes that a node may have, and all leaf nodes in the tree

public STRtree(int nodeCapacity, IList<IBoundable<Envelope, TItem>> itemBoundables)

Parameters

nodeCapacity int

The maximum number of child nodes in a node

itemBoundables IList<IBoundable<Envelope, TItem>>

The list of leaf nodes in the tree

Properties

IntersectsOp

protected override AbstractSTRtree<Envelope, TItem>.IIntersectsOp IntersectsOp { get; }

Property Value

AbstractSTRtree<Envelope, TItem>.IIntersectsOp

Methods

CreateNode(int)

protected override AbstractNode<Envelope, TItem> CreateNode(int level)

Parameters

level int

Returns

AbstractNode<Envelope, TItem>

CreateParentBoundables(IList<IBoundable<Envelope, TItem>>, int)

Creates the parent level for the given child level. First, orders the items by the x-values of the midpoints, and groups them into vertical slices. For each slice, orders the items by the y-values of the midpoints, and group them into runs of size M (the node capacity). For each run, creates a new (parent) node.

protected override IList<IBoundable<Envelope, TItem>> CreateParentBoundables(IList<IBoundable<Envelope, TItem>> childBoundables, int newLevel)

Parameters

childBoundables IList<IBoundable<Envelope, TItem>>
newLevel int

Returns

IList<IBoundable<Envelope, TItem>>

CreateParentBoundablesFromVerticalSlice(IList<IBoundable<Envelope, TItem>>, int)

protected IList<IBoundable<Envelope, TItem>> CreateParentBoundablesFromVerticalSlice(IList<IBoundable<Envelope, TItem>> childBoundables, int newLevel)

Parameters

childBoundables IList<IBoundable<Envelope, TItem>>
newLevel int

Returns

IList<IBoundable<Envelope, TItem>>

GetComparer()

protected override IComparer<IBoundable<Envelope, TItem>> GetComparer()

Returns

IComparer<IBoundable<Envelope, TItem>>

Insert(Envelope, TItem)

Inserts an item having the given bounds into the tree.

public void Insert(Envelope itemEnv, TItem item)

Parameters

itemEnv Envelope
item TItem

IsWithinDistance(STRtree<TItem>, IItemDistance<Envelope, TItem>, double)

Tests whether some two items from this tree and another tree lie within a given distance. IItemDistance<T, TItem> is used as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search.

public bool IsWithinDistance(STRtree<TItem> tree, IItemDistance<Envelope, TItem> itemDist, double maxDistance)

Parameters

tree STRtree<TItem>

Another tree

itemDist IItemDistance<Envelope, TItem>

A distance metric applicable to the items in the trees

maxDistance double

The distance limit for the search

Returns

bool

true if there are items within the distance

NearestNeighbour(Envelope, TItem, IItemDistance<Envelope, TItem>)

Finds the item in this tree which is nearest to the given item, using IItemDistance<T, TItem> as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search.

The query item does not have to be contained in the tree, but it does have to be compatible with the itemDist distance metric.
public TItem NearestNeighbour(Envelope env, TItem item, IItemDistance<Envelope, TItem> itemDist)

Parameters

env Envelope

The envelope of the query item

item TItem

The item to find the nearest neighbour of

itemDist IItemDistance<Envelope, TItem>

A distance metric applicable to the items in this tree and the query item

Returns

TItem

The nearest item in this tree or null if the tree is empty

NearestNeighbour(Envelope, TItem, IItemDistance<Envelope, TItem>, int)

Finds up to k items in this tree which are the top k nearest neighbors to the given item, using itemDist as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search. This method implements the KNN algorithm described in the following paper:

Roussopoulos, Nick, Stephen Kelley, and Fr�d�ric Vincent. "Nearest neighbor queries." ACM sigmod record. Vol. 24. No. 2. ACM, 1995.

The query item does not have to be contained in the tree, but it does have to be compatible with the itemDist distance metric.

If the tree size is smaller than k fewer items will be returned. If the tree is empty an array of size 0 is returned.
public TItem[] NearestNeighbour(Envelope env, TItem item, IItemDistance<Envelope, TItem> itemDist, int k)

Parameters

env Envelope

The envelope of the query item

item TItem

The item to find the nearest neighbours of

itemDist IItemDistance<Envelope, TItem>

A distance metric applicable to the items in this tree and the query item

k int

The maximum number of nearest items to search for

Returns

TItem[]

An array of the nearest items found (with length between 0 and k)

NearestNeighbour(IItemDistance<Envelope, TItem>)

Finds the two nearest items in the tree, using IItemDistance<T, TItem> as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search.

If the tree is empty, the return value is null. If the tree contains only one item, the return value is a pair containing that item. If it is required to find only pairs of distinct items, the IItemDistance<T, TItem> function must be anti-reflexive.
public TItem[] NearestNeighbour(IItemDistance<Envelope, TItem> itemDist)

Parameters

itemDist IItemDistance<Envelope, TItem>

A distance metric applicable to the items in this tree

Returns

TItem[]

The pair of the nearest items or null if the tree is empty

NearestNeighbour(STRtree<TItem>, IItemDistance<Envelope, TItem>)

Finds the two nearest items from this tree and another tree, using IItemDistance<T, TItem> as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search. The result value is a pair of items, the first from this tree and the second from the argument tree.

public TItem[] NearestNeighbour(STRtree<TItem> tree, IItemDistance<Envelope, TItem> itemDist)

Parameters

tree STRtree<TItem>

Another tree

itemDist IItemDistance<Envelope, TItem>

A distance metric applicable to the items in the trees

Returns

TItem[]

The pair of the nearest items, one from each tree or null if no pair of distinct items can be found.

Query(Envelope)

Returns items whose bounds intersect the given envelope.

public IList<TItem> Query(Envelope searchEnv)

Parameters

searchEnv Envelope

Returns

IList<TItem>

Query(Envelope, IItemVisitor<TItem>)

Returns items whose bounds intersect the given envelope.

public void Query(Envelope searchEnv, IItemVisitor<TItem> visitor)

Parameters

searchEnv Envelope
visitor IItemVisitor<TItem>

Remove(Envelope, TItem)

Removes a single item from the tree.

public bool Remove(Envelope itemEnv, TItem item)

Parameters

itemEnv Envelope

The Envelope of the item to remove.

item TItem

The item to remove.

Returns

bool

true if the item was found.

VerticalSlices(IList<IBoundable<Envelope, TItem>>, int)

protected IList<IBoundable<Envelope, TItem>>[] VerticalSlices(IList<IBoundable<Envelope, TItem>> childBoundables, int sliceCount)

Parameters

childBoundables IList<IBoundable<Envelope, TItem>>

Must be sorted by the x-value of the envelope midpoints.

sliceCount int

Returns

IList<IBoundable<Envelope, TItem>>[]