Grid — geocatalog.grid¶
Pixel grids: convert between a GeoSlice and a pixel window, check and
snap slices to a raster's grid, and count the whole pixels in a length.
Windows¶
geocatalog.grid.slice_to_window(slice_, transform)
¶
Convert a CRS-unit GeoSlice to a pixel-space Window.
Lossy in the time / CRS axes — the returned Window carries
neither.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/geoslice.py
geocatalog.grid.window_to_slice(window, transform, crs, interval, resolution)
¶
Inverse of slice_to_window. Mostly useful in tests and debugging.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/geoslice.py
geocatalog.grid.PIXEL_PRECISION = 3
module-attribute
¶
Grid alignment¶
geocatalog.grid.Align = Literal['off', 'warn', 'error', 'snap']
module-attribute
¶
Construction-time alignment policy for GeoSlice.
"off": skip the check entirely (today's behaviour)."warn": emit aGridAlignmentWarningvia the standard librarywarningsmodule and continue with the original bounds."error": raiseValueErroron the first misaligned axis."snap": round outward while preserving the affine origin (xminandymaxfor north-up rasters).
geocatalog.grid.is_grid_aligned(a, b, *, tol=None, explain=False)
¶
Are a and b on the same pixel lattice?
Two slices are co-registered iff their resolutions match (within
tol) and their per-axis origin offsets are congruent modulo
resolution.
CRS mismatch returns False — the lattice question is undefined
across CRSs. Reproject one side first via GeoSlice.to_crs if
that's the intent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
GeoSlice
|
First slice. |
required |
b
|
GeoSlice
|
Second slice. |
required |
tol
|
float | None
|
Absolute tolerance (CRS units) for the resolution and
origin checks. |
None
|
explain
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
bool | dict[str, Any]
|
|
Source code in packages/geotoolz-catalog/src/geocatalog/_src/grid.py
geocatalog.grid.GridAlignmentWarning
¶
Bases: UserWarning
Emitted by GeoSlice for align="warn" and align="snap".
A dedicated subclass so applications can filter alignment notices
independently of other UserWarning\ s — e.g. via
warnings.simplefilter("error", GridAlignmentWarning) in tests
or "ignore" in pipelines that have audited their slice sites.
Inherits from UserWarning so it is visible by default; unlike a
loguru log record it is not silenced by the library's
logger.disable("geocatalog") import-time hygiene.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/grid.py
geocatalog.grid.count_steps(length, step, *, tol=None, label='length')
¶
round(length/step), raising if not within tol of exact.
The "loud" counterpart to a bare round(L / r) — useful when a
subpixel residual would silently shift a grid by a fraction of a
pixel and surface much later as an off-by-one elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
numerator in CRS units (e.g. |
required |
step
|
float
|
denominator in CRS units (e.g. |
required |
tol
|
float | None
|
absolute tolerance (CRS units) on the residual
|
None
|
label
|
str
|
name of the dividend, surfaced in the error message. |
'length'
|
Returns:
| Type | Description |
|---|---|
int
|
Integer pixel count |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |