public void Distance(HashSet <ISpatialTreeNode> hashSet, GeomCoordinate coordinate, double variance, SpatialQueryIterator i) { //Query elements on the map close to coordinate (indexed search) lock (this) { if (!IsBottomSheet) { if (Sheets.HasChilds) { foreach (var sheet in Sheets.Values) { i.Next(); if (sheet.Rectangle.RectangeDistance(coordinate) <= variance) { sheet.Distance(hashSet, coordinate, variance, i); } } } } else if (Content.HasChilds) { foreach (var node in Content.Values) { i.Next(); double distance = -1; switch (node.NodeType) { case SpatialTreeNodeTypes.Point: distance = node.Coordinate.Distance(coordinate); break; case SpatialTreeNodeTypes.Line: distance = node.Rectangle.LineDistance(coordinate); break; case SpatialTreeNodeTypes.Rectangle: distance = node.Rectangle.RectangeDistance(coordinate); break; case SpatialTreeNodeTypes.Poligon: distance = node.Poligon.PoligonDistance(coordinate); break; } if (distance >= 0 && distance <= variance) { hashSet.Add(node); } } } } }
public void Query(HashSet <ISpatialTreeNode> hashSet, CoordinateRectangle rectangle, IntersectResult parentResult, SpatialQueryIterator i) { //Query elements on the map by coordinate ractengle(indexed search) lock (this) { if (!IsBottomSheet) { if (Sheets.HasChilds) { foreach (var sheet in Sheets.Values) { var res = parentResult == IntersectResult.Supersets ? IntersectResult.Supersets : IntersectResult.None; if (res != IntersectResult.Supersets) { i.Next(); res = sheet.Rectangle.RectangleContains(rectangle); } if (res != IntersectResult.None) { sheet.Query(hashSet, rectangle, res, i); } if (res == IntersectResult.Contains) { break; } } } } else if (Content.HasChilds) { foreach (var node in Content.Values) { var res = parentResult == IntersectResult.Supersets ? IntersectResult.Supersets : IntersectResult.None; if (res != IntersectResult.Supersets) { i.Next(); switch (node.NodeType) { case SpatialTreeNodeTypes.Point: res = rectangle.PointContains(node.Coordinate); break; case SpatialTreeNodeTypes.Line: res = rectangle.LineContains(node.Rectangle); break; case SpatialTreeNodeTypes.Rectangle: res = rectangle.RectangleContains(node.Rectangle); break; case SpatialTreeNodeTypes.Poligon: res = rectangle.PoligonContains(node.Poligon); break; } } if (res != IntersectResult.None) { hashSet.Add(node); } } } } }