Rasterio Distributed
RasterX at the Python level is, in large part, rasterio plus a best-of-breed Python raster stack: rio-tiler, scipy, scikit-image, shapely, pyproj, h3 and quadbin. They run as Arrow-vectorized Spark UDFs and UDTFs across the cluster. It is not a single-node rasterio.open loop, and it is not a reimplementation. The same rasterio functions you would call locally run inside a vectorized Spark UDF, once per tile, on every executor in parallel. No JAR and no native GDAL install separate from rasterio's bundled GDAL.
If you already know rasterio, you already understand what pyrx does. The coverage matrix below maps the surface, and the side-by-sides show each operation in rasterio next to its distributed pyrx form.
Register
Register the *_gbx data sources and SQL functions once per session before using any rst_* function or raster_gbx reader:
# Register the GeoBrix lightweight (pyrx) functions once per session
from databricks.labs.gbx import register
register(spark) # gbx_* SQL functions and the raster_gbx family of data sources
Capability coverage
The table below maps each RasterX capability to the rasterx function(s) whose Python level uses it, and the backing Python library. Every rst_* function runs at the Python level, on every compute.
See the RasterX Function Reference for runnable per-function code examples.
| Capability | pyrx function(s) | Backing library |
|---|---|---|
| I/O & metadata | rst_fromcontent, rst_fromfile, rst_width, rst_height, rst_srid, rst_numbands, rst_metadata, rst_subdatasets | rasterio |
| Raster summary | rst_summary | GDAL raster info in the worker |
| Warp / reproject | rst_transform, rst_to_webmercator | GDAL raster reproject in the worker |
| Clip / mask | rst_clip | rasterio + shapely |
| Resample | rst_resample, rst_resample_to_size, rst_resample_to_res | GDAL raster reproject in the worker |
| Merge | rst_merge, rst_merge_agg | rasterio + NumPy |
| COG conversion | rst_cog_convert | rasterio (GDAL's COG driver) |
| Spectral indices | rst_ndvi, rst_evi, rst_savi, rst_ndwi, rst_nbr, rst_index, rst_threshold | GDAL raster calc |
| Band math | rst_derivedband, rst_derivedband_agg, rst_combineavg, rst_combineavg_agg | NumPy |
| Terrain (Horn 3×3) | rst_slope, rst_aspect, rst_hillshade, rst_tri, rst_tpi, rst_roughness | GDAL raster algorithms in the worker |
| Fill NoData | rst_fillnodata | GDAL raster fill-nodata in the worker |
| Color relief | rst_color_relief | GDAL raster color-map in the worker |
| Rasterize | rst_rasterize, rst_h3_rasterize_agg | rasterio + shapely |
| Polygonize | rst_polygonize | GDAL raster polygonize in the worker |
| Focal / convolution | rst_filter, rst_convolve | scipy.ndimage |
| Proximity | rst_proximity | scipy |
| Contour | rst_contour | GDAL raster contour in the worker |
| Viewshed | rst_viewshed | GDAL raster viewshed in the worker |
| XYZ tiles | rst_tilexyz, rst_xyzpyramid | rio-tiler + morecantile |
| Tiling / retile | rst_maketiles, rst_retile | rasterio + NumPy |
| Grid aggregation (H3) | rst_h3_tessellate, rst_h3_rastertogrid* | h3 |
| Grid aggregation (quadbin) | rst_quadbin_tessellate, rst_quadbin_rastertogrid*, rst_quadbin_rasterize_agg | quadbin |
| Grid aggregation (BNG) | rst_bng_tessellate, rst_bng_rastertogrid*, rst_bng_rasterize_agg | pure-Python BNG codec + rasterio (27700 warp) |
Side-by-sides
Reproject (warp)
rasterio computes the target grid for a single file:
# Single-node rasterio: reproject one file to EPSG:3857
import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling
with rasterio.open("in.tif") as src:
t, w, h = calculate_default_transform(
src.crs, "EPSG:3857", src.width, src.height, *src.bounds)
# ...write a reprojected file, one machine, one file at a time
pyrx runs GDAL's raster reproject on each tile across the cluster:
# GeoBrix: reproject a whole DataFrame of tiles, distributed
from databricks.labs.gbx.rasterx import functions as rx
df2 = df.withColumn("tile", rx.rst_transform("tile", 3857))
# rst_transform runs GDAL's raster reproject on each tile in an Arrow UDF across the cluster
The test verifies two things. The pyrx-reprojected tile reports the correct target CRS (EPSG:3857). Its geographic bounds agree, within 1%, with the bounds calculate_default_transform computes on the rasterio side. Pixel-level equality between the two outputs was not asserted. The rasterio warp and the pyrx distributed warp agree on the reprojected grid geometry, not on every pixel value.
Clip
rasterio clips a single file to a geometry:
# Single-node rasterio: clip one raster to a geometry
import rasterio
from rasterio.mask import mask as rio_mask
with rasterio.open("in.tif") as src:
out, out_transform = rio_mask(src, [geom], crop=True)
pyrx applies the same clip operation to every tile in a DataFrame:
# GeoBrix: clip every tile to a geometry, distributed
from databricks.labs.gbx.rasterx import functions as rx
from pyspark.sql import functions as f
# clip_geom column holds WKB/WKT geometry; third arg controls border pixel inclusion
df2 = df.withColumn("tile", rx.rst_clip("tile", "clip_geom", f.lit(False)))
Both operations mask the raster to the provided geometry. The third argument to rst_clip controls border pixel inclusion (True = include any pixel that touches the geometry boundary; False = include only pixels fully inside). This corresponds to rasterio.mask's all_touched parameter. Both are shown here as the same distributed clip operation, not as pixel-level equivalents.
NDVI (band math)
rasterio + NumPy computes NDVI for a single file:
# Single-node rasterio + NumPy: NDVI for one raster (band1=red, band2=nir)
import rasterio, numpy as np
with rasterio.open("in.tif") as src:
red = src.read(1).astype("float32")
nir = src.read(2).astype("float32")
ndvi = (nir - red) / (nir + red)
pyrx computes the same NDVI across a DataFrame of tiles:
# GeoBrix: NDVI across a DataFrame of tiles, distributed
from databricks.labs.gbx.rasterx import functions as rx
# rst_ndvi(tile, red_idx, nir_idx) — band indices are 1-based
df2 = df.withColumn("tile", rx.rst_ndvi("tile", 1, 2))
The test asserts np.allclose between the rasterio-computed NDVI array and the pyrx-computed result. The rasterio side is NumPy arithmetic on band arrays. The pyrx side runs GDAL's raster calc. The two agree to within floating-point tolerance.
Gaps and divergences
Distributed in pyrx today
Everything in the matrix above. Every rst_* function runs at the Python level. A dedicated cluster with the JAR adds the JVM level where it is faster.
JVM-level differences
None. Every function and mode runs at the Python level, the conforming TIN mode included.
See Surfaces & Levels for how GeoBrix picks an implementation.
See Benchmarking and Performance for per-function timing data across both implementations.
With the plain GeoBrix wheel, rasterio brings the GDAL bundled in PyPI's rasterio wheels, which has a narrower driver set than GeoBrix's own GDAL build. The GeoBrix env wheels (environment 5 and 6) give rasterio that build instead, the one the JVM loads from the same wheel.
How it is distributed
The Python level distributes rasterio and NumPy compute over Spark via three mechanisms, none of which require the Spark JVM internals:
- Arrow scalar UDFs (per-tile functions): each scalar
rst_*function invoked via the Python Column API is a@pandas_udf(tile_scalar_udf/tile_scalar_udf2inpyrx/_udf.py). It receives a batch of tiles' raster bytes as a Pandas Series, calls rasterio/NumPy once per tile within the batch, and returns transformed bytes. The Arrow batch crosses the JVM↔Python boundary once per batch, not once per row. The same functions are also registered as plain@f.udffor SQL use (soDESCRIBE FUNCTIONand SQL calls work). The Python Column API always routes through thepandas_udfpath. - Grouped-aggregate pandas UDFs (merges and combineavg):
rst_merge_agg,rst_combineavg_agg, and similar grouped aggregators use@pandas_udf(BinaryType())— Spark 4 auto-detects the grouped-aggregate eval type. Each receives all tiles in a group as a Pandas Series and merges them in one Python call. - Streaming UDTFs (fan-out):
rst_h3_tessellate,rst_quadbin_tessellate,rst_bng_tessellate,rst_maketiles,rst_retile,rst_xyzpyramiduse@udtfto yield one output row per chip or tile without materializing the full output in memory first.
No _jvm access, no .rdd, no Spark driver-side collect before distributing. Data-source readers and writers (raster_gbx, gtiff_gbx, etc.) use the DataSource V2 API. See Performance for partitioning guidance and per-tier timing benchmarks.