Exemplo n.º 1
0
        public HashSet <ISpatialTreeNode> Query(CoordinateRectangle rectangle)
        {
            //for debug to see how many iterations used for a search
            var i = SpatialQueryIterator.Start();

            var res = new HashSet <ISpatialTreeNode>();

            _root.Query(res, rectangle, InterseptResult.None, i);

            //index turning
            System.Diagnostics.Trace.WriteLine(string.Format("{5} Level nodes {1} {2} {3} {4}, Query iterations - {0:d}",
                                                             i.Value, NodeDimension[0], NodeDimension[1], NodeDimension[2], NodeDimension[3], typeof(TNode).Name));

            return(res);
        }
Exemplo n.º 2
0
        public HashSet <ISpatialTreeNode> Distance(Coordinate coordinate, double variance)
        {
            //for debug to see how many iterations used for a search
            var i = SpatialQueryIterator.Start();

            var res = new HashSet <ISpatialTreeNode>();

            _root.Distance(res, coordinate, variance, i);

            //index turning
            System.Diagnostics.Trace.WriteLine(string.Format("{5} Level nodes {1} {2} {3} {4}, Distance iterations - {0:d}",
                                                             i.Value, NodeDimension[0], NodeDimension[1], NodeDimension[2], NodeDimension[3], typeof(TNode).Name));

            return(res);
        }
Exemplo n.º 3
0
        public void Distance(HashSet <ISpatialTreeNode> hashSet, Coordinate 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);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Query(HashSet <ISpatialTreeNode> hashSet, CoordinateRectangle rectangle, InterseptResult 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 == InterseptResult.Supersets ? InterseptResult.Supersets : InterseptResult.None;

                            if (res != InterseptResult.Supersets)
                            {
                                i.Next();

                                res = sheet.Rectangle.RectangleContains(rectangle);
                            }
                            if (res != InterseptResult.None)
                            {
                                sheet.Query(hashSet, rectangle, res, i);
                            }
                            if (res == InterseptResult.Contains)
                            {
                                break;
                            }
                        }
                    }
                }
                else if (Content.HasChilds)
                {
                    foreach (var node in Content.Values)
                    {
                        var res = parentResult == InterseptResult.Supersets ? InterseptResult.Supersets : InterseptResult.None;
                        if (res != InterseptResult.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 != InterseptResult.None)
                        {
                            hashSet.Add(node);
                        }
                    }
                }
            }
        }