h3-py
h3-py copied to clipboard
Polyfill not working, two different sets of Polygons
Hi there,
My application uses this library in order to take a shapefile of Canada and plot a grid of Hexagons (chloropleth map) and it seems when I use the same algorithm on two different shapefiles (sets of polygons), the polyfill returns the correct number of hexagons for one of them, and zero for the other. I have confirmed the issue has not to do with the resolution used. One of the shapefiles is just the provinces of Canada, and the other includes sea areas as well. My code is the following.
#obtain all hexagon locations
h3_list = []
exploded = canada_boundary.explode()
print(exploded.head())
for i, row in exploded.iterrows():
poly_fill=h3.polyfill(exploded.geometry[i].__geo_interface__, H3_res,geo_json_conformant=True)
print(len(poly_fill))
for y in poly_fill:
h3_list.append(y)
megaFrame = pd.DataFrame(h3_list,columns=['h3_cell'])
Any advice would be appreciated, thanks!
Ask any questions necessary.
Could you point me to the shapefiles? Or, better yet, do you think you could reduce it to a minimal example?
Hi there, good to hear back from someone.
In this example, poly_fill returns 0 for every Polygon in the exploded shapefile. We explode the shapefile because h3.polyfill can only accept singular Polygons.
#obtain all hexagon locations
exploded = canada_boundary.explode()
for i, row in exploded.iterrows():
poly_fill=h3.polyfill(exploded.geometry[i].__geo_interface__, H3_res,geo_json_conformant=True)
The shapefiles can be found at https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm
Ive only used the first two shape files, one being the provinces and territories cartographic and the other digital boundary.
It may be the geo interface thing but it worked for one of the shapefiles.
Please help, this issue is kind of pressing for me.
I found this Explanation regarding my issue.