示例#1
0
        /**
         * Neighbors Integer
         *
         * Returns all neighbors' hash integers clockwise from north around to northwest
         * 7 0 1
         * 6 x 2
         * 5 4 3
         * @param {long} hashInt
         * @param {int} bitDepth
         * @returns {EncodeInt'd neighborHashIntList|long[]}
         */
        public static long[] NeighborsInt(long hashInt, int bitDepth = 52)
        {
            var lonlat = DecodeInt(hashInt, bitDepth);
            var coords = new GeohashDecodeResult
            {
                Coordinates = lonlat.Coordinates,
                Error = new Coordinates
                {
                    Lat = lonlat.Error.Lat*2,
                    Lon = lonlat.Error.Lon*2
                }
            };

            return new[]
            {
                EncodeNeighborInt(1, 0, coords, bitDepth),
                EncodeNeighborInt(1, 1, coords, bitDepth),
                EncodeNeighborInt(0, 1, coords, bitDepth),
                EncodeNeighborInt(-1, 1, coords, bitDepth),
                EncodeNeighborInt(-1, 0, coords, bitDepth),
                EncodeNeighborInt(-1, -1, coords, bitDepth),
                EncodeNeighborInt(0, -1, coords, bitDepth),
                EncodeNeighborInt(1, -1, coords, bitDepth)
            };
        }
示例#2
0
 public static long EncodeNeighborInt(int neighborLatDir, int neighborLonDir, GeohashDecodeResult coords, int bitDepth)
 {
     var neighborLat = coords.Coordinates.Lat + neighborLatDir*coords.Error.Lat;
     var neighborLon = coords.Coordinates.Lon + neighborLonDir*coords.Error.Lon;
     return EncodeInt(neighborLat, neighborLon, bitDepth);
 }
示例#3
0
        /**
         * Neighbors
         *
         * Returns all neighbors' hashstrings clockwise from north around to northwest
         * 7 0 1
         * 6 x 2
         * 5 4 3
         * @param {string} hashString
         * @returns {encoded neighborHashList|string[]}
         */
        public static string[] Neighbors(string hashString)
        {
            var hashstringLength = hashString.Length;

            var lonlat = Decode(hashString);

            var coords = new GeohashDecodeResult
            {
                Coordinates = lonlat.Coordinates,
                Error = new Coordinates
                {
                    Lat = lonlat.Error.Lat*2,
                    Lon = lonlat.Error.Lon*2
                }

            };

            return new[]
            {
                EncodeNeighbor(hashstringLength, 1, 0, coords),
                EncodeNeighbor(hashstringLength, 1, 1, coords),
                EncodeNeighbor(hashstringLength, 0, 1, coords),
                EncodeNeighbor(hashstringLength, -1, 1, coords),
                EncodeNeighbor(hashstringLength, -1, 0, coords),
                EncodeNeighbor(hashstringLength, -1, -1, coords),
                EncodeNeighbor(hashstringLength, 0, -1, coords),
                EncodeNeighbor(hashstringLength, 1, -1, coords)
            };
        }
示例#4
0
 public static string EncodeNeighbor(int hashstringLength, int neighborLatDir, int neighborLonDir, GeohashDecodeResult coords)
 {
     var neighborLat = coords.Coordinates.Lat + neighborLatDir*coords.Error.Lat;
     var neighborLon = coords.Coordinates.Lon + neighborLonDir*coords.Error.Lon;
     return Encode(neighborLat, neighborLon, hashstringLength);
 }