public void Should_Give_Neighbors() { var hasher = new Geohasher(); var subhashes = hasher.GetNeighbors("u33dc0"); Assert.Equal("u33dc1", subhashes[Direction.North]); Assert.Equal("u33dc3", subhashes[Direction.NorthEast]); Assert.Equal("u33dc2", subhashes[Direction.East]); Assert.Equal("u33d9r", subhashes[Direction.SouthEast]); Assert.Equal("u33d9p", subhashes[Direction.South]); Assert.Equal("u33d8z", subhashes[Direction.SouthWest]); Assert.Equal("u33dbb", subhashes[Direction.West]); Assert.Equal("u33dbc", subhashes[Direction.NorthWest]); }
public void Should_Give_Neighbors_EdgeNorth() { var hasher = new Geohasher(); var subhashes = hasher.GetNeighbors("u"); Assert.Equal("h", subhashes[Direction.North]); Assert.Equal("5", subhashes[Direction.NorthWest]); Assert.Equal("j", subhashes[Direction.NorthEast]); Assert.Equal("v", subhashes[Direction.East]); Assert.Equal("s", subhashes[Direction.South]); Assert.Equal("e", subhashes[Direction.SouthWest]); Assert.Equal("t", subhashes[Direction.SouthEast]); Assert.Equal("g", subhashes[Direction.West]); }
public void Should_Give_Neighbors_EdgeWest() { var hasher = new Geohasher(); var subhashes = hasher.GetNeighbors("9"); Assert.Equal("c", subhashes[Direction.North]); Assert.Equal("b", subhashes[Direction.NorthWest]); Assert.Equal("f", subhashes[Direction.NorthEast]); Assert.Equal("d", subhashes[Direction.East]); Assert.Equal("3", subhashes[Direction.South]); Assert.Equal("2", subhashes[Direction.SouthWest]); Assert.Equal("6", subhashes[Direction.SouthEast]); Assert.Equal("8", subhashes[Direction.West]); }
public async Task <IEnumerable <string> > GetGeohashes(GeohashGetBinding binding) { var geohasher = new Geohasher(); using (var context = GetMainContext()) { var neighbours = binding.Geohash is null ? null : geohasher.GetNeighbors(binding.Geohash); return(await context.Trackings.WhereUser(UserId) .WhereTimestampInclusive(binding) .WhereIf(neighbours is not null, x => x.Geohash.StartsWith(binding.Geohash) || x.Geohash.StartsWith(neighbours[Direction.North]) || x.Geohash.StartsWith(neighbours[Direction.South]) || x.Geohash.StartsWith(neighbours[Direction.East]) || x.Geohash.StartsWith(neighbours[Direction.West]) || x.Geohash.StartsWith(neighbours[Direction.NorthEast]) || x.Geohash.StartsWith(neighbours[Direction.NorthWest]) || x.Geohash.StartsWith(neighbours[Direction.SouthEast]) || x.Geohash.StartsWith(neighbours[Direction.SouthWest])) .Select(x => x.Geohash.Substring(0, binding.Precision)) .Distinct() .ToListAsync()); } }
public List <string> Neighbours(string geohash) { return(hasher.GetNeighbors(geohash).Select(d => d.Value).ToList()); }