The conversion Module

Two maps of the same polygon over New Zealand filled with cells. Left: 518 cells, all at resolution 5. Right: the same coverage after compact_cells, 182 cells of mixed resolutions, with large low-resolution cells in the interior and small high-resolution cells along the edges.

Fig. 20 compact_cells: a uniform resolution 5 polyfill of a polygon (left) and the same set of cells after compaction (right), where any nine siblings all present in the set are replaced by their parent, repeatedly. The interior collapses to coarse cells while the edge detail is preserved exactly – here 518 cells become 182. The change of texture partway down is the boundary between the equatorial Q cells (longitude-latitude rectangles) and the south polar S cells (skew quads and darts, which are not).

CellZoneFromPoly(feature, ...)

Cells covering a polygon, found by refining a bounding cell.

compact_cells(cells[, N_side])

Compact a set of rHEALPix DGGS cells by repeatedly merging complete groups of N_side ** 2 siblings into their parent until no further merging is possible.

compress_order_cells(cells[, recursive, N_side])

Compress and sort a collection of cells.

get_finest_containing_cell(polygon, rdggs)

Finds the finest DGGS Cell containing a given cartesian polygon

class rhealpixdggs.conversion.CellZoneFromPoly(feature: tuple[str, ~shapely.geometry.polygon.Polygon | ~shapely.geometry.multipolygon.MultiPolygon], res_limit: int, return_cells: bool, file: ~typing.TextIO | None = None, bounding_cell: ~rhealpixdggs.cell.Cell | None = None, rdggs: ~rhealpixdggs.dggs.RHEALPixDGGS = <rhealpixdggs.dggs.RHEALPixDGGS object>)[source]

Bases: object

Cells covering a polygon, found by refining a bounding cell.

This is a producer, not a collection: it walks down from a cell that contains the geometry, keeping cells the geometry contains outright and recursing into ones it merely overlaps, until res_limit. For a set of cells to hold and operate on afterwards – union, intersection, difference, the hierarchy walks of OGC Topic 21 – see rhealpixdggs.zoneset.ZoneSet.

rhealpixdggs.conversion.compact_cells(cells: Iterable[str], N_side: int = 3) → set[str][source]

Compact a set of rHEALPix DGGS cells by repeatedly merging complete groups of N_side ** 2 siblings into their parent until no further merging is possible. N_side defaults to 3 (the default for RHEALPixDGGS and most presets, e.g. WGS84_003); pass the N_side of the DGGS the cells actually belong to if it’s not 3 (e.g. 2 for WGS84_002), otherwise a complete sibling group will never be recognised as complete and nothing will compact.

All input cells must be at the same resolution (equal string length). Raises ValueError if the input contains cells at mixed resolutions. Returns a set; if the caller needs ordering, sort the result separately.

rhealpixdggs.conversion.compress_order_cells(cells: list[str], recursive: bool = False, N_side: int = 3) → list[str][source]

Compress and sort a collection of cells.

Each complete group of N_side ** 2 siblings is replaced by their parent cell. N_side defaults to 3 (the default for RHEALPixDGGS and most presets, e.g. WGS84_003); pass the N_side of the DGGS the cells actually belong to if it’s not 3 (e.g. 2 for WGS84_002), otherwise a complete sibling group will never be recognised as complete and nothing will compress. By default only one level of compression is performed. Pass recursive=True to repeat until no further compression is possible. The result is always deduplicated and sorted alphanumerically.

rhealpixdggs.conversion.get_finest_containing_cell(polygon: Polygon | MultiPolygon, rdggs: RHEALPixDGGS = <rhealpixdggs.dggs.RHEALPixDGGS object>) → Cell | None[source]

Finds the finest DGGS Cell containing a given cartesian polygon