Example #1
0
        public void TestCreateAndExtendByMassiveNumberZ()
        {
            _data = CreateSampleData(50000, new Envelope(-100, 100, -100, 100));
            var zRange = Interval.Create(1, 10);
            var tree   = SbnTree.Create(_data, zRange, null);

            Assert.AreEqual(zRange, tree.ZRange);

            foreach (var tuple in CreateSampleData(50000, new Envelope(-100, 100, -100, 100), 50001))
            {
                tree.Insert(tuple.Item1, tuple.Item2, CreateInterval(Interval.Create(0, 20)), null);
            }
            Assert.IsTrue(tree.FeatureCount == 100000);
            Assert.IsTrue(tree.ZRange.Min < 1d);
            Assert.IsTrue(tree.ZRange.Max > 10d);
            Assert.IsTrue(Interval.Create(0, 20).Contains(tree.ZRange));
        }
Example #2
0
        public void TestToText(string sbnFile)
        {
            if (!File.Exists(sbnFile))
            {
                throw new IgnoreException("File '" + sbnFile + "' not found!");
            }

            SbnTree sbn = null;

            Assert.DoesNotThrow(() => sbn = SbnTree.Load(sbnFile));
            Assert.DoesNotThrow(() => SbnTree.SbnToText(sbnFile, new StreamWriter(File.OpenWrite(Path.ChangeExtension(sbnFile, ".sbn.txt")))));
            Assert.IsNotNull(sbn);
            Assert.IsTrue(sbn.VerifyNodes());

            var sbnTestFile = Path.ChangeExtension(sbnFile, null) + "_test.sbn";

            Assert.DoesNotThrow(() => sbn.Save(sbnTestFile));
            Assert.DoesNotThrow(() => SbnTree.SbnToText(sbnTestFile, new StreamWriter(File.OpenWrite(Path.ChangeExtension(sbnTestFile, ".sbn.txt")))));
        }
Example #3
0
        public void TestGetNodeLevel()
        {
            var tree = new SbnTree(new SbnHeader(256, ToSbn(Interval.Create(-180, 180)),
                                                 ToSbn(Interval.Create(-90, 90)),
                                                 ToSbn(Interval.Create()),
                                                 ToSbn(Interval.Create())));
            var node = new SbnNode(tree, 1);

            Assert.AreEqual(1, node.Level);

            node = new SbnNode(tree, 2);
            Assert.AreEqual(2, node.Level);
            node = new SbnNode(tree, 3);
            Assert.AreEqual(2, node.Level);

            node = new SbnNode(tree, 4);
            Assert.AreEqual(3, node.Level);
            node = new SbnNode(tree, 5);
            Assert.AreEqual(3, node.Level);
            node = new SbnNode(tree, 6);
            Assert.AreEqual(3, node.Level);
            node = new SbnNode(tree, 7);
            Assert.AreEqual(3, node.Level);

            node = new SbnNode(tree, 8);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 9);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 10);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 11);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 12);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 13);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 14);
            Assert.AreEqual(4, node.Level);
            node = new SbnNode(tree, 15);
            Assert.AreEqual(4, node.Level);
        }
Example #4
0
        public void Test(string sbnFile)
        {
            if (!File.Exists(sbnFile))
            {
                throw new IgnoreException("File '" + sbnFile + "' not found!");
            }

            SbnTree sbn = null;

            Assert.DoesNotThrow(() => sbn = SbnTree.Load(sbnFile));
            Assert.IsNotNull(sbn);
            Assert.IsTrue(sbn.VerifyNodes());

            var sbnTestFile = Path.ChangeExtension(sbnFile, null) + "_test.sbn";

            Assert.DoesNotThrow(() => sbn.Save(sbnTestFile));

            var fiO = new FileInfo(sbnFile);
            var fiT = new FileInfo(sbnTestFile);

            Assert.AreEqual(fiO.Length, fiT.Length);
        }
Example #5
0
        public void TestQueryTime(string sbnFile)
        {
            if (!File.Exists(sbnFile))
            {
                throw new IgnoreException("File '" + sbnFile + "' not found!");
            }

            var     sw  = new Stopwatch();
            SbnTree sbn = null;

            sw.Start();
            Assert.DoesNotThrow(() => sbn = SbnTree.Load(sbnFile));
            sw.Stop();
            Console.WriteLine("SbnTree read in {0:N0} ticks", sw.ElapsedTicks);

            var fullExtent = sbn.Extent;

            for (var i = 0; i < 10; i++)
            {
                sw.Restart();
                var fids = new List <uint>(sbn.QueryFids(fullExtent));
                sw.Stop();
                Console.WriteLine("Querying full in {0:N0} ticks ({1} ids)", sw.ElapsedTicks, fids.Count);
            }

            var partialExtent = ToSbn(new Envelope(
                                          fullExtent.MinX + 0.4 * fullExtent.Width,
                                          fullExtent.MaxX - 0.4 * fullExtent.Width,
                                          fullExtent.MinY + 0.3 * fullExtent.Height,
                                          fullExtent.MaxY - 0.3 * fullExtent.Height));

            for (var i = 0; i < 10; i++)
            {
                sw.Restart();
                var fids = new List <uint>(sbn.QueryFids(partialExtent));
                sw.Stop();
                Console.WriteLine("Querying part in {0:N0} ticks ({1} ids)", sw.ElapsedTicks, fids.Count);
            }
        }
Example #6
0
 public SbnTreeWrapper(SbnTree sbnTree)
 {
     _sbnTree = sbnTree;
 }
Example #7
0
 ISpatialIndex <uint> ISpatialIndexFactory <uint> .Create(Envelope extent, int expectedNumberOfEntries, IEnumerable <ISpatialIndexItem <uint> > entries)
 {
     return(new SbnTreeWrapper(SbnTree.Create(ToCollection(entries))));
 }