/// <summary> /// polyfill takes a given GeoJSON-like data structure and preallocated, /// zeroed memory, and fills it with the hexagons that are contained by /// the GeoJSON-like data structure. /// /// This implementation traces the GeoJSON geofence(s) in cartesian space with /// hexagons, tests them and their neighbors to be contained by the geofence(s), /// and then any newly found hexagons are used to test again until no new /// hexagons are found. /// </summary> /// <param name="polygon">The geofence and holes defining the relevant area</param> /// <param name="res">The Hexagon resolution (0-15)</param> /// <returns>List of H3Index that compose the polyfill</returns> /// <!-- /// algos.c /// void H3_EXPORT(polyfill) /// --> public static List <H3Index> Polyfill(this GeoPolygon polygon, int res) { // TODO: Eliminate this wrapper with the H3 4.0.0 release (int failure, var result) = polygon.PolyFillInternal(res); if (failure == 0) { return(result.Where(r => r != 0).ToList()); } // The polyfill algorithm can theoretically fail if the allocated memory is // not large enough for the polygon, but this should be impossible given the // conservative overestimation of the number of hexagons possible. int numHexagons = polygon.MaxPolyFillSize(res); return(new H3Index[numHexagons].ToList()); }