gbif / occurrence-cube

Workflows for producing species occurrence cubes from GBIF mediated data
Apache License 2.0
4 stars 1 forks source link

Support a hexagonal grid #23

Open MattBlissett opened 2 months ago

MattBlissett commented 2 months ago

Feedback and discussion from the B³ Hackathon: A hexagonal grid could help for statistical analysis. The OGC defines a Discrete Global Grid System as having constant or near-constant area cells at a particular resolution.

See also https://en.wikipedia.org/wiki/Discrete_global_grid#Standard_equal-area_hierarchical_grids and https://ecce.esri.ca/blog/2023/06/24/introduction-to-discrete-global-grid-system-dggs/

My investigation

Applied Open-Source Discrete Global Grid Systems summarizes available software libraries and the grids they implement, including the Uber H3 grid developed by Uber for fast indexing — though H3 is not a constant area grid. It concludes:

rHEALPix on the other side, and ISEA-based DGGS (Snyder equal area projection in DGGRID and OpenEAGGR), are ideal candidates for gridded representation of continuous phenomena (like in GeoTIFF or NetCDF formats). For example, H3 is an aperture 7 hexagonal grid that use the Gnomonic projection which is not equal area. Google S2 builds on a cube-sphered projection which only guarantees area variations to stay within a factor of 1.5 (Veach et al., 2017). Thus, H3 and S2 should not be considered in environmental modelling or equal-area DGGS-based data cubes, because they do not have equal area cells across the globe. For example, when intending to aggregate large scale landuse, forest cover, soils and climatologies and calculate area-based statistics, rHEALPix and ISEA-based grids should be used.

The open source* Open EAGGR library implements two grids, ISEA4T with triangles and ISEA3H with hexagons. The project is written in C++, but includes bindings for Java, Python, PostgreSQL and ElasticSearch. It currently only builds in Eclipse, but recent commits on a branch might be improving this. I have compiled the library on Linux, and have it working in Java.

The library works, but:

It would be worth investigating dggridR as well.

* Having now read to the end of the README, I'm not sure this library is open source. It is "supplied under the LGPL v3 subject to the End User License Agreement", and the EULA restricts use to the UK and EU.

Please comment or like this issue if you would like us to implement a hexagonal grid.

MattBlissett commented 2 months ago

This paper describes an identification scheme for the cells of the ISEA3H grid which is less opaque: https://www.tandfonline.com/doi/full/10.1080/15230406.2018.1455157

+53 40766511 074019041

+53 — resolution 9 of the icosahedron, negative longitude

40766511 — latitude, 40.766511°

074019041 — longitude, -74.019041°

And there's a Java implementation! https://github.com/mocnik-science/geogrid?tab=readme-ov-file

MattBlissett commented 3 weeks ago

Note OBIS have explored the Uber H3 grid: https://iobis.github.io/notebook-ospar/

DavidAClarke commented 2 weeks ago

I am quite interested in exploring the use of hexagonal grids, particularly from an Antarctic perspective. Antarctica introduces some complexities with regard to grid systems, with the military grid system seemingly not extending south enough and the universal polar stereographic (UPS) not extending north enough. The H3 grid appears to be truly global and thus applicable to Antarctica.

timrobertson100 commented 2 weeks ago

Just for info We've had a GBIF Helpdesk request from someone working at the CEH in the UK asking for a data cube that requires an ISEA3H join.

MattBlissett commented 1 week ago

The ISEA3H grid is now available for use — other hexagonal grids may be added, this is to support the direct request we had from a user.

This is an example download: https://www.gbif.org/occurrence/download/0000005-240626123714530

And this is the SQL function for use with the GBIF API: https://techdocs.gbif-uat.org/en/data-use/api-sql-download-functions#isea3h-grid-cell-code-gbif_isea3hcode

And standalone: https://techdocs.gbif-uat.org/en/data-use/b-cubed/sql-cube-functions

It is using the geogrid library linked above. We will prepare shapefiles/geopackage/wkt (whatever seems appropriate) of the grid at various resolutions to help users — also for the existing square grids.