6. Spatial Indexing¶
6.1 Spatial Index Definition¶
A store’s spatial index is a regular N-dimensional grid pinned to the
level-0 chunk shape. It is defined by root zarr_vectors keys:
Key |
Meaning |
|---|---|
|
One |
|
|
|
Level-0 chunk extent, one positive float per axis ( |
|
Optional level-0 bin grid. It MUST divide |
|
Optional world position of the stored origin: |
The coordinate reference system, if any, is the root attribute
proj:projjson (§8.8).
A level may override chunk_shape and bins
(§6.6), replace the uniform grid with
octree leaves (§6.5), or add a leading non-spatial
chunk axis (§6.7).
6.2 Spatial Chunk Addressing¶
A chunk coordinate is an integer tuple, one entry per axis,
written dot-separated: 3.7, 2.1.0, <c_0.c_1.…c_{ndim-1}>.
chunk_coord_i = floor(position_i / chunk_shape_i)
Writers compute this in float64, so a vertex on a boundary belongs to
the upper chunk. Coordinates are absolute — the lower bound is not
subtracted — so data below the origin has negative chunk coordinates.
Empty chunks are absent from the store and read as “no data here”.
Chunk coordinate → array cell¶
Each per-chunk array spans the level’s chunk grid; the chunk at
absolute coordinate c is cell c - origin:
origin_i = floor(bounds_min_i / chunk_shape_i)
shape_i = floor(bounds_max_i / chunk_shape_i) - origin_i + 1
cell_i = chunk_coord_i - origin_i
using the level’s chunk_shape. A non-zero origin is stored as the
array’s chunk_grid_origin key; absent means zero. Chunk keys in
metadata such as nonempty_chunks stay absolute; the cell index is
where the bytes live. For bounds [-300, 300] and chunk_shape = 200
the grid has shape [4, 4, 4] and origin [-2, -2, -2], and chunk
-1.-1.1 is stored at <array>/c/1/1/3.
At a level with chunk_shape = r_i × root_chunk_shape_i, the chunk
covering a level-0 chunk is coord_0 // r_i; the grids nest exactly.
Sharding (§11.6) changes
neither keys nor cell indices.
6.3 Spatial Query Semantics¶
A box query [lo, hi) resolves to the absolute chunk set
c_i ∈ [floor(lo_i / chunk_shape_i), ceil(hi_i / chunk_shape_i) - 1]
intersected with the level’s grid. Readers fetch only chunks that
exist — listed by nonempty_chunks, or taken from the store while
presence is deferred (§7).
With a bin grid, a reader can narrow further to bins. Bins, like chunks, align to the coordinate origin:
bins_per_chunk_i = chunk_shape_i / bin_shape_i
local_i = floor(position_i / bin_shape_i) - chunk_coord_i * bins_per_chunk_i
At level 0 of a point cloud written without object ids, fragment f
of a chunk is the bin at unravel(f, bins_per_chunk) in C order
(§7.3), so one chunk read can
be subdivided cheaply.
6.4 Boundary Conditions¶
Each vertex is placed in exactly one chunk, floor(position / chunk_shape). The root cross_chunk_strategy says how connectivity
crosses chunk seams:
Value |
Meaning |
|---|---|
|
Each cross-chunk edge or face is a record in |
|
A vertex on a seam is duplicated into both chunks; readers recover connectivity by coordinate matching |
|
Both representations are written |
6.5 Octree Chunks¶
A level MAY replace its uniform chunks with octree chunks: grid cells merged into content-sized leaves, large where data is sparse and fine where it is dense. Octree chunks apply to 3-D point clouds and graphs, and convert to and from uniform chunks without loss.
Cell: one cell of the level’s uniform grid, the smallest leaf.
Root cube:
2**Dcells per side fromorigin_cell,D = max_depth.Leaf: an aligned cube of
2**(D - d)cells per side at depthd, addressedd/i.j.k. Each leaf is one chunk.Anchor: a leaf’s minimum-corner cell; the leaf’s data is stored at its anchor’s key.
Declaration¶
The level’s zarr_vectors object carries octree_chunks
(§8.3):
{
"zarr_vectors": {
"kind": "level",
"octree_chunks": {
"max_depth": 4,
"origin_cell": [0, 0, 0],
"target": 500.0,
"balanced": true,
"max_leaf_cells": null,
"shard_shape": null,
"shard_origin": null,
"fit_shards": true,
"weight": "vertices",
"leaves": 69
}
}
}
Key |
Meaning |
|---|---|
|
|
|
The root cube’s minimum-corner cell |
|
Largest leaf weight asked for; a single heavier cell stays one leaf |
|
Whether leaves sharing a face, edge or corner differ by at most one depth |
|
Widest leaf, in cells per side (a power of two); |
|
Shard grid the leaves were fitted to, in cells; |
|
|
|
What leaves are weighed by: |
|
Number of stored leaves |
During a conversion the object is {"converting": "to_octree"} or
{"converting": "to_uniform"}; a reader MUST NOT read the level then.
Layout¶
Path |
Contents |
|---|---|
|
|
|
|
|
As for uniform chunks, keyed by leaf anchors; manifest entries name |
|
Keyed by the source leaf’s anchor; see §10.9 |
A leaf holds its cells’ vertices and fragments end to end in Z order; the cell table records where each cell’s run starts.
Readers without octree support¶
Such a reader would take each leaf for one cell. Two mechanisms stop it:
While any level has
octree_chunks, the root lists theoctree_chunkscapability in bothformat_capabilitiesandrequired_capabilities. A reader that does not implement it MUST NOT read such a level.Every per-chunk array of an octree level ends its cell codecs (inside any sharding codec) with the marker codec
{"name": "zarr_vectors_octree_chunks"}, which leaves bytes unchanged, so a plain Zarr reader fails on an unknown codec instead of misreading.
6.6 Per-Level Chunk Shape¶
A level MAY set its own chunk_shape in its level object. It MUST be
a positive integer multiple r_i of the root chunk_shape on every
axis, and, where the level’s bin is not larger than its chunk, a
multiple of the level’s bin shape. A coarse level’s bin MAY be larger
than its chunk. A level without chunk_shape uses the root’s.
Level 0’s bin is the root base_bin_shape (or chunk_shape). A
coarser level records bin_shape and bin_ratio (its bin divided by
the root base_bin_shape, per axis, as floats) only in its own level
object; a level recording neither reads as level 0’s. See
§9.3.
chunk_shape, bin_shape, bin_ratio and bounds fix the layout of
written arrays; a writer MUST NOT change them on a populated level.
Larger coarse chunks amortise per-chunk overhead, as voxel-size scaling does for image pyramids. Cross-level links re-anchor their offsets into the target level’s grid (§7.5, §10.8).
6.7 Leading Non-Spatial Chunk Axes¶
A level MAY add one leading non-spatial axis to its chunk keys
(b.i.j.k): every per-chunk array gains a leading axis of length K,
origin 0, and object manifests use the extended coordinates. The
level’s chunk_dims names the axes, leading axis first; without it the
level is chunked by position only. Readers MUST check chunk_dims
before interpreting chunk keys. Two uses are defined, mutually
exclusive on a level (§8.3):
Attribute chunking: a categorical vertex attribute (
chunk_attribute_name) is the leading axis, with one label per bin inchunk_attribute_values, so a query for one value reads only its chunks. With 4 labels and a 5 × 5 × 5 grid,verticeshas shape(4, 5, 5, 5), and label 2 at(1, 0, 3)isvertices/c/2/1/0/3.Chunk sources (composite levels): the leading axis is
"source"; 0 is the level’s own cells and each other value is a store listed inchunk_sources. A manifest entry((s, i, j, k), f)withs >= 1names fragmentfof cell(i, j, k)in sources.