H3Lib/Extensions/GeoFenceExtensions.cs
/// <summary>
/// Get hexagons along edge of lines of a polygon
/// </summary>
/// <param name="geofence"></param>
/// <param name="res"></param>
/// <returns></returns>
Get hexagons along edge of lines of a polygon
Get hexagons along edge of lines of a polygon
internal static HashSet<H3Index> GetEdgeHexagons(this GeoFence geofence, int res)
        {
            var found = new List<H3Index>();
            for (var i = 0; i < geofence.NumVerts; i++)
            {
                var origin = geofence.Verts[i];
                var destination = i == geofence.NumVerts - 1
                                      ? geofence.Verts[0]
                                      : geofence.Verts[i + 1];
                int numHexesEstimate = origin.LineHexEstimate(destination, res);
                for (var j = 0; j < numHexesEstimate; j++)
                {
                    var interpolate =
                        new GeoCoord
                            (
                             origin.Latitude * (numHexesEstimate - j) / numHexesEstimate +
                             destination.Latitude * j / numHexesEstimate,
                             origin.Longitude * (numHexesEstimate - j) / numHexesEstimate +
                             destination.Longitude * j / numHexesEstimate
                            );
                    var pointHex = interpolate.ToH3Index(res);
                    found.Add(pointHex);
                }
            }
            return new HashSet<H3Index>(found);
        }
internal static HashSet < H3Index > GetEdgeHexagons ( this GeoFence geofence , int res ) { var found = new List < H3Index > ( ) ; for ( var i = 0 ; i < geofence . NumVerts ; i ++ ) { var origin = geofence . Verts [ i ] ; var destination = i == geofence . NumVerts - 1 ? geofence . Verts [ 0 ] : geofence . Verts [ i + 1 ] ; int numHexesEstimate = origin . LineHexEstimate ( destination , res ) ; for ( var j = 0 ; j < numHexesEstimate ; j ++ ) { var interpolate = new GeoCoord ( origin . Latitude * ( numHexesEstimate - j ) / numHexesEstimate + destination . Latitude * j / numHexesEstimate , origin . Longitude * ( numHexesEstimate - j ) / numHexesEstimate + destination . Longitude * j / numHexesEstimate ) ; var pointHex = interpolate . ToH3Index ( res ) ; found . Add ( pointHex ) ; } } return new HashSet < H3Index > ( found ) ; }
Get hexagons along edge of lines of a polygon
Get hexagons along edge of lines of a polygon
None
GeoFence
this
res
int
None
geofence
None