diff --git a/xdggs/grid.py b/xdggs/grid.py index 969f4d0..8e0bf05 100644 --- a/xdggs/grid.py +++ b/xdggs/grid.py @@ -42,6 +42,9 @@ def cell_boundaries(self, cell_ids, backend="shapely"): def zoom_to(self, cell_ids, level: int): raise NotImplementedError() + def neighbours(self, cell_ids, ring=1): + raise NotImplementedError() + def translate_parameters(mapping, translations): def translate(name, value): diff --git a/xdggs/h3.py b/xdggs/h3.py index 0eb65a9..fc4d99e 100644 --- a/xdggs/h3.py +++ b/xdggs/h3.py @@ -7,14 +7,14 @@ import xarray as xr try: - from h3ronpy import change_resolution + from h3ronpy import change_resolution, grid_disk from h3ronpy.vector import ( cells_to_coordinates, cells_to_wkb_polygons, coordinates_to_cells, ) except ImportError: - from h3ronpy.arrow import change_resolution + from h3ronpy.arrow import change_resolution, grid_disk from h3ronpy.arrow.vector import ( cells_to_coordinates, cells_to_wkb_polygons, @@ -205,6 +205,11 @@ def zoom_to(self, cell_ids, level): return np.asarray(change_resolution(cell_ids, level)) + def neighbours(self, cell_ids, ring=1): + neighbours = grid_disk(cell_ids, k=ring, flatten=False) + + return neighbours + @register_dggs("h3") class H3Index(DGGSIndex): diff --git a/xdggs/healpix.py b/xdggs/healpix.py index ff642c3..6d449bb 100644 --- a/xdggs/healpix.py +++ b/xdggs/healpix.py @@ -322,6 +322,11 @@ def zoom_to(self, cell_ids, level): return zoom_to(cell_ids, self.level, level) + def neighbours(self, cell_ids, ring=1): + from healpix_geo.nested import kth_neighbourhood + + return kth_neighbourhood(cell_ids, depth=self.level, ring=ring) + def construct_chunk_ranges(chunks, until): start = 0