h3-py
h3-py copied to clipboard
Traversing the globe at one resolution
Hello from Hub Ocean in Norway! We are creating a platform for anyone who wants to share and consume data related to the ocean.
I am currently creating hexagons within our PostGIS database to divide up huge queries of data. But I think that H3 would be a better tool for that job now that we have our pipelines in python.
I am lacking example code for how to do this with H3.
I want to define a grid at a fixed resolution that I can iterate over. So that I can perform a SELECT on each hex defined as a polygon / list of points that postGIS can consume.
Anyone who would like to help, or know where I can look?
Regards, Henrik :D
There are two PostgreSQL extensions for H3, which might be helpful: https://h3geo.org/docs/community/bindings#postgresql
To iterate over the entire world, the easiest option at the moment is to start with the 122 resolution 0 indexes and then take their children at the desired resolution. For example:
my_resolution = 5
for index_0 in h3.get_res0_indexes():
for child_index in h3.h3_to_children(index_0, my_resolution):
polygon = h3.h3_to_geo_boundary(child_index, geo_json=True)
# do something with the polygon
Thanks a lot for your help! Just a sanity check; will this - at one single resolution - not overlap or miss any area of the globe?
Thanks a lot for your help! Just a sanity check; will this - at one single resolution - not overlap or miss any area of the globe?
Sorry for the slow reply: Yes, this will cover the whole globe with no overlaps.