Tile Structure
Understanding the internal structure of GeoBrix tiles is essential for advanced use cases like custom UDFs, direct data manipulation, and performance optimization.
Overview
In GeoBrix, a tile is not a simple binary column. It is a structured type (struct) that represents a raster dataset along with its metadata and grid-cell information. When the tile is a bytes-free reference, the struct also carries the source path, window, and clip/CRS provenance. The same struct is shared by both execution tiers.
Tile Schema
A tile has the following structure:

struct<
cellid: bigint, -- Grid cell ID (never NULL; -1 when not tessellated)
raster: binary, -- Raster bytes (NULL when virtual)
path: string, -- Source path (virtual) or provenance (materialized)
path_mode: string, -- Storage mode: null, 'external', or 'managed'
window: struct<col_off,row_off,width,height>, -- Pixel window
clip_polygon: binary, -- Optional clip geometry (WKB)
clip_crs: string, -- CRS for clip_polygon
crs: string, -- Working/target CRS
metadata: map<string,string> -- Driver, extension, size, etc.
>
A tile is materialized when raster carries the encoded bytes (the common case, and the only form the JVM level consumes). A tile is virtual when raster is NULL and path + window are set — a bytes-free reference that materializes pixels on demand (a Python-level capability). For the full virtual/materialized model, see Virtual Tiles.
Field Descriptions
| Field | Type | Nullable | Description |
|---|---|---|---|
cellid | bigint (Long) | No | Grid cell identifier for tessellated rasters. -1 for a tile that was not tessellated. The field is never null. |
raster | binary | Yes | Encoded raster bytes when materialized; null when the tile is virtual (bytes-free). |
path | string | Yes | Set on a virtual tile, where it is the source the pixels are read from. On a materialized tile it is provenance of where the bytes came from (a reader's tile, a materialize=True output, a retile-family output); the bytes in raster are the data and are always read in preference to path. null when the tile has no single source file. |
path_mode | string | Yes | Storage mode for a virtual tile. null = materialized (raster bytes present) or plain FUSE-path virtual. "external" = FILE EXTERNAL virtual tile. "managed" = FILE MANAGED virtual tile (governed lifecycle). |
window | struct<col_off,row_off,width,height> | Yes | The pixel window (offset + size). On a virtual tile it is the window to read; on a materialized tile it is provenance of the window already extracted. The Python rst_retile, rst_tooverlappingtiles and rst_maketiles record the window relative to their immediate input tile, so windows from different parents can repeat; one output that covers its whole input keeps the input's own window instead. The JVM versions leave it null. |
clip_polygon | binary | Yes | Optional clip geometry (WKB). Instruction on a virtual tile; applied-provenance on a materialized tile. |
clip_crs | string | Yes | CRS for clip_polygon (e.g. "EPSG:4326"). |
crs | string | Yes | Working/target CRS. |
metadata | map<string,string> | Yes | Key-value map containing driver name, file extension, size, and other metadata. The Python rst_separatebands also sets band (1-based) on each output. A tile read from a Zarr store carries the keys listed in Zarr tile metadata. |
On a materialized tile, window / clip_polygon / clip_crs / crs are provenance — a record of what was already applied to produce the bytes. On a virtual tile they are instructions — pending operations applied when the tile is read. See Virtual Tiles.
Working with Tiles
Accessing Tile Fields
Use dot notation to access tile struct fields:
Python:
from pyspark.sql import functions as f
from databricks.labs.gbx.rasterx import functions as rx
df = spark.read.format("raster_gbx").option("virtualTiles", "false").load(SAMPLE_NYC_RASTERS)
# Access individual fields
df.select(
f.col("tile.cellid"),
f.col("tile.raster"),
f.col("tile.metadata"),
f.col("tile.metadata.driver")
)
+------+--------+------------------+-------+
|cellid|raster |metadata |driver |
+------+--------+------------------+-------+
|-1 |[BINARY]|{driver=GTiff,...}|GTiff |
+------+--------+------------------+-------+
SQL:
CREATE OR REPLACE TEMP VIEW nyc_raster USING raster_gbx OPTIONS (path '{SAMPLE_NYC_RASTER}', virtualTiles 'false');
SELECT
tile.cellid,
tile.raster,
tile.metadata,
tile.metadata['driver'] as driver
FROM nyc_raster;
+------+--------+------------------+-------+
|cellid|raster |metadata |driver |
+------+--------+------------------+-------+
|-1 |[BINARY]|{driver=GTiff,...}|GTiff |
+------+--------+------------------+-------+
Filtering by Metadata
Filter tiles based on driver or other metadata:
df = spark.read.format("raster_gbx").load(SAMPLE_NYC_RASTERS)
# Filter by driver
gtiff_only = df.filter(f.col("tile.metadata.driver") == "GTiff")
# Filter by file extension
tif_files = df.filter(f.col("tile.metadata.extension") == ".tif")
Filtered DataFrame (e.g. driver = GTiff or extension = .tif).
Access individual metadata keys from a tile:
df = spark.read.format("raster_gbx").load(SAMPLE_NYC_RASTERS)
metadata_df = df.select(
f.col("tile.metadata").alias("metadata"),
f.col("tile.metadata.driver").alias("driver"),
f.col("tile.metadata.extension").alias("extension"),
f.col("tile.metadata.size").alias("size")
)
+------------------+-------+----------+------+
|metadata |driver |extension |size |
+------------------+-------+----------+------+
|{driver=GTiff,...}|GTiff |.tif |... |
+------------------+-------+----------+------+
Using Tiles in Custom UDFs
Access tile components for custom processing. The reader returns virtual tiles by default, and their tile.raster is NULL. This example sets virtualTiles to false, so each tile carries its bytes:
from pyspark.sql.functions import udf
from pyspark.sql.types import IntegerType
@udf(IntegerType())
def get_raster_size(raster_binary):
"""Size in bytes of the tile's raster data (0 for a virtual tile, which holds none)"""
return len(raster_binary) if raster_binary else 0
# virtualTiles=false: the tiles carry their bytes in tile.raster
df = spark.read.format("raster_gbx").option("virtualTiles", "false").load(SAMPLE_NYC_RASTERS)
df_with_size = df.withColumn(
"data_size",
get_raster_size(f.col("tile.raster"))
)
+------+---------+
|source|data_size|
+------+---------+
|... |12345678 |
+------+---------+
Materialized vs Virtual: path and raster
A virtual tile has tile.raster = null and tile.path set to the source file path. A materialized tile is the opposite. Its tile.raster carries the encoded bytes, and tile.path is usually null. When the path is set, it only records where the bytes came from. Classify a tile by tile.raster, never by tile.path alone:
# rst_fromfile returns a VIRTUAL tile by default:
# raster=null, path set to the source path.
virtual_df = spark.range(1).select(
rx.rst_fromfile(f.lit(SAMPLE_NYC_RASTER), f.lit("GTiff")).alias("tile")
).select(
f.col("tile.path").alias("path"), # non-null: source file path
f.col("tile.raster").isNull().alias("is_virtual"), # True: bytes-free
)
# Returns: path=/Volumes/.../nyc_sentinel2_red.tif, is_virtual=true
# Materialized tile: binaryFile reader + rst_fromcontent embeds bytes.
# tile.raster holds the encoded GeoTIFF; tile.path is null.
materialized_df = (
spark.read.format("binaryFile").load(SAMPLE_NYC_RASTER)
.select(
rx.rst_fromcontent(f.col("content"), f.lit("GTiff")).alias("tile")
)
.select(
f.col("tile.path").isNull().alias("path_null"), # True: no source path
f.col("tile.raster").isNull().alias("is_virtual"), # False: bytes present
)
)
Virtual tile — raster null, path set:
+-----------------------------------------------------+----------+
|path |is_virtual|
+-----------------------------------------------------+----------+
|/Volumes/main/.../nyc_sentinel2_red.tif |true |
+-----------------------------------------------------+----------+
Materialized tile — raster bytes present, path null:
+---------+----------+
|path_null|is_virtual|
+---------+----------+
|true |false |
+---------+----------+
Tile Storage Mode
tile.path_mode records the storage model used by a virtual tile's backing data. It is null for both materialized tiles and plain FUSE-path virtual tiles. Use tile.raster is null to distinguish those two cases. The field carries "external" for FILE EXTERNAL tiles and "managed" for FILE MANAGED tiles (governed lifecycle via Delta):
# Virtual tile (plain FUSE path) — raster null, path set, path_mode null
virtual_df = spark.range(1).select(
rx.rst_fromfile(f.lit(SAMPLE_NYC_RASTER), f.lit("GTiff")).alias("tile")
).select(
f.col("tile.path_mode").alias("path_mode"), # null (plain FUSE virtual)
f.col("tile.raster").isNull().alias("is_virtual"), # True
f.col("tile.path").isNull().alias("path_null"), # False
)
# Returns: path_mode=null, is_virtual=true, path_null=false
# Materialized tile — raster bytes present, path null, path_mode null
materialized_df = (
spark.read.format("binaryFile").load(SAMPLE_NYC_RASTER)
.select(
rx.rst_fromcontent(f.col("content"), f.lit("GTiff")).alias("tile")
)
.select(
f.col("tile.path_mode").alias("path_mode"), # null (materialized)
f.col("tile.raster").isNull().alias("is_virtual"), # False
f.col("tile.path").isNull().alias("path_null"), # True
)
)
Virtual tile (plain FUSE) — path_mode null, raster null:
+---------+----------+---------+
|path_mode|is_virtual|path_null|
+---------+----------+---------+
|null |true |false |
+---------+----------+---------+
Materialized tile — path_mode null, raster bytes present:
+---------+----------+---------+
|path_mode|is_virtual|path_null|
+---------+----------+---------+
|null |false |true |
+---------+----------+---------+
(path_mode is "external" for FILE EXTERNAL tiles, "managed" for FILE MANAGED tiles)
When tile.raster contains binary data, use it with rasterio or GDAL. Read with virtualTiles set to false to get the bytes, because a virtual tile has none:
from rasterio.io import MemoryFile
from pyspark.sql.functions import udf
from pyspark.sql.types import DoubleType
@udf(DoubleType())
def compute_mean_from_tile(raster_binary):
"""Compute mean from binary raster data"""
import numpy as np
if raster_binary is None:
return None
# Convert to bytes if needed
tile_data = bytes(raster_binary)
# Open with rasterio
with MemoryFile(tile_data) as memfile:
with memfile.open() as src:
data = src.read(1)
return float(np.mean(data))
# The reader gives virtual tiles (raster is NULL) unless virtualTiles is "false"
df = spark.read.format("raster_gbx").option("virtualTiles", "false").load(SAMPLE_NYC_RASTER)
stats_df = df.withColumn(
"mean_value",
compute_mean_from_tile(f.col("tile.raster"))
)
+------+----------+
|source|mean_value|
+------+----------+
|... |0.42 |
+------+----------+
Comparing rst_fromfile vs rst_fromcontent
In Python, rst_fromfile takes a path and returns a virtual tile (bytes-free by default; pass materialize=True to force bytes); the SQL function gbx_rst_fromfile returns a materialized tile. rst_fromcontent always returns a materialized tile — it takes bytes you already have (e.g. from spark.read.format("binaryFile")) and embeds them directly.
To enumerate paths from a Volume directory and decode each one in a single pipeline, compose
gbx_file_read with rst_fromfile — see GBX Common Functions.
# rst_fromfile: VIRTUAL tile (raster=null, path set)
fromfile_tile = spark.range(1).select(
rx.rst_fromfile(f.lit(SAMPLE_NYC_RASTER), f.lit("GTiff")).alias("tile")
)
fromfile_tile.select(
f.col("tile.raster").isNull().alias("raster_null"), # True: virtual tile
f.col("tile.path").isNull().alias("path_null"), # False: path set
).show()
# +-----------+---------+
# |raster_null|path_null|
# +-----------+---------+
# |true |false |
# +-----------+---------+
# rst_fromcontent takes bytes you already have in a column (e.g. from binaryFile)
fromcontent_tile = spark.read.format("binaryFile").load(SAMPLE_NYC_RASTER).select(
rx.rst_fromcontent(f.col("content"), f.lit("GTiff")).alias("tile")
)
fromcontent_tile.select(
f.col("tile.raster").isNull().alias("raster_null"), # False: bytes present
f.col("tile.path").isNull().alias("path_null"), # True: no source path
).show()
rst_fromfile (virtual by default) — VIRTUAL tile:
+-----------+---------+
|raster_null|path_null|
+-----------+---------+
|true |false |
+-----------+---------+
rst_fromcontent — MATERIALIZED tile (bytes embedded):
+-----------+---------+
|raster_null|path_null|
+-----------+---------+
|false |true |
+-----------+---------+
Zarr tile metadata
A tile cut from a Zarr store with gbx_zarr_read(..., output="tiles")
is virtual, and its metadata holds everything a task needs to read its window. window is a window of one
2-D plane of a variable (its latitude and longitude); sliceDims says where the tile sits along the other
dimensions. A table of these tiles can be saved and opened later by tasks that have no session and no manifest
table: see Zarr tiles.
| Key | Holds |
|---|---|
format, driver | zarr and Zarr on a virtual tile. Both are GTiff once the tile is materialized, because its bytes are then a GeoTIFF |
sourcePath | The store the tile was cut from (for a registered store, the store's own directory) |
zarr_array | The variable, that is the Zarr array, the tile was cut from |
sliceDims | The tile's position along each dimension other than latitude, longitude and the band_dim, by position and sorted by name: level=3,time=12. Absent when there is no such dimension. The NetCDF reader writes the same form |
sliceCoord_<dim> | The label at that position, for each dimension that has coordinates; a time is ISO text such as 2023-01-01T05:00:00.000000000 |
zarr_meta | JSON: the array's metadata, cut to what decoding needs (data type, chunk and shard layout, codecs, fill value, CF attributes) |
zarr_refs | JSON: for each band of the tile, the storage objects its window needs, each with a file, an offset and a length, taken from the manifest at the pinned version. Empty for a plain store, which has no manifest |
zarr_root | The directory the files are read from: the store itself for a plain store or a read-only registration, the store's root for a managed one, the overlay root for a writable registration |
zarr_base_root | A registered store only: the store's own directory, where its original objects are (the same as zarr_root for a read-only registration) |
zarr_table, zarr_version | The manifest table and the version the read was pinned to. Both are empty for a plain store |
zarr_gt, zarr_crs | The geotransform of the whole plane (six comma-separated numbers, north-up) and its CRS |
width, height | The size of the whole plane in cells; the tile's window is a part of it |
count | The number of bands in the tile |
bandDim, bandDescriptions, bandCoords, zarr_band_index | band_dim stacks only: the stacked dimension, a <dim>=<label> description of each band, the label of each band (when the dimension has coordinates), and the positions of the bands in the array |
The crs field of a virtual Zarr tile is NULL: it is the target of a pending reprojection, and the tile's
own CRS is zarr_crs. A materialized tile (read with virtual_tiles=False) keeps every zarr_* key, which is
how a tile is written back to the array it was cut from.
from databricks.labs.gbx.zarr import gbx_zarr_read
def first_tile(**options):
tiles = gbx_zarr_read(
spark,
cube,
variables=["t2m"],
isel={"time": 0},
output="tiles",
**options,
)
by_position = tiles.orderBy("tile.window.row_off", "tile.window.col_off")
return by_position.first()["tile"]
# A virtual tile holds no pixels, only where to read them.
tile = first_tile()
print("virtual:", tile.raster is None, "| path_mode:", tile.path_mode)
print("window:", tuple(tile.window))
long_or_local = {"sourcePath", "zarr_meta", "zarr_refs", "zarr_root"}
for key in sorted(set(tile.metadata) - long_or_local):
print(key, "=", repr(tile.metadata[key]))
print("not shown:", ", ".join(sorted(long_or_local)))
# Read now, the tile holds GeoTIFF bytes and keeps where it came from.
held = first_tile(virtual_tiles=False)
meta = held.metadata
print("materialized:", held.raster is not None)
print("driver:", meta["driver"], "| zarr_array:", meta["zarr_array"])
virtual: True | path_mode: None
window: (0, 0, 180, 91)
count = '1'
driver = 'Zarr'
format = 'zarr'
height = '181'
sliceCoord_time = '2023-01-01T00:00:00.000000000'
sliceDims = 'time=0'
width = '360'
zarr_array = 't2m'
zarr_crs = 'EPSG:4326'
zarr_gt = '-0.5,1.0,0.0,90.5,0.0,-1.0'
zarr_table = ''
zarr_version = ''
not shown: sourcePath, zarr_meta, zarr_refs, zarr_root
materialized: True
driver: GTiff | zarr_array: t2m
Tessellated vs Non-Tessellated Tiles
Non-Tessellated Tiles
Created by constructors (rst_fromfile, rst_fromcontent) or readers:
df = spark.read.format("raster_gbx").option("virtualTiles", "false").load(SAMPLE_NYC_RASTER)
df.select(
f.col("tile.cellid"), # -1 (not tessellated)
f.col("tile.raster"), # binary data
f.col("tile.metadata") # {driver: "GTiff", ...}
).show()
+----+--------+------------------+
|cellid|raster |metadata |
+----+--------+------------------+
|-1 |[BINARY]|{driver=GTiff,...}|
+----+--------+------------------+
Characteristics:
cellidis-1- Represents entire raster or a tile from tiling operations
- Suitable for processing complete rasters
Tessellated Tiles
Created by rst_h3_tessellate:
from databricks.labs.gbx.rasterx import functions as rx
raw = spark.read.format("raster_gbx").load(SAMPLE_NYC_RASTER)
# One row per H3 cell, with the columns of a tile; pack them back into one tile struct
cells = rx.rst_h3_tessellate(raw.select("tile"), "tile", 7)
df = cells.select(f.struct(*raw.select("tile.*").columns).alias("tile"))
df.select(
f.col("tile.cellid"), # H3 cell ID (e.g., 604189641255419903)
f.col("tile.raster"), # binary data (clipped to cell)
f.col("tile.metadata") # {driver: "GTiff", gridSystem: "h3", width: "...", ...}
).show()
+-------------------+--------+------------------+
|cellid |raster |metadata |
+-------------------+--------+------------------+
|604189641255419903 |[BINARY]|{RASTERX_CELL_ID..|
+-------------------+--------+------------------+
Characteristics:
cellidcontains the grid cell id (H3, quadbin, or BNG depending on the tessellate function used)tile.metadata["gridSystem"]names the DGGS:"h3","quadbin", or"bng"- Raster is clipped to the cell's bounds
- Enables equi-joins with any DGGS-indexed table via
cellid+gridSystemfor unambiguous matching
Next Steps
- Virtual Tiles - The virtual↔materialized model over this struct
- Raster Functions - Functions that work with tiles
- Custom UDFs - Build custom tile processing
- Library Integration - Use tiles with rasterio/xarray