Is there a way to polyfill edge to edge or as much as possible (Res 8) without increasing the resolution. Black boundary is the polygon boundary I am trying to polyfill completely
This happens because polyfill
only returns cells whose centroid falls into the polygon.
In your case, you could use polyfill on a finer resolution and then use h3_to_parent
to convert back to your desired resolution.
Keep in mind that this isn't guaranteed to cover the whole geometry. But in practice, using sufficiently fine resolution for polyfill
usually does the trick (and the fact that some cells with only a tiny intersection might not generated is often even useful).
Here is an example using Geopandas and H3-Pandas, but of course, the logic works with any implementation of the H3
API.
import geopandas as gpd
import h3pandas
# Choose a random country boundary (Tanzania)
gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')).iloc[1:2]
gdf.h3.polyfill_resample(2)
gdf.h3.polyfill_resample(4).h3.h3_to_parent_aggregate(2)