示例#1
0
        /// <summary>
        /// Bounding Polygon
        /// Get all the hashString covered by the polygon in numberOfChars
        /// </summary>
        /// <param name="polygon">array of coordinates describes the polygon</param>
        /// <param name="numberOfChars"></param>
        /// <returns>array of hash string</returns>
        public static string[] Bpolygon(Coordinates[] polygon, int numberOfChars = 9)
        {
            var hashList = new List <string>();
            // Get all bounding boxes that are possible be covered by polygon
            Coordinates max = new Coordinates {
                Lat = -90, Lon = -180
            };
            Coordinates min = new Coordinates {
                Lat = 90, Lon = 180
            };

            foreach (Coordinates c in polygon)
            {
                max.Lat = Math.Max(max.Lat, c.Lat);
                max.Lon = Math.Max(max.Lon, c.Lon);
                min.Lat = Math.Min(min.Lat, c.Lat);
                min.Lon = Math.Min(min.Lon, c.Lon);
            }
            string[] bboxHash = GeoHash.Bboxes(min.Lat, min.Lon, max.Lat, max.Lon, numberOfChars);
            foreach (string hash in bboxHash)
            {
                BoundingBox box = GeoHash.DecodeBbox(hash);
                if (BoxOverlapPolygon(box, polygon))
                {
                    hashList.Add(hash);
                }
            }
            return(hashList.ToArray());
        }
示例#2
0
        /// <summary>
        /// Bounding Box Coordinates
        /// Get all coordinates covered by the box in numberOfChars
        /// </summary>
        /// <param name="minLat"></param>
        /// <param name="minLon"></param>
        /// <param name="maxLat"></param>
        /// <param name="maxLon"></param>
        /// <param name="numberOfChars"></param>
        /// <returns>all coordinates covered by the box in numberOfChars</returns>
        public Coordinates[] BboxCoordinates(double minLat, double minLon, double maxLat, double maxLon, int numberOfChars = 9)
        {
            var coorList = new List <Coordinates>();

            string[] hashList = GeoHash.Bboxes(minLat, minLon, maxLat, maxLat, numberOfChars);

            foreach (string hash in hashList)
            {
                // TODO: search all level or search current level only?
                Coordinates[] coors = GetCoordinates(hash);
                BoundingBox   box   = GeoHash.DecodeBbox(hash);

                if (BoxInBoxRange(box, minLat, minLon, maxLat, maxLon))
                {
                    // All covered by box
                    coorList.AddRange(coors);
                }
                else
                {
                    // Not all covered by box
                    foreach (Coordinates c in coors)
                    {
                        if (CoordinateInBoxRange(c, minLat, minLon, maxLat, maxLon))
                        {
                            coorList.Add(c);
                        }
                    }
                }
            }

            return(coorList.ToArray());
        }
示例#3
0
        /// <summary>
        /// Get all bounding boxes covered by box
        /// </summary>
        /// <param name="minLat"></param>
        /// <param name="minLon"></param>
        /// <param name="maxLat"></param>
        /// <param name="maxLon"></param>
        /// <param name="numberOfChars"></param>
        /// <returns></returns>
        public static BoundingBox[] BboxBoxes(double minLat, double minLon, double maxLat, double maxLon, int numberOfChars = 9)
        {
            var boxList = new List <BoundingBox>();

            string[] hashList = GeoHash.Bboxes(minLat, minLon, maxLat, maxLon, numberOfChars);
            foreach (string hash in hashList)
            {
                boxList.Add(GeoHash.DecodeBbox(hash));
            }

            return(boxList.ToArray());
        }
示例#4
0
        public static void BoundingBoxTest()
        {
            // Bounding box
            Coordinates coor1 = new Coordinates {
                Lat = 41.85776407, Lon = -87.73420671
            };
            Coordinates coor2 = new Coordinates {
                Lat = 41.89993156, Lon = -87.60380377
            };
            var watch = System.Diagnostics.Stopwatch.StartNew();

            string[] hashlist = GeoHash.Bboxes(coor1.Lat, coor1.Lon, coor2.Lat, coor2.Lon, mLevel);
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Get bounding box, time elapsed: " + elapsedMs + " ms | " + hashlist.Length + " results get");
            KMLGenerator.GenerateKMLBoundingBoxes(hashlist, coor1, coor2, "bounding box");
        }
示例#5
0
        public void BBoxes_ReturnsHashStringsBetweenCoordinates()
        {
            var bBoxes = GeoHash.Bboxes(30, 120, 30.0001, 120.0001, 8);

            Assert.Equal(GeoHash.Encode(30.0001, 120.0001, 8), bBoxes[bBoxes.Length - 1]);
        }