示例#1
0
        /// <summary>
        /// 1.获取字符串长度的网格范围
        /// 2.从leftTop开始,根据
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="characterLength"></param>
        private void splitRectangle(RectangleD rect, int characterLength)
        {
            double xRange = GeoHashSizeTable.LonCharacterRange[characterLength];
            double yRange = GeoHashSizeTable.LatCharacterRange[characterLength];
            //由leftTop开始分裂
            double x = rect.Left;

            while (x <= rect.Right)
            {
                double y = rect.Top;
                while (y <= rect.Bottom)
                {
                    GeoHash hash = GeoHash.EncodeWithCharacterPrecision(x, y, characterLength);
                    if (!_geoHashes.Contains(hash))
                    {
                        _geoHashes.Add(hash);
                    }
                    if (y == rect.Bottom)
                    {
                        break;
                    }
                    y = nextLonLat(y, yRange, rect.Bottom);
                }
                if (x == rect.Right)
                {
                    break;
                }
                x = nextLonLat(x, xRange, rect.Right);
            }
        }
 private void expandSearch(GeoHash hash)
 {
     addSearchHash(hash);
     foreach (GeoHash gh in hash.GetEightDirection())
     {
         if (gh.Bound.IsIntersect(Rect) && !_geoHashes.Contains(gh))
         {
             addSearchHash(gh);
         }
     }
 }
        public GeoHashRectangleQuery(RectangleD rect)
        {
            Rect = rect;
            int     length = GeoHashSizeTable.NumberOfCharacter(rect);
            GeoHash hash   = GeoHash.EncodeWithCharacterPrecision(rect.Center, length);

            if (hash.Bound.Contains(rect))
            {
                addSearchHash(hash);
            }
            else
            {
                expandSearch(hash);
            }
        }
示例#4
0
 public override bool Equals(object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     else
     {
         GeoHash hash = obj as GeoHash;
         if (hash != null && DesiredPrecision == hash.DesiredPrecision && Bits == hash.Bits)
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
        static void Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 3)
            {
                Usage();
            }

            DateTime date;

            string[] coords;
            if (args[0] == "-g")
            {
                if (args.Length == 1)
                {
                    date = DateTime.Now;
                }
                else
                {
                    date = DateTime.Parse(args[1]);
                }

                coords = GeoHash.GetGlobalHash(date);
                Console.WriteLine($"Globalhash: {coords[0]} {coords[1]}");
            }
            else
            {
                if (args.Length == 2)
                {
                    date = DateTime.Now;
                }
                else
                {
                    date = DateTime.Parse(args[2]);
                }

                int latitude  = int.Parse(args[0]);
                int longitude = int.Parse(args[1]);

                coords = GeoHash.GetGeoHash(date, latitude, longitude);
                Console.WriteLine($"Geohash: {coords[0]} {coords[1]}");
            }
        }
 private void addSearchHash(GeoHash hash)
 {
     Bound.Union(hash.Bound);
     _geoHashes.Add(hash);
 }