public void testAllNeighbors(S2CellId id, int level)
        {
            Assert.True(level >= id.Level && level < S2CellId.MaxLevel);

            // We compute GetAllNeighbors, and then add in all the children of "id"
            // at the given level. We then compare this against the result of finding
            // all the vertex neighbors of all the vertices of children of "id" at the
            // given level. These should give the same result.
            var all      = new List <S2CellId>();
            var expected = new List <S2CellId>();

            id.GetAllNeighbors(level, all);
            var end = id.ChildEndForLevel(level + 1);

            for (var c = id.ChildBeginForLevel(level + 1); !c.Equals(end); c = c.Next)
            {
                all.Add(c.Parent);
                c.GetVertexNeighbors(level, expected);
            }
            // Sort the results and eliminate duplicates.
            all.Sort();
            expected.Sort();
            ISet <S2CellId> allSet      = new HashSet <S2CellId>(all);
            ISet <S2CellId> expectedSet = new HashSet <S2CellId>(expected);
            var             result      = allSet.SetEquals(expectedSet);

            Assert.True(result);
        }
        public void testAllNeighbors(S2CellId id, int level)
        {
            Assert.True(level >= id.Level && level < S2CellId.MaxLevel);

            // We compute GetAllNeighbors, and then add in all the children of "id"
            // at the given level. We then compare this against the result of finding
            // all the vertex neighbors of all the vertices of children of "id" at the
            // given level. These should give the same result.
            var all = new List<S2CellId>();
            var expected = new List<S2CellId>();
            id.GetAllNeighbors(level, all);
            var end = id.ChildEndForLevel(level + 1);
            for (var c = id.ChildBeginForLevel(level + 1); !c.Equals(end); c = c.Next)
            {
                all.Add(c.Parent);
                c.GetVertexNeighbors(level, expected);
            }
            // Sort the results and eliminate duplicates.
            all.Sort();
            expected.Sort();
            ISet<S2CellId> allSet = new HashSet<S2CellId>(all);
            ISet<S2CellId> expectedSet = new HashSet<S2CellId>(expected);
            var result = allSet.SetEquals(expectedSet);
            Assert.True(result);
        }
Пример #3
0
        public List <Guid> Search(double lon, double lat, int radius)
        {
            var latlng = S2LatLng.FromDegrees(lat, lon);

            var centerPoint = pointFromLatLng(lat, lon);

            var centerAngle = ((double)radius) / EarthRadiusM;

            var cap = S2Cap.FromAxisAngle(centerPoint, S1Angle.FromRadians(centerAngle));

            var regionCoverer = new S2RegionCoverer();

            regionCoverer.MaxLevel = 13;

            //  regionCoverer.MinLevel = 13;


            //regionCoverer.MaxCells = 1000;
            // regionCoverer.LevelMod = 0;


            var covering = regionCoverer.GetCovering(cap);



            var res = new List <Guid>();


            foreach (var u in covering)
            {
                var sell = new S2CellId(u.Id);

                if (sell.Level < _level)
                {
                    var begin = sell.ChildBeginForLevel(_level);
                    var end   = sell.ChildEndForLevel(_level);
                    do
                    {
                        var cur = tree.Search(new S2CellId(begin.Id));

                        if (cur != null)
                        {
                            res.AddRange(cur.Pointer);
                        }

                        begin = begin.Next;
                    } while (begin.Id != end.Id);
                }
                else
                {
                    var item = tree.Search(sell);
                    if (item != null)
                    {
                        res.AddRange(item.Pointer);
                    }
                }
            }
            return(res);
        }
Пример #4
0
        public List <Guid> Search(double lon, double lat, int radius)
        {
            var latlng = S2LatLng.FromDegrees(lat, lon);

            var centerPoint = Index.pointFromLatLng(lat, lon);

            var centerAngle = ((double)radius) / Index.EarthRadiusM;

            var cap = S2Cap.FromAxisAngle(centerPoint, S1Angle.FromRadians(centerAngle));

            var regionCoverer = new S2RegionCoverer();

            regionCoverer.MaxLevel = 13;

            //  regionCoverer.MinLevel = 13;


            //regionCoverer.MaxCells = 1000;
            // regionCoverer.LevelMod = 0;


            var covering = regionCoverer.GetCovering(cap);



            var res = new List <Guid>();


            foreach (var u in covering)
            {
                var sell = new S2CellId(u.Id);

                if (sell.Level < _level)
                {
                    var begin = sell.ChildBeginForLevel(_level);
                    var end   = sell.ChildEndForLevel(_level);

                    var qres = rtree.Query(new Range <S2CellId>(begin, end));

                    foreach (var r in qres)
                    {
                        res.AddRange(r.Content);
                    }
                }
                else
                {
                    var qres = rtree.Query(new Range <S2CellId>(sell));
                    if (qres.Count > 0)
                    {
                        foreach (var r in qres)
                        {
                            res.AddRange(r.Content);
                        }
                    }
                }
            }
            return(res);
        }
Пример #5
0
        public List <Guid> Search(double lon, double lat, int radius)
        {
            lock (locker)
            {
                var latlng = S2LatLng.FromDegrees(lat, lon);

                var centerPoint = pointFromLatLng(lat, lon);

                var centerAngle = ((double)radius) / EarthRadiusM;

                var cap = S2Cap.FromAxisAngle(centerPoint, S1Angle.FromRadians(centerAngle));

                var regionCoverer = new S2RegionCoverer();

                regionCoverer.MaxLevel = 13;

                //  regionCoverer.MinLevel = 13;


                //regionCoverer.MaxCells = 1000;
                // regionCoverer.LevelMod = 0;


                var covering = regionCoverer.GetCovering(cap);



                var res = new List <Guid>();


                foreach (var u in covering)
                {
                    var sell = new S2CellId(u.Id);

                    if (sell.Level < _level)
                    {
                        var begin = sell.ChildBeginForLevel(_level);
                        var end   = sell.ChildEndForLevel(_level);

                        var qres = rtree.Search(new Interval <UserList>(new UserList()
                        {
                            s2CellId = begin
                        }, new UserList()
                        {
                            s2CellId = end
                        }));


                        foreach (var item in qres)
                        {
                            res.AddRange(item.Start.list);
                        }
                    }
                    else
                    {
                        var qres = rtree.Search(new UserList()
                        {
                            s2CellId = sell
                        });
                        if (qres.Count > 0)
                        {
                            foreach (var r in qres)
                            {
                                res.AddRange(r.Start.list);
                            }
                        }
                    }
                }
                return(res);
            }
        }