Ejemplo n.º 1
0
        /// <summary>
        /// Radius of bounding box in hexagons.  i.e., the radius of a k-ring centered
        /// on the bbox center and covering the entire bbox.
        /// </summary>
        /// <param name="bbox">Bounding box to measure</param>
        /// <param name="res">Resolution of hexagons to use in measurement</param>
        /// <returns>Radius in hexagons</returns>
        /// <!-- Based off 3.1.1 -->
        public static int bboxHexRadius(BBox bbox, int res)
        {
            // Determine the center of the bounding box
            GeoCoord center = new GeoCoord();

            bboxCenter(bbox, ref center);

            // Use a vertex on the side closest to the equator, to ensure the longest
            // radius in cases with significant distortion. East/west is arbitrary.
            double lat =
                Math.Abs(bbox.north) > Math.Abs(bbox.south)
                    ? bbox.south
                    : bbox.north;

            GeoCoord vertex = new GeoCoord {
                lat = lat, lon = bbox.east
            };

            // Determine the length of the bounding box "radius" to then use
            // as a circle on the earth that the k-rings must be greater than
            double bboxRadiusKm = GeoCoord._geoDistKm(center, new [] { vertex });

            // Determine the radius of the center hexagon
            double centerHexRadiusKm = _hexRadiusKm(H3Index.geoToH3(ref center, res));

            // The closest point along a hexagon drawn through the center points
            // of a k-ring aggregation is exactly 1.5 radii of the hexagon. For
            // any orientation of the GeoJSON encased in a circle defined by the
            // bounding box radius and center, it is guaranteed to fit in this k-ring
            // Rounded *up* to guarantee containment
            return((int)Math.Ceiling(bboxRadiusKm / (1.5 * centerHexRadiusKm)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the radius of a given hexagon in kilometers
        /// </summary>
        /// <param name="h3Index">Index of the hexagon</param>
        /// <returns>radius of hexagon in kilometers</returns>
        /// <!-- Based off 3.1.1 -->
        static double _hexRadiusKm(H3Index h3Index)
        {
            // There is probably a cheaper way to determine the radius of a
            // hexagon, but this way is conceptually simple
            GeoCoord    h3Center   = new GeoCoord();
            GeoBoundary h3Boundary = new GeoBoundary();

            H3Index.h3ToGeo(h3Index, ref h3Center);
            H3Index.h3ToGeoBoundary(h3Index, ref h3Boundary);
            return(GeoCoord._geoDistKm(h3Center, h3Boundary.verts));
        }