H3Lib/Extensions/LinkedGeoLoopExtensions.cs
/// <summary>
/// Convert GeoLoop to bounding box for loop
/// </summary>
/// <param name="loop"></param>
/// <returns></returns>
Convert GeoLoop to bounding box for loop
Convert GeoLoop to bounding box for loop
public static BBox ToBBox(this LinkedGeoLoop loop)
        {
            if (loop.IsEmpty)
            {
                return new BBox();
            }
            var box = new BBox(-decimal.MaxValue, decimal.MaxValue, -decimal.MaxValue, decimal.MaxValue);
            decimal minPosLon = decimal.MaxValue;
            decimal maxNegLon = -decimal.MaxValue;
            bool isTransmeridian = false;
            decimal lat;
            decimal lon;
            var nodes = loop.Nodes;
            for (int idx = 0; idx < nodes.Count; idx++)
            {
                var coord = nodes[idx];
                var next = nodes[(idx + 1) % nodes.Count];
                lat = coord.Latitude;
                lon = coord.Longitude;
                if (lat < box.South)
                {
                    box = box.ReplaceSouth(lat);
                }
                if (lon < box.West)
                {
                    box = box.ReplaceWest(lon);
                }
                if (lat > box.North)
                {
                    box = box.ReplaceNorth(lat);
                }
                if (lon > box.East)
                {
                    box = box.ReplaceEast(lon);
                }
                if (lon > 0 && lon < minPosLon)
                {
                    minPosLon = lon;
                }
                if (lon < 0 && lon > maxNegLon)
                {
                    maxNegLon = lon;
                }
                if (Math.Abs(lon - next.Longitude) > Constants.H3.M_PI)
                {
                    isTransmeridian = true;
                }
            }
            if (isTransmeridian)
            {
                box = box.ReplaceEW(maxNegLon, minPosLon);
            }
            return box;
        }
public static BBox ToBBox ( this LinkedGeoLoop loop ) { if ( loop . IsEmpty ) { return new BBox ( ) ; } var box = new BBox ( - decimal . MaxValue , decimal . MaxValue , - decimal . MaxValue , decimal . MaxValue ) ; decimal minPosLon = decimal . MaxValue ; decimal maxNegLon = - decimal . MaxValue ; bool isTransmeridian = false ; decimal lat ; decimal lon ; var nodes = loop . Nodes ; for ( int idx = 0 ; idx < nodes . Count ; idx ++ ) { var coord = nodes [ idx ] ; var next = nodes [ ( idx + 1 ) % nodes . Count ] ; lat = coord . Latitude ; lon = coord . Longitude ; if ( lat < box . South ) { box = box . ReplaceSouth ( lat ) ; } if ( lon < box . West ) { box = box . ReplaceWest ( lon ) ; } if ( lat > box . North ) { box = box . ReplaceNorth ( lat ) ; } if ( lon > box . East ) { box = box . ReplaceEast ( lon ) ; } if ( lon > 0 && lon < minPosLon ) { minPosLon = lon ; } if ( lon < 0 && lon > maxNegLon ) { maxNegLon = lon ; } if ( Math . Abs ( lon - next . Longitude ) > Constants . H3 . M_PI ) { isTransmeridian = true ; } } if ( isTransmeridian ) { box = box . ReplaceEW ( maxNegLon , minPosLon ) ; } return box ; }
Convert GeoLoop to bounding box for loop
Convert GeoLoop to bounding box for loop
// Save the min positive and max negative longitude for // use in the transmeridian case // check for arcs > 180 degrees longitude, flagging as transmeridian // Swap east and west if transmeridian
None
LinkedGeoLoop
this
loop
None