Skip to content

Mixed aperture "4/3" grids: cell_to_index()/get_parent()/get_children() use the wrong numbering scheme and error #31

Description

@gcol33

Mixed aperture "4/3" grids: cell_to_index(), get_parent(), get_children() use the wrong numbering scheme and error on every call

Defect

lonlat_to_cell() (R/grid_helpers.R:71-94) and cell_to_lonlat() (:112-134) both special-case g@aperture == "4/3" and call the dedicated cpp_lonlat_to_cell_ap43/cpp_cell_to_lonlat_ap43 C++ entry points, which use calc_grid_params_ap43() — a distinct cell-ID numbering scheme for mixed grids (src/rcpp_cell.cpp:1209).

cell_to_index() (R/grid_helpers.R:653-674), get_parent() (:692-731), and get_children() (:745-780) have no such special case: they always call aperture_to_int(g@aperture) (returns 3L for "4/3", R/constants.R:257-259) and feed that into the generic cpp_cell_to_quad_ij/cpp_cell_to_index/cpp_get_parent_index/cpp_get_children_indices, which use the pure aperture-3 numbering (calc_grid_params(), not the ap43 variant).

Reproduction

grid <- hex_grid(resolution = 6, aperture = "4/3")
cells <- lonlat_to_cell(c(0, 30, -60), c(10, 45, -30), grid)   # 3629 5216 10420
get_parent(cells, grid)
# Error: cell_id must be a finite value in [1, 7292] for resolution 6, aperture 3
cell_to_index(cells, grid)
# same error

7292 is 10*3^6+2 (the pure aperture-3 cell count), not the actual ap43 cell space for this grid — a documented, first-class hex_grid(aperture = "4/3") option throws on every call to these three functions.

Impact

tests/testthat/test-hierarchical-index.R only exercises apertures 3, 4, 7 — never "4/3" — so this is completely uncovered by CI.

Fix

Add the same g@aperture == "4/3" special-casing to cell_to_index(), get_parent(), and get_children() that lonlat_to_cell()/cell_to_lonlat() already have, routing through the ap43-aware C++ entry points.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions