/// <summary> /// Inserts a node into the tree using <see cref="EntryStrategy"/> /// </summary> /// <param name="key">Key for the geometry</param> /// <param name="region">Bounding box of the geometry to enter into the index</param> public virtual void Insert(UInt32 key, SharpMap.Converters.Geometries.BoundingBox region) { RTreeIndexEntry entry = new RTreeIndexEntry(key, region); Node newSiblingFromSplit; EntryInsertStrategy.InsertEntry(entry, Root, _nodeSplitStrategy, Heuristic, out newSiblingFromSplit); // Add the newly split sibling if (newSiblingFromSplit is LeafNode) { if (Root is LeafNode) { LeafNode oldRoot = Root as LeafNode; Root = CreateIndexNode(); (Root as IndexNode).Add(oldRoot); } (Root as IndexNode).Add(newSiblingFromSplit); newSiblingFromSplit = null; } else if (newSiblingFromSplit is IndexNode) // Came from a root split { Node oldRoot = Root; Root = CreateIndexNode(); (Root as IndexNode).Add(oldRoot); (Root as IndexNode).Add(newSiblingFromSplit); } }
/// <summary> /// Searches the tree and looks for intersections with the boundingbox 'bbox' /// </summary> /// <param name="box">Boundingbox to intersect with</param> public virtual List <UInt32> Search(SharpMap.Converters.Geometries.BoundingBox box) { List <uint> objectlist = new List <uint>(); IntersectTreeRecursive(box, Root, objectlist); return(objectlist); }
/// <summary> /// Recursive function that traverses the tree and looks for intersections with a given <see cref="BoundingBox">region</see>. /// </summary> /// <remarks> /// Nothing is added to the list if <paramref name="box"/> equals <see cref="BoundingBox.Empty"/>. /// </remarks> /// <param name="box">Boundingbox to intersect with</param> /// <param name="node">Node to search from</param> /// <param name="list">List of found intersections</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="node"/> is null or if <paramref name="list"/> is null.</exception> protected void IntersectTreeRecursive(SharpMap.Converters.Geometries.BoundingBox box, Node node, List <uint> list) { if (node == null) { throw new ArgumentNullException("node"); } if (list == null) { throw new ArgumentNullException("list"); } if (box == SharpMap.Converters.Geometries.BoundingBox.Empty) { return; } if (node is LeafNode) //Leaf has been reached { foreach (RTreeIndexEntry entry in (node as LeafNode).Entries) { if (entry.Box.Intersects(box)) { list.Add(entry.Id); } } } else if (node is IndexNode) { if (box.Intersects(node.Box)) { foreach (Node child in (node as IndexNode).Children) { IntersectTreeRecursive(box, child, list); } } } else { throw new InvalidOperationException("Unknown node type: " + node.GetType()); } }
public RTreeIndexEntry(UInt32 key, SharpMap.Converters.Geometries.BoundingBox box) { _id = key; _box = box; }