vignette("duckh3")).duckdb dependency to v2.0.0 See https://r.duckdb.org/news/index.html#duckdb-200.resolution no longer defaults to 8: it is now required in ddbh3_lonlat_to_h3(), ddbh3_lonlat_to_spatial(), ddbh3_get_parent(), ddbh3_get_children(), ddbh3_get_center_child(), ddbh3_get_n_children() and ddbh3_get_child_pos(), as it already was in ddbh3_points_to_*(), ddbh3_polygons_to_*() and ddbh3_lines_to_*(). A fixed default is rarely right for relative operations (e.g. the parent at resolution 8 of a resolution 6 cell is NA) (#40).containment (and buffer_scale) now come right after resolution in ddbh3_polygons_to_spatial() and ddbh3_lines_to_spatial(), as in ddbh3_polygons_to_h3() and ddbh3_lines_to_h3(); and nested comes right after new_column in every function. Only calls that pass these arguments by position are affected (#40).ddbh3_h3_to_spatial() and ddbh3_h3_to_points() now follow mode: they return a duckspatial_df (mode = "duckspatial", the default) or an sf (mode = "sf"), both with the indexes and their geometry in EPSG:4326. Before, they returned a wk_wkb vector without CRS (#37).ddbh3_default_conn() no longer reuses a default connection created by duckspatial with bigint = "numeric", which silently rounded UBIGINT H3 indexes. It now warns and replaces it with an integer64 connection.new_column, h3, h3vertex, lon, lat) and the geometry column name are now quoted as SQL identifiers, so names with spaces or quotes work and SQL expressions passed as column names are no longer executed.new_column, the result now replaces that column. Before, the result was added as <new_column>_1 and the original column kept its old values.name equal to the source table and overwrite = TRUE) no longer deletes the source table: the result is now built in a staging table and swapped in place.ddbh3_create_conn() now registers the ddbh3_* macros, so they work inside dplyr::mutate() on user-created connections.ddbh3_default_conn(create = FALSE) no longer errors when no default connection exists.ddbh3_vertex_to_lon(), ddbh3_vertex_to_lat() and ddbh3_is_vertex() no longer reject valid H3 vertexes in vectorized mode, and ddbh3_is_vertex() returns FALSE for invalid input instead of erroring.ddbh3_create_conn() and ddbh3_default_conn() set geometry_always_xy = true, which DuckDB >= 2.0 requires before spheroid functions such as duckspatial::ddbs_area() can run on H3 geometries. This keeps the pre-2.0 axis convention that duckspatial's measure functions are written for.ddbh3_child_pos_to_cell() no longer errors when the child position column is stored as a double (e.g. data.frame(h3child_pos = 0)).overwrite = TRUE (e.g. name = "my_schema.my_table") no longer moves the table to the main schema (#25).ddbh3_default_conn(): the default connection is now set up with the h3 extension (and bigint = "integer64") when needed, in vectorized and table modes (#26).ddbh3_get_base_cell_number(), ddbh3_grid_disk(), ddbh3_grid_disk_distances(), ddbh3_grid_ring(), ddbh3_grid_path_cells() and ddbh3_grid_distance() now quote column names, so names with spaces or quotes work (#27).ddbh3_grid_disk_distances() now returns all the cells within distance k (it only returned the cells at distance 1), also in vectorized mode (#28).ddbh3_h3_to_spatial() and ddbh3_h3_to_points() now accept a bit64::integer64 vector of cells in vectorized mode (#31).ddbh3_h3_to_spatial(), ddbh3_lonlat_to_spatial() and ddbh3_h3_to_points() are always stored with the EPSG:4326 CRS. Before, a spatial input in another CRS gave its CRS to the new geometries when writing a table with name (#31).ddbh3_vertex_to_spatial() on a nested vertex column now builds the MULTIPOINT geometries in a single query. It now works with name, and with spatial inputs whatever their geometry column is called (#32).ddbh3_edge_to_spatial() and ddbh3_vertex_to_spatial() now detect nested columns in table names and lazy tables (#32).ddbh3_grid_path_cells(), ddbh3_grid_distance() and ddbh3_child_pos_to_cell() give an informative error when x is a vector (they need a table with two columns) instead of an obscure SQL error (#30).k must be between 0 and 1500, buffer_scale must be a positive number, h3_format must be a single string, and inputs without a CRS give the "CRS must be EPSG:4326" error (#33).ddbh3_compact() errors when new_column is one of the by columns (#33).ddbh3_default_conn() now applies threads and memory_limit_gb to an existing default connection, instead of silently ignoring them (#33).NAs (#33).ddbh3_create_conn() warns when bigint is not "integer64", since H3 indexes stored as UBIGINT are then rounded (#33).mode is now validated: values other than "duckspatial" or "sf" give an error, instead of silently returning a duckspatial_df (#36, reported upstream as Cidree/duckspatial#197).NA for valid cells (e.g. ddbh3_get_parent() to a finer resolution) now warn that the other arguments may be incompatible with the input, instead of saying that x is invalid. Empty list results (e.g. ddbh3_get_children() to a coarser resolution) now warn too (#37).ddbh3_compact() and ddbh3_uncompact() return a zero-length vector for a zero-length input (they returned NULL), and validate and compute in a single query in vectorized mode (#37).ddbh3_default_conn(bigint = ...) warns that bigint is ignored, instead of failing with formal argument "bigint" matched by multiple actual arguments (#38).NA logical vectors (e.g. NA), and other logical vectors give an informative error. Before, factors were taken as table names (#38).ddbh3_h3_to_vertexes() now works inside dplyr::mutate() (#39).ddbh3_default_conn() is mandatory: it is created when needed since #26 (#42).nested is ignored in vectorized mode, that ddbh3_polygons_to_spatial() and ddbh3_lines_to_spatial() drop features without cells, that resolution must be compatible with the input cells in hierarchy functions, and that replacing a bigint = "numeric" default connection leaves the old one open (#42).Remove arrow lambda syntax for compatibility with DuckDB v2.0 (#6).
The @returns documentation now states that spatial outputs are returned as sf with mode = "sf", that *_to_spatial() functions and ddbh3_h3_to_points() always return spatial output, and that mode is ignored for non-spatial results (#10).
Internal helpers now reuse those of duckspatial (e.g. identifier quoting with sql_ident(), table names with sql_table(), and extension checks), so both packages handle names and connections the same way. Two related problems were reported upstream: Cidree/duckspatial#195 (schema-qualified table names as input) and Cidree/duckspatial#196 (length-2 name).
Vectorized mode is up to ~40x faster: input validation and evaluation now run in a single query, and the default connection is no longer re-initialised on every call. The h3 extension check is cached for the default connection.
Faster polygon/line to H3 conversion: polyfill reads WKB instead of WKT, the geometry type is validated on the already-prepared input instead of preparing it twice, and the cell list is no longer de-duplicated twice.
Internal clean-up: the input preparation shared by every function is now a single helper (ddbh3_points_to_*() use the templates too), and SQL string literals are always quoted with the duckspatial helper (#43).
All functions gain a mode argument that can be set to "sf" or "duckspatial" to return the output in that format. Alternatively, the user can use duckspatial::ddbs_options() to set the mode globally.
H3 directed edges: ddbh3_h3_to_edge(), ddbh3_h3_to_edges(), ddbh3_edge_to_origin(), ddbh3_edge_to_destination(), ddbh3_edge_to_h3(), ddbh3_reverse_edge(), ddbh3_get_edge_length() and ddbh3_edge_to_spatial() create directed edges from H3 cells and convert them to cells, lengths and lines. They also work inside dplyr::mutate() on lazy tables (except ddbh3_edge_to_spatial()).
ddbh3_compact() and ddbh3_uncompact(): compact a set of H3 cells into the smallest set of cells covering the same area (optionally per group with by), and uncompact cells back to a single resolution. ddbh3_compact() also works inside dplyr::summarise(), and ddbh3_uncompact() inside dplyr::mutate() on list columns.
ddbh3_h3_to_local_ij() and ddbh3_local_ij_to_h3() convert H3 cells to local IJ coordinates relative to an origin cell, and back. They also work inside dplyr::mutate() on lazy tables.
ddbh3_is_index() checks if an index is any valid H3 index (cell, directed edge or vertex), and ddbh3_digits_to_h3() builds H3 cells from a base cell and a list of digits. They also work inside dplyr::mutate() on lazy tables.
H3 metrics: ddbh3_get_area() gets the area of H3 cells, ddbh3_great_circle_distance() gets the great circle distance between two points, and ddbh3_get_hexagon_area_avg() and ddbh3_get_hexagon_edge_length_avg() get the average hexagon area and edge length at one or more resolutions. They also work inside dplyr::mutate() on lazy tables.
ddbh3_is_edge(): check if an index is a valid H3 directed edge.
ddbh3_is_neighbor(): check if two H3 cells are neighbors.
ddbh3_grid_path_cells(): find a grid path connecting two H3 cells.
ddbh3_grid_distance(): get the grid distance between two H3 cells.
ddbh3_grid_disk(), ddbh3_grid_disk_distances(), ddbh3_grid_ring(): get H3 grid neighborhoods (disks, rings, and distances). ddbh3_grid_disk_distances() returns the grid distance of each cell in a second column (new_column = c("h3neighbors", "h3distance")), and all three use the pentagon-safe algorithm by default (safe = TRUE).
ddbh3_max_grid_disk_size(): get the maximum grid disk size for a given distance k.
ddbh3_child_pos_to_cell(): get an H3 child cell from a parent and child position.
ddbh3_get_base_cell_number(): get the base cell number of an H3 cell.
The neighborhood functions, ddbh3_get_base_cell_number() and ddbh3_child_pos_to_cell() also work inside dplyr::mutate() on lazy tables (#30).
Documentation fixes: roxygen templates, aliases, examples and DESCRIPTION (#34).
Requires DuckDB >= 1.5.6
Requires duckspatial >= 1.3.0
Functions in vectorized mode automatically parse to UBIGINT when the input is a numeric vector.
Error message on wrong CRS is now displayed correctly (#3).
ddbh3_polygons_to_h3() / ddbh3_lines_to_h3() add a list column with
the H3 cells intersecting each feature (string or UBIGINT).ddbh3_polygons_to_spatial() / ddbh3_lines_to_spatial() return one row
per intersecting cell, with geometry replaced by the cell hexagon
boundary.overlap
containment by default); lines are polyfilled via a buffer-then-exact-trim
strategy since they have no native polyfill (buffer_scale argument).Learn more about this release here{target="_blank"}.