Esempio n. 1
0
 public void SetUp()
 {
     this.factory    = new GeometryFactory();
     this.geometries = new List <IPoint>(Enumerable.Range(1, 1000).Select(value => this.factory.CreatePoint(value, value, value)));
     this.tree       = new HilbertRTree();
     this.tree.Add(this.geometries);
 }
Esempio n. 2
0
        public void HilbertRTreeSearchTest()
        {
            // empty results

            this.tree.Search(Envelope.Undefined).ShouldBeEmpty();

            for (Int32 value = 0; value < 1000; value++)
            {
                this.tree.Search(new Envelope(value, value, value, value, 0, 0)).ShouldBeEmpty();
            }

            // all results
            this.tree.Search(Envelope.Infinity).Count().ShouldBe(this.geometries.Count);
            this.tree.Search(Envelope.FromEnvelopes(this.geometries.Select(geometry => geometry.Envelope))).Count().ShouldBe(this.geometries.Count);

            // exact results
            HilbertRTree tree = new HilbertRTree(3);

            Coordinate[] firstShell = new Coordinate[]
            {
                new Coordinate(0, 0, 0),
                new Coordinate(0, 10, 0),
                new Coordinate(10, 10, 0),
                new Coordinate(10, 0, 0),
                new Coordinate(0, 0, 0)
            };

            Coordinate[] secondShell = new Coordinate[]
            {
                new Coordinate(0, 0, 0),
                new Coordinate(0, 15, 0),
                new Coordinate(15, 15, 0),
                new Coordinate(15, 0, 0),
                new Coordinate(0, 0, 0)
            };

            Coordinate[] thirdShell = new Coordinate[]
            {
                new Coordinate(30, 30, 0),
                new Coordinate(30, 40, 0),
                new Coordinate(40, 40, 0),
                new Coordinate(40, 30, 0),
                new Coordinate(30, 30, 0)
            };

            tree.Add(this.factory.CreatePolygon(firstShell));
            tree.Add(this.factory.CreatePolygon(secondShell));
            tree.Add(this.factory.CreatePolygon(thirdShell));

            tree.Search(Envelope.FromCoordinates(firstShell)).Count().ShouldBe(1);
            tree.Search(Envelope.FromCoordinates(secondShell)).Count().ShouldBe(2);
            tree.Search(Envelope.FromCoordinates(thirdShell)).Count().ShouldBe(1);
            tree.Search(Envelope.FromCoordinates(secondShell.Union(thirdShell))).Count().ShouldBe(3);

            // errors
            Should.Throw <ArgumentNullException>(() => this.tree.Search(null));
        }
Esempio n. 3
0
        public void HilbertRTreeContainsTest()
        {
            this.tree.Contains(null).ShouldBeFalse();
            this.tree.Contains(this.factory.CreatePoint(1000, 1000, 1000)).ShouldBeFalse();
            this.tree.Contains(this.factory.CreatePoint(Coordinate.Undefined)).ShouldBeFalse();

            HilbertRTree tree = new HilbertRTree(3);

            tree.Add(this.geometries);
            Int32 contained = this.geometries.Count(geometry => tree.Contains(geometry));

            contained.ShouldBe(this.geometries.Count);
        }
Esempio n. 4
0
        public void HilbertRTreeAddTest()
        {
            HilbertRTree tree = new HilbertRTree(3);

            // the maxChildren in this case is the minimum allowed 3
            // the minChildren in this case is 3 * 2 / 3 = 2
            // the root node has a maxChildren count of 2 * minChildren, so in this case it's 4
            // therefore the height shall increase once we insert the fifth geometry
            tree.Add(this.geometries[0]);
            tree.Height.ShouldBe(1);
            tree.NumberOfGeometries.ShouldBe(1);

            tree.Add(this.geometries[1]);
            tree.Height.ShouldBe(1);
            tree.NumberOfGeometries.ShouldBe(2);

            tree.Add(this.geometries[2]);
            tree.Height.ShouldBe(1);
            tree.NumberOfGeometries.ShouldBe(3);

            tree.Add(this.geometries[3]);
            tree.Height.ShouldBe(1);
            tree.NumberOfGeometries.ShouldBe(4);

            tree.Add(this.geometries[4]);
            tree.Height.ShouldBe(2);
            tree.NumberOfGeometries.ShouldBe(5);

            // insert the remaining geometries
            for (Int32 geometryIndex = 5; geometryIndex < this.geometries.Count; geometryIndex++)
            {
                tree.Add(this.geometries[geometryIndex]);
            }

            // check that the tree has a correct height
            tree.NumberOfGeometries.ShouldBe(this.geometries.Count);
            tree.Height.ShouldBeGreaterThanOrEqualTo((Int32)Math.Floor(Math.Log(this.geometries.Count, 3)));
            tree.Height.ShouldBeLessThanOrEqualTo((Int32)Math.Ceiling(Math.Log(this.geometries.Count, 2)));

            // add a complete collection
            tree = new HilbertRTree();
            tree.Add(this.geometries);
            tree.NumberOfGeometries.ShouldBe(this.geometries.Count);

            // errors
            Should.Throw <ArgumentNullException>(() => tree.Add((IGeometry)null));
            Should.Throw <ArgumentNullException>(() => tree.Add((IEnumerable <IGeometry>)null));
        }
Esempio n. 5
0
        public void HilbertRTreeConstructorTest()
        {
            HilbertRTree tree = new HilbertRTree();

            tree.Height.ShouldBe(0);
            tree.NumberOfGeometries.ShouldBe(0);
            tree.MinChildren.ShouldBe(8);
            tree.MaxChildren.ShouldBe(12);
            tree.IsReadOnly.ShouldBeFalse();

            tree = new HilbertRTree(9);
            tree.Height.ShouldBe(0);
            tree.NumberOfGeometries.ShouldBe(0);
            tree.MinChildren.ShouldBe(6);
            tree.MaxChildren.ShouldBe(9);
            tree.IsReadOnly.ShouldBeFalse();

            Should.Throw <ArgumentOutOfRangeException>(() => new HilbertRTree(-3));
            Should.Throw <ArgumentOutOfRangeException>(() => new HilbertRTree(0));
            Should.Throw <ArgumentOutOfRangeException>(() => new HilbertRTree(20));
            Should.Throw <ArgumentNullException>(() => new HilbertRTree(3, null));
        }