Skip to main content

Readers Overview

GeoBrix provides Spark readers for geospatial file formats.

The lightweight tier ships native Python DataSource V2 readers — no JAR, no init script.

Distributed readers, virtual tiles by default

These are Spark DataSource V2 readers (not single-node rasterio/pyogrio wrappers): work is partitioned and read in parallel across the cluster — vector readers slice features by chunkSize, raster readers split large files by sizeInMB — returning a distributed DataFrame with no driver-side collect. Raster readers load virtual tiles by default — bytes-free (path, window) refs that read pixels lazily, so a multi-gigabyte raster fans into tiles without OOM (.option("virtualTiles", "false") for materialized reads). See Virtual Tiles.

Register first

Unlike the heavyweight readers (auto-discovered from the JAR), the lightweight Python DataSources are not auto-registered — call register(spark) once per session before using any *_gbx format:

from databricks.labs.gbx.ds.register import register
register(spark)

To register only the formats this session uses, pass only= (by format name, with or without the _gbx suffix):

register(spark, only=["raster_gbx", "gtiff_gbx"])

An unrecognized format raises ValueError.

On Serverless, read from a FILE-column table

The Delta-scan FILE-column-table read path is the recommended read path on Serverless: a tilesTable (raster) or vector_file_read(table) (vector) scans the Delta table and resolves FILE references without per-tile opens — measured at ~1.8–2 s for 1,000 raster tiles or 100k vector features on both Serverless and classic clusters.

The raster_gbx directory DataSource path incurs a per-tile open and is ~16–17× slower on Serverless (~30 s vs. ~2 s per 1,000 tiles). When running on Serverless, write your rasters or vectors to a FILE-column table first, then read from that table rather than the directory directly.

All tile reads are size-gated by a connect-aware cap (64 MiB on Serverless / Spark Connect, 256 MiB on classic; override with GBX_STREAM_MAX_BYTES). Files under the cap stream in full; files over the cap open lazily so reads never load an unbounded tile into executor memory. See Serverless & Memory for the full guide including write-path safety and caveats.

See the full capability tiers & read-options matrix.

Available Readers

ReaderFormat NameDescription
Raster Readerraster_gbxPure-Python catch-all raster reader (no JAR; DataSource V2)
GeoTIFF Readergtiff_gbxPure-Python GeoTIFF reader (preset driver="GTiff")
COG Readercog_gbxPure-Python cloud-optimized GeoTIFF reader — windowed/overview-aware reads
NetCDF Readernetcdf_gbxPure-Python CF NetCDF reader — CF grids (raster) or CF-DSG points (vector)
File Readerfile_gbxPure-Python file lister — enumerates matching paths as rows (read-only)
PMTiles Readerpmtiles_gbxPure-Python PMTiles reader — mosaic pyramid from rasters (source="raster") or tiles from an archive (source="archive")
Vector Readervector_gbxPure-Python catch-all vector reader (pyogrio; same OGR schema)
Shapefile Readershapefile_gbxPure-Python Shapefile reader (preset OGR driver)
GeoJSON Readergeojson_gbxPure-Python GeoJSON reader (preset OGR driver)
GeoJSONL Readergeojsonl_gbxPure-Python newline-delimited GeoJSONL reader — reads GeoJSONSeq shard directories
GeoPackage Readergpkg_gbxPure-Python GeoPackage reader (preset OGR driver)
GeoDatabase Readerfile_gdb_gbxPure-Python File Geodatabase reader (preset OGR driver)

See the Raster Reader page for full raster usage/options, and the vector reader pages for the OGR (geom_0, geom_0_srid, geom_0_srid_proj, …attributes) schema.

.limit() and filters are not pushed into the reader — use the function layer for a bounded scan

The lightweight DataSource readers enumerate the entire source at planning time, regardless of a downstream .limit(N), WHERE, or column projection. Spark 4.0.0's Python DataSource API exposes no limit/filter pushdown hook, so spark.read.format("raster_gbx").load(dir).limit(10) still lists — and plans a partition for — every file under dir, then discards all but 10 rows afterward. The listing is a fast, stat-free directory walk, so this is cheap for typical directories; on a very large directory, every file is still planned.

When you want the limit (or a filter) honored during planning, use the function layer instead:

  • gbx_file_read(spark, dir).limit(N) — on a FILE-capable runtime this reads through the native read_files table function, which pushes .limit() and predicate/column filters, so only the needed files are enumerated.
  • rst_fromfile("path") — a per-row function returning virtual tiles, so gbx_file_read(dir).limit(N).select(..., rst_fromfile("path")) decodes only the N selected rows and reads no pixels until a downstream op forces it.

See GBX Common Functions.

FILE-column-table reads

Both the raster and vector light-tier readers can read directly from a FILE-column Delta table (a table whose rows carry FILE references to geospatial files) in addition to Volume paths. Both auto-order by the resolved source path by default. The ordering effect differs by format:

  • Raster (tilesTable) — a single GeoTIFF can produce many tile rows; auto-ordering groups those tiles together so each executor opens the source file once and reads all its windows, amortizing the open cost. See Raster Reader → tilesTable auto-order.
  • Vector (vector_file_read) — one vector file maps to exactly one table row (one FILE ref). Every source opens exactly once regardless of row order, so auto-ordering is a deterministic, cross-format-consistent default, not a throughput lever. See Vector Reader → Reading from a FILE-column table.

Both support an opt-out: skipOrdering="true" (raster DataSource option) and skip_ordering=True (vector_file_read kwarg). Use either when the table is already physically ordered (written with layout="order" or layout="cluster") to avoid the redundant sort step.

Benchmarks

Each *_gbx lightweight reader corresponds to a *_ogr (or gdal/gtiff_gdal) heavyweight counterpart. The generic vector_gbx catch-all reader pairs with the heavyweight ogr generic OGR reader; named readers such as shapefile_gbx pair with shapefile_ogr, and so on.

Both tiers are benchmarked on the same cluster, same source file, same row counts. Parity (row-count equality between the two tiers) is a hard gate — a mismatch fails the run immediately. Per-format timing results are published on the Benchmarking page; the vector-reader comparison table is in the Results — vector readers section (timing figures will be filled in once a controlled cluster run is completed).

For the full methodology, raster-function results, and the PMTiles writer comparison, see the Benchmarking page.