{"id":30190673,"url":"https://github.com/extendr/h3o","last_synced_at":"2025-08-12T20:07:23.578Z","repository":{"id":132838746,"uuid":"611802318","full_name":"extendr/h3o","owner":"extendr","description":"🚀 Blazingly faster Uber H3 gridding in R 🐇","archived":false,"fork":false,"pushed_at":"2025-07-27T17:57:13.000Z","size":14149,"stargazers_count":28,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-10T18:37:23.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/extendr.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-09T15:20:15.000Z","updated_at":"2025-08-05T16:34:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"df95cc01-81f1-465d-9512-f8aa5d6d54a9","html_url":"https://github.com/extendr/h3o","commit_stats":{"total_commits":36,"total_committers":3,"mean_commits":12.0,"dds":0.05555555555555558,"last_synced_commit":"4cea595c7d6548196d15b3c4e23aa2dedf64fd12"},"previous_names":["extendr/h3o"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/extendr/h3o","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fh3o","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fh3o/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fh3o/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fh3o/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extendr","download_url":"https://codeload.github.com/extendr/h3o/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fh3o/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270127392,"owners_count":24531793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-12T20:07:20.235Z","updated_at":"2025-08-12T20:07:23.509Z","avatar_url":"https://github.com/extendr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# h3o\n\n\u003c!-- badges: start --\u003e\n\n[![](https://github.com/JosiahParry/h3o/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/JosiahParry/h3o/actions/workflows/R-CMD-check.yaml)\n\n\u003c!-- badges: end --\u003e\n\n`{h3o}` is a lightweight R package for interacting with [Uber’s H3\nGeospatial Indexing system](https://github.com/uber/h3). The R package\nuses [extendr](https://extendr.github.io/) to wrap the eponymous [h3o\nRust crate](https://crates.io/crates/h3o), which offers a pure Rust\nimplementation of H3, so no linking to Uber’s H3 C library. The package\nis also intended to work with the\n[`{sf}`](https://github.com/r-spatial/sf) package for geometric\noperations and as a bonus represents the H3 class as\n[`{vctrs}`](https://github.com/r-lib/vctrs), so they work seamlessly\nwithin a tidyverse workflow.\n\n## Installation\n\nYou can install the release version of `{h3o}` from CRAN with:\n\n``` r\ninstall.packages(\"h3o\")\n```\n\nOr you can install the development version from\n[GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"pak\")\npak::pak(\"JosiahParry/h3o\")\n```\n\n## Example\n\nH3 vectors can be created from `POINT` geometry columns (`sfc` objects)\ndefined by sf.\n\n``` r\nlibrary(h3o)\nlibrary(dplyr)\nlibrary(sf)\nlibrary(tibble)\n\nxy \u003c- data.frame(\n  x = runif(100, -5, 10),\n  y = runif(100, 40, 50)\n)\n\npnts \u003c- st_as_sf(\n  xy,\n  coords = c(\"x\", \"y\"),\n  crs = 4326\n)\n\npnts |\u003e mutate(h3 = h3_from_points(geometry, 5))\n#\u003e Simple feature collection with 100 features and 1 field\n#\u003e Geometry type: POINT\n#\u003e Dimension:     XY\n#\u003e Bounding box:  xmin: -4.687389 ymin: 40.09688 xmax: 9.911612 ymax: 49.97784\n#\u003e Geodetic CRS:  WGS 84\n#\u003e First 10 features:\n#\u003e                      geometry              h3\n#\u003e 1   POINT (4.504552 45.26616) 851f93d7fffffff\n#\u003e 2   POINT (1.816329 40.94935) 853946abfffffff\n#\u003e 3  POINT (-2.147328 46.43598) 85184183fffffff\n#\u003e 4   POINT (3.260273 41.34728) 853940a3fffffff\n#\u003e 5   POINT (-1.50323 46.38411) 85186a53fffffff\n#\u003e 6  POINT (0.1499664 42.05342) 85397567fffffff\n#\u003e 7   POINT (4.900316 41.40955) 85394cdbfffffff\n#\u003e 8  POINT (-1.195541 46.94178) 85186e6bfffffff\n#\u003e 9   POINT (9.911612 49.19627) 851faa37fffffff\n#\u003e 10 POINT (-3.434653 45.27516) 85184ecffffffff\n```\n\nH3 vectors also have an `st_as_sfc()` method which allows conversion of\nH3 cell indexes into sf `POLYGON`s.\n\n``` r\n# replace geometry\nh3_cells \u003c- pnts |\u003e\n  mutate(\n    h3 = h3_from_points(geometry, 4),\n    geometry = st_as_sfc(h3)\n  )\n\n# plot the hexagons\nplot(st_geometry(h3_cells))\n```\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-1-1.png\"\nstyle=\"width:100.0%\" /\u003e\n\nH3 cell centroids can be returned using `h3_to_points()`. If `sf` is\navilable, the results will be returned as an `sfc` (sf column) object.\nOtherwise it will return a list of `sfg` (sf geometries).\n\n``` r\n# fetch h3 column\nh3s \u003c- h3_cells[[\"h3\"]]\n\n# get there centers\nh3_centers \u003c- h3_to_points(h3s)\n\n# plot the hexagons with the centers\nplot(st_geometry(h3_cells))\nplot(h3_centers, pch = 16, add = TRUE, col = \"black\")\n```\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-2-1.png\"\nstyle=\"width:100.0%\" /\u003e\n\n`H3Edge` vectors representing the boundaries of H3 cells can be created\nwith `h3_edges()`, `h3_shared_edge_pairwise()`, and\n`h3_shared_edge_sparse()`.\n\n``` r\ncell_edges \u003c- h3_edges(h3s[1:3])\ncell_edges\n#\u003e [[1]]\n#\u003e \u003cH3Edge[6]\u003e\n#\u003e [1] 1141f93dffffffff 1241f93dffffffff 1341f93dffffffff 1441f93dffffffff\n#\u003e [5] 1541f93dffffffff 1641f93dffffffff\n#\u003e \n#\u003e [[2]]\n#\u003e \u003cH3Edge[6]\u003e\n#\u003e [1] 1143946bffffffff 1243946bffffffff 1343946bffffffff 1443946bffffffff\n#\u003e [5] 1543946bffffffff 1643946bffffffff\n#\u003e \n#\u003e [[3]]\n#\u003e \u003cH3Edge[6]\u003e\n#\u003e [1] 11418419ffffffff 12418419ffffffff 13418419ffffffff 14418419ffffffff\n#\u003e [5] 15418419ffffffff 16418419ffffffff\n```\n\nWe’ve created a list of each cell’s edges. We can flatten them using\n`flatten_edges()`.\n\n``` r\ncell_edges \u003c- flatten_edges(cell_edges)\ncell_edges\n#\u003e \u003cH3Edge[18]\u003e\n#\u003e  [1] 1141f93dffffffff 1241f93dffffffff 1341f93dffffffff 1441f93dffffffff\n#\u003e  [5] 1541f93dffffffff 1641f93dffffffff 1143946bffffffff 1243946bffffffff\n#\u003e  [9] 1343946bffffffff 1443946bffffffff 1543946bffffffff 1643946bffffffff\n#\u003e [13] 11418419ffffffff 12418419ffffffff 13418419ffffffff 14418419ffffffff\n#\u003e [17] 15418419ffffffff 16418419ffffffff\n```\n\nThese can be cast to sfc objects using `st_as_sfc()`.\n\n``` r\nst_as_sfc(cell_edges)\n#\u003e Geometry set for 18 features \n#\u003e Geometry type: LINESTRING\n#\u003e Dimension:     XY\n#\u003e Bounding box:  xmin: -2.518472 ymin: 40.84516 xmax: 4.818449 ymax: 46.60887\n#\u003e Geodetic CRS:  WGS 84\n#\u003e First 5 geometries:\n#\u003e LINESTRING (4.748771 44.94225, 4.818449 45.17055)\n#\u003e LINESTRING (4.201051 44.99631, 4.440499 44.85539)\n#\u003e LINESTRING (4.440499 44.85539, 4.748771 44.94225)\n#\u003e LINESTRING (4.578042 45.31175, 4.268915 45.22437)\n#\u003e LINESTRING (4.818449 45.17055, 4.578042 45.31175)\n```\n\nAdditionally, you can get the vertexes of H3 cell indexes using\n`h3_to_vertexes()` which returns an `sfc_MULTIPOINT`.\n\n``` r\nh3_to_vertexes(h3s)\n#\u003e Geometry set for 100 features \n#\u003e Geometry type: MULTIPOINT\n#\u003e Dimension:     XY\n#\u003e Bounding box:  xmin: -5.049869 ymin: 39.94716 xmax: 10.37721 ymax: 50.35027\n#\u003e Geodetic CRS:  WGS 84\n#\u003e First 5 geometries:\n#\u003e MULTIPOINT ((4.268915 45.22437), (4.201051 44.9...\n#\u003e MULTIPOINT ((1.563896 41.22113), (1.508041 40.9...\n#\u003e MULTIPOINT ((-2.164091 46.60887), (-2.470648 46...\n#\u003e MULTIPOINT ((2.941338 41.43962), (2.880845 41.2...\n#\u003e MULTIPOINT ((-1.602187 46.52355), (-1.907502 46...\n```\n\n## Bench marks\n\nSince h3o is written in Rust, it is very fast.\n\n### Creating polygons\n\n``` r\nh3_strs \u003c- as.character(h3s)\nbench::mark(\n  h3o = st_as_sfc(h3s),\n  h3jsr = h3jsr::cell_to_polygon(h3_strs)\n)\n#\u003e # A tibble: 2 × 6\n#\u003e   expression      min   median `itr/sec` mem_alloc `gc/sec`\n#\u003e   \u003cbch:expr\u003e \u003cbch:tm\u003e \u003cbch:tm\u003e     \u003cdbl\u003e \u003cbch:byt\u003e    \u003cdbl\u003e\n#\u003e 1 h3o         432.3µs  477.7µs     1972.    9.85KB     14.6\n#\u003e 2 h3jsr        8.19ms   8.83ms      110.    2.69MB     89.4\n```\n\n### Converting polygons to H3 cells:\n\n``` r\nnc \u003c- st_read(system.file(\"gpkg/nc.gpkg\", package = \"sf\"), quiet = TRUE) |\u003e\n  st_transform(4326) |\u003e\n  st_geometry()\n\nbench::mark(\n  h3o = sfc_to_cells(nc, 5, \"centroid\"),\n  h3jsr = h3jsr::polygon_to_cells(nc, 5),\n  check = FALSE\n)\n#\u003e # A tibble: 2 × 6\n#\u003e   expression      min   median `itr/sec` mem_alloc `gc/sec`\n#\u003e   \u003cbch:expr\u003e \u003cbch:tm\u003e \u003cbch:tm\u003e     \u003cdbl\u003e \u003cbch:byt\u003e    \u003cdbl\u003e\n#\u003e 1 h3o          4.96ms   5.29ms     185.     21.4KB    11.2 \n#\u003e 2 h3jsr       28.79ms   29.5ms      33.8   748.7KB     5.19\n```\n\n### Converting points to cells\n\n``` r\nbench::mark(\n  h3o = h3_from_points(pnts$geometry, 3),\n  h3jsr = h3jsr::point_to_cell(pnts$geometry, 3),\n  check = FALSE\n)\n#\u003e # A tibble: 2 × 6\n#\u003e   expression      min   median `itr/sec` mem_alloc `gc/sec`\n#\u003e   \u003cbch:expr\u003e \u003cbch:tm\u003e \u003cbch:tm\u003e     \u003cdbl\u003e \u003cbch:byt\u003e    \u003cdbl\u003e\n#\u003e 1 h3o         105.2µs  124.5µs     7114.      848B    11.7 \n#\u003e 2 h3jsr        2.57ms   2.96ms      329.     975KB     8.49\n```\n\n### Retrieve edges\n\n``` r\nbench::mark(\n  h3o = h3_edges(h3s),\n  h3jsr = h3jsr::get_udedges(h3_strs),\n  check = FALSE\n)\n#\u003e # A tibble: 2 × 6\n#\u003e   expression      min   median `itr/sec` mem_alloc `gc/sec`\n#\u003e   \u003cbch:expr\u003e \u003cbch:tm\u003e \u003cbch:tm\u003e     \u003cdbl\u003e \u003cbch:byt\u003e    \u003cdbl\u003e\n#\u003e 1 h3o         351.7µs  509.5µs     1674.      848B     13.1\n#\u003e 2 h3jsr        1.72ms   2.88ms      363.    67.9KB     16.2\n```\n\n### Get origins and destinations from edges.\n\n``` r\n# get edges for a single location\neds \u003c- h3_edges(h3s[1])[[1]]\n# strings for h3jsr\neds_str \u003c- as.character(eds)\n\nbench::mark(\n  h3o = h3_edge_cells(eds),\n  h3jsr = h3jsr::get_udends(eds_str),\n  check = FALSE\n)\n#\u003e # A tibble: 2 × 6\n#\u003e   expression      min   median `itr/sec` mem_alloc `gc/sec`\n#\u003e   \u003cbch:expr\u003e \u003cbch:tm\u003e \u003cbch:tm\u003e     \u003cdbl\u003e \u003cbch:byt\u003e    \u003cdbl\u003e\n#\u003e 1 h3o          14.3µs     22µs    40992.    7.86KB     16.4\n#\u003e 2 h3jsr       646.1µs    741µs     1250.   19.82KB     15.4\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Fh3o","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextendr%2Fh3o","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Fh3o/lists"}