Пример #1
0
        public bool TryRemoveKey(Object keyObject)
        {
            IGeometry key;
            if (!IndexHelper.CheckObject(out key, keyObject))
            {
                return false;
            }

            if (ReadResource())
            {
                if (TestOfGeometry(key) && DimensionTest(key.Dimensions))
                {
                    IRTreeDataContainer searchContainer;
                    if (key is IPoint)
                        searchContainer = new PointDataContainer(((IPoint)key).PointToSpaceR());
                    else
                        searchContainer = new SpatialDataContainer(key.GeometryToMBR());

                    var removeObjects = Searching(searchContainer, Inclusion, Inclusion);
                    FinishReadResource();
                    foreach (var value in removeObjects)
                    {
                        RemoveValue(value);
                    }

                    return removeObjects.Count > 0;
                }
                return false;
            }
            throw new CollisionException(this);
        }
Пример #2
0
        public bool TryGetValue(out ReadOnlyCollection<AGraphElement> result, Object geometryObject)
        {
            IGeometry geometry;
            if (!IndexHelper.CheckObject(out geometry, geometryObject))
            {
                result = null;
                return false;
            }

            if (ReadResource())
            {
                result = new List<AGraphElement>().AsReadOnly();
                IRTreeDataContainer element;
                if (DimensionTest(geometry.Dimensions) && TestOfGeometry(geometry))
                {
                    if (geometry is IPoint)
                        element = new PointDataContainer(((IPoint)geometry).PointToSpaceR());
                    else
                        element = new SpatialDataContainer(geometry.GeometryToMBR());

                    result = EqualSearch(element);
                }
                FinishReadResource();

                return result.Count > 0;
            }
            throw new CollisionException(this);
        }
Пример #3
0
 public bool SearchPoint(out ReadOnlyCollection<AGraphElement> result, IPoint point)
 {
     if (ReadResource())
     {
         result = new List<AGraphElement>().AsReadOnly();
         if (TestOfGeometry(point) && DimensionTest(point.Dimensions))
         {
             var searchContainer = new PointDataContainer(point.PointToSpaceR());
             result = Searching(searchContainer, Intersection, Intersection);
         }
         FinishReadResource();
         return result.Count > 0;
     }
     throw new CollisionException(this);
 }
Пример #4
0
        public bool Overlap(out ReadOnlyCollection<AGraphElement> result, IGeometry geometry)
        {
            if (ReadResource())
            {
                result = new List<AGraphElement>().AsReadOnly();
                if (TestOfGeometry(geometry) && DimensionTest(geometry.Dimensions))
                {
                    IRTreeDataContainer searchContainer;
                    if (geometry is IPoint)
                        searchContainer = new PointDataContainer(((IPoint)geometry).PointToSpaceR());
                    else
                        searchContainer = new SpatialDataContainer(geometry.GeometryToMBR());

                    result = OverlapSearch(searchContainer);
                }
                FinishReadResource();
                return result.Count > 0;
            }
            throw new CollisionException(this);
        }
Пример #5
0
        public bool GetNextNeighbors(out ReadOnlyCollection<AGraphElement> result, IGeometry geometry, int countOfNextNeighbors)
        {
            if (ReadResource())
            {
                result = new List<AGraphElement>().AsReadOnly();
                if (TestOfGeometry(geometry) && DimensionTest(geometry.Dimensions))
                {
                    IRTreeDataContainer output;
                    if (geometry is IPoint)
                        output = new PointDataContainer(((IPoint)geometry).PointToSpaceR());
                    else
                        output = new SpatialDataContainer(geometry.GeometryToMBR());

                    var containers = new LinkedList<Tuple<float, IRTreeDataContainer>>();
                    var maxElement = float.PositiveInfinity;

                    var stack = new Stack<ARTreeContainer>();
                    if (Distance(_root, output) < maxElement || containers.Count < countOfNextNeighbors)
                        stack.Push(_root);
                    while (stack.Count > 0)
                    {
                        var currentContainer = stack.Pop();

                        if (!currentContainer.IsLeaf)
                        {
                            foreach (var value2 in ((RTreeNode)currentContainer).Children)
                            {
                                if (Distance(value2, output) < maxElement || containers.Count < countOfNextNeighbors)
                                    stack.Push(value2);
                            }
                        }
                        else
                        {
                            foreach (var value2 in ((RTreeLeaf)currentContainer).Data)
                            {
                                var dist = Distance(value2, output);

                                if ((containers.Count < countOfNextNeighbors || dist < maxElement) && value2 != output)
                                {
                                    if (containers.Count == 0)
                                    {
                                        containers.AddFirst(new LinkedListNode<Tuple<float, IRTreeDataContainer>>(Tuple.Create(dist, value2)));
                                        maxElement = dist;
                                    }
                                    else
                                    {
                                        var end = true;
                                        var start = containers.First;
                                        while (end)
                                        {

                                            if (dist < start.Value.Item1)
                                            {
                                                containers.AddBefore(start, Tuple.Create(dist, value2));
                                                if (containers.Count > countOfNextNeighbors)
                                                {
                                                    containers.RemoveLast();
                                                    maxElement = containers.Last.Value.Item1;
                                                }
                                                break;
                                            }
                                            if (start == containers.Last)
                                            {
                                                end = false;
                                            }
                                            else
                                            {
                                                start = start.Next;
                                            }
                                        }
                                        if (!end && containers.Count < countOfNextNeighbors)
                                        {
                                            maxElement = dist;
                                            containers.AddLast(Tuple.Create(dist, value2));
                                        }
                                    }
                                }
                            }
                        }

                    }
                    result = containers.Select(_ => _.Item2.GraphElement).ToList().AsReadOnly();
                }
                FinishReadResource();
                return result.Count > 0;

            }
            throw new CollisionException(this);
        }
Пример #6
0
        public void AddOrUpdate(Object keyObject, AGraphElement graphElement)
        {
            IGeometry key;
            if (!IndexHelper.CheckObject(out key, keyObject))
            {
                return;
            }

            if (WriteResource())
            {
                if (DimensionTest(key.Dimensions) && TestOfGeometry(key))
                {
                    if (!_mapOfContainers.ContainsKey(graphElement.Id))
                    {
                        IRTreeDataContainer currentContainer;

                        if (key is IPoint)
                        {
                            var coordinations = ((IPoint)key).PointToSpaceR();
                            currentContainer = new PointDataContainer(coordinations) {GraphElement = graphElement};

                        }
                        else
                        {
                            var mbr = key.GeometryToMBR();
                            currentContainer = new SpatialDataContainer(mbr.Lower, mbr.Upper)
                                                   {GraphElement = graphElement};
                        }

                        InsertData(currentContainer);
                        _mapOfContainers.Add(graphElement.Id, currentContainer);

                    }
                    else
                    {
                        RemoveValue(graphElement);
                        AddOrUpdate(key, graphElement);
                    }

                }
                FinishWriteResource();
                return;
            }
            throw new CollisionException(this);
        }