Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

H3 polyfill is skipping the areas near the boundary I am trying to polyfill. (Python)

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why this happens

This happens because polyfill only returns cells whose centroid falls into the polygon.

What to do instead

In your case, you could use polyfill on a finer resolution and then use h3_to_parent to convert back to your desired resolution.

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]

Simple polyfill

gdf.h3.polyfill_resample(2)

enter image description here

"Finer" polyfill

gdf.h3.polyfill_resample(4).h3.h3_to_parent_aggregate(2)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading