# SpatialTree<T> class

Namespace: [Grasshopper2.Geometry.SpatialTree](https://developer.rhino3d.com/api/gh2/namespace/grasshopper2.geometry.spatialtree.md) · Assembly: [Grasshopper2](https://developer.rhino3d.com/api/gh2/assembly/grasshopper2.md)

```cs
public class SpatialTree<T>
```

Provides a spatial lookup tree for 3d point-like data. This class uses an adaptive octree-subdivision algorithm. If you're dealing with n-dimensional where n != 3, then you can use the SampleSet class in the Grasshopper2.Geometry.Clustering namespace.

**Type parameters:**

- `T`: Type of data to encapsulate.

## Constructors

- [SpatialTree<T>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/ctor.md): (2 overloads) Construct a new empty octree.

## Properties

- [Count](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/count.md): Gets the number of items stored in this tree. Though note some of these may have been removed from the spatial lookup caches and can thus no longer be found.
- [Optimized](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/optimized.md): Gets whether this tree has been optimized.

## Indexers

- [this[]](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/item.md): Gets a specific item in the tree.

## Methods

- [Add](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/add.md): Add a single item to the tree.
- [AddRange](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/addrange.md): Add a collection of items to the tree.
- [Bounds](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/bounds.md): (2 overloads) Gets the bounding box for the entire tree.
- [BuildTree](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/buildtree.md): Ensure the tree has been constructed.
- [Clear](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/clear.md): Remove all items from the tree. Although why you would want to do this instead of just creating just a new spatial tree is unclear.
- [Contains](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/contains.md): Gets whether an item is defined within the tree.
- [Difference](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/difference.md): Compute the difference along the x, y and z axes between two items.
- [Distance](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/distance.md): Compute the distance between two instances.
- [Draw](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/draw.md): Draw all leaf nodes as box corners.
- [FindAbovePlane](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/findaboveplane.md): Find all items above a plane.
- [FindCustom](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/findcustom.md): Perform a custom search.
- [FindInBox](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/findinbox.md): Find all items within a box.
- [FindInSphere](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/findinsphere.md): Find all items within a sphere.
- [ForgetAbout](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/forgetabout.md): Remove an item from the spatial lookup caches. This will prevent the item from being found using a Near or Far search, but it will not remove the item from this collection or affect the indices of other items.
- [FurthestItem](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/furthestitem.md): (2 overloads) Find the nearest item to a search point.
- [FurthestItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/furthestitems.md): (2 overloads) Find the nearest items to a search point.
- [IndexOf](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/indexof.md): Gets the index of a specific item.
- [NearestItem](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/nearestitem.md): (8 overloads) Find the nearest item to a search line.
- [NearestItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/nearestitems.md): (6 overloads) Find the nearest item to a search line.
- [Optimize](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/optimize.md): Optimize this tree. Optimized trees will have faster searches, but they become immutable. Any changes made to an optimized tree will result in the tree being rebuilt.
- [Quadrance](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/quadrance.md): Compute the quadrance between two instances.
- [RemoveAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/removeat.md): Remove a specific item from this spatial tree.
- [ToArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.geometry.spatialtree.spatialtree-1/toarray.md): Create an array of all the items in this tree.
