Writers Overview
GeoBrix provides Spark writers for geospatial file formats.
Available Writers
Every writer is a pure-Python DataSource V2 (the *_gbx formats). It needs no JAR and
runs on every compute, Serverless included. Detailed options and the vector column
contract follow below.
| Format | Writer |
|---|---|
| Raster (generic) | raster_gbx |
| GeoTIFF | gtiff_gbx |
| COG | cog_gbx |
| Zarr | gbx_zarr_write (a function, not a DataSource) |
| PMTiles | pmtiles_gbx |
| NetCDF | netcdf_gbx |
| LiDAR (LAS/LAZ) | lidar_gbx |
| Vector (generic) | vector_gbx |
| Shapefile | shapefile_gbx |
| GeoJSON | geojson_gbx |
| GeoJSONL | geojsonl_gbx |
| GeoPackage | gpkg_gbx |
| File Geodatabase | file_gdb_gbx |
Named Vector Formats
The vector readers and writers share a small column contract for geometry and its coordinate reference system (CRS). A vector frame carries one geometry column plus up to two CRS-companion columns:
<geom> binary (WKB) or string (WKT) # the geometry
<geom>_srid string — REQUIRED # CRS authority code, e.g. "4326" ("0" if unknown)
<geom>_srid_proj string — optional # PROJ4 string; CRS fallback when srid is "0"
The geometry encoding is read from the column's type — binary is WKB,
string is WKT. The CRS is EPSG:<srid> when <geom>_srid is set, falling
back to the PROJ4 string in <geom>_srid_proj when the srid is "0". Every
other column is written as an attribute; <geom>_srid / <geom>_srid_proj are
CRS metadata and are not written as fields.
What each format expects when written differs — how (and whether) the geometry is named, field-name and type limits, and how the CRS is stored:
| Format | Geometry on output | Field-name / type limits | CRS |
|---|---|---|---|
| Shapefile | The shape record — no named geometry field; one geometry type per file. | Attribute names truncated to 10 characters (.dbf); limited types. Output is a sidecar set (.shp/.shx/.dbf/.prj/.cpg). | .prj sidecar. |
| GeoJSON / GeoJSONL | Structural GeoJSON geometry member — no named field. | Properties keep full names; JSON types (string/number/bool/null). | WGS84 (EPSG:4326) per RFC 7946; a crs member otherwise. |
| GeoPackage | A named geometry column, default geom. | Full field names; rich types (int64, real, text, blob, datetime). | Stored per geometry column (gpkg_spatial_ref_sys). |
| FileGDB | A named geometry field, default SHAPE. | Esri limits (≤ 64 chars; reserved names like OBJECTID disallowed). | Per feature class. |
What .save(path) produces
The writer name chooses the format (driver), not the path extension.
Some formats are a single file and others a directory, so name path accordingly:
| Writer | .save(path) writes | Recommended path |
|---|---|---|
gpkg_gbx | a single file | …/merged.gpkg |
geojson_gbx | a single file | …/merged.geojson |
shapefile_gbx | a directory holding the .shp/.shx/.dbf/.prj/.cpg bundle; or a single .shp.zip when zip=true | …/roads or …/roads.shp.zip |
geojsonl_gbx | a directory of part-*.geojsonl shards | …/edges |
file_gdb_gbx | a directory …/name.gdb | …/roads.gdb |
The extension is cosmetic for writing (the driver decides the format), but include it on single-file outputs so the result is recognizable and portable.
Output naming for single-file writers
The single-file vector writers (gpkg_gbx, geojson_gbx, shapefile_gbx with zip=true,
and file_gdb_gbx) apply an adaptive naming contract that resolves the final output path
from the .save(path) argument and an optional fileName option. Extension auto-completion
handles partial names so you never produce a misnamed file.
Resolution rules (evaluated in order):
| Case | Condition | Resolved output |
|---|---|---|
| 1 | .option("fileName", name) given | path is treated as the parent directory (created if missing); output = path/complete(name) |
| 2 | No fileName; path is an existing directory | output = path/complete(basename(path)) — named after the directory, written under it |
| 3 | No fileName; path does not yet exist (stem/file path) | output = complete(path); parent directory created if missing |
Extension auto-completion (complete(name)) appends only the missing parts of the
canonical extension for the format — so roads → roads.shp.zip, roads.shp →
roads.shp.zip, roads.shp.zip → unchanged. If name ends with a different recognized
geo extension (for example, .gpkg passed to the Shapefile writer), the writer raises a clear
error. It never silently produces a doubly-suffixed name.
Examples:
# Case 1 — explicit fileName, path is the parent dir (created as needed)
df.write.format("gpkg_gbx").option("fileName", "districts").mode("overwrite") \
.save("/Volumes/main/geo/exports")
# -> /Volumes/main/geo/exports/districts.gpkg
# Case 2 — path is an existing directory; output named after the dir, under it
df.write.format("geojson_gbx").mode("overwrite") \
.save("/Volumes/main/geo/exports")
# -> /Volumes/main/geo/exports/exports.geojson (if exports/ already exists)
# Case 3 — stem path; extension completed automatically
df.write.format("shapefile_gbx").option("zip", "true").mode("overwrite") \
.save("/Volumes/main/geo/exports/roads")
# -> /Volumes/main/geo/exports/roads.shp.zip
The nameCol option on the sharded and raster writers (geojsonl_gbx, raster_gbx,
gtiff_gbx) is a separate, per-row concept and is not affected by this contract.
Choosing a writer for large datasets
The single-file writers (geojson_gbx, shapefile_gbx, gpkg_gbx, file_gdb_gbx) assemble
the output on the driver. They stream the partitions through one pass
(the whole dataset is never held at once), so they scale much further than a naive
single-node merge. They are still single-node writes,
so:
shapefile_gbx— streamed, but the format hard-caps each.shp/.dbfat 2 GB (the.dbfis one fixed-width record per row), so very large attribute tables eventually hit that ceiling.geojson_gbx/gpkg_gbx— streamed, single file, no hard size cap; bounded by the single-node write throughput.file_gdb_gbx— streamed, but GDAL's FileGDB writer keeps per-feature index state in memory until the file is closed. Driver memory therefore grows with the feature count (about 120 bytes per feature; a 14-million-polygon write peaked at 1.9 GB). See Benchmarking.
For the largest datasets, prefer the writers that spread work across partitions:
geojsonl_gbx— one shard per partition (no driver assembly at all); throughput scales with partitions. The most scalable option.gpkg_gbx— a single file with no 2 GB cap, a good single-file choice when one file is required.
The single-file writers assemble the output in Spark's Python worker
processes. A very large result (for example, a Shapefile whose .dbf runs to
~1 GB+) can therefore exceed the worker memory on Serverless and fail mid-write.
The failure appears as a CancelledKeyException (the driver is lost) or a "Python worker exited
unexpectedly" crash. If you hit that:
- Run on a classic cluster with a larger node — the proven path for the largest single-file writes.
- Or avoid single-node assembly entirely: use
geojsonl_gbx(shards per partition) orgpkg_gbx, which scale on Serverless without this ceiling.
Note: high-memory Serverless ("High: 32 GB") raises the notebook REPL memory but not the Spark Python-worker memory the writer assembles in. It therefore does not extend this ceiling, so prefer a classic cluster or the sharded writers. The write itself is correct at scale (it completes on a classic cluster); this is a memory ceiling, not a writer limit.
GeoBrix ships native Python DataSource V2 writers — no JAR.
These are Spark DataSource V2 writers, not single-node pyogrio/rasterio wrappers. Each
partition is written concurrently by its executor, then the driver merges the parts into
the final output (a two-phase write). The PMTiles writer goes further with distributed
spatial sharding. It partitions tiles into bounded per-shard archives written in parallel
and then catalogs them. This scales horizontally instead of building one memory-bound
archive on a single node. Merges are sequential and rename-free, so they are safe on
FUSE-mounted Unity Catalog Volumes / DBFS.
The two-phase staging is isolated per write. Each write stages its parts under a unique, hidden scratch namespace. Concurrent jobs, or multiple users, writing to the same output location never see or overwrite one another's in-progress data. Scratch left behind by an interrupted job is reclaimed automatically on a later write to the same location.
The Python DataSources are not auto-registered — call register(spark) once per
session before using any *_gbx format:
from databricks.labs.gbx 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", "geojson_gbx"])
An unrecognized format raises ValueError.
On Serverless, prefer writing raster or vector output to a FILE-column Delta table (use
file_mode="external" or file_mode="managed" on the writer). Once written, reads via
read_tiles_table (raster) or vector_file_read(table) (vector) use the Delta-scan path. That path resolves the
FILE reference in the scan, so it needs no per-tile FUSE open. The directory DataSource path opens each tile on the worker.
Per-tile FILE writes themselves are not the fast path; the benefit is on the read side once the
table exists. For large-dataset write throughput on Serverless, geojsonl_gbx (sharded) and
gpkg_gbx scale horizontally without single-node assembly.
See the full capability tiers & read-options matrix.
Writers in detail
| Writer | Format Name | Description |
|---|---|---|
| Raster Writer | raster_gbx | Pure-Python catch-all raster writer (no JAR; DataSource V2) |
| GeoTIFF Writer | gtiff_gbx | Pure-Python GeoTIFF writer (driver forced to GTiff) |
| COG Writer | cog_gbx | Pure-Python cloud-optimized GeoTIFF writer — converts source files to master COGs (path-direct where possible). |
| PMTiles Writer | pmtiles_gbx | Package a tile pyramid into spatially-sharded PMTiles archives + a catalog. |
| Vector Writer | vector_gbx | Pure-Python generic vector writer (pyogrio); any OGR-supported driver. |
| Shapefile Writer | shapefile_gbx | Pure-Python Shapefile writer (OGR driver: ESRI Shapefile). |
| GeoJSON Writer | geojson_gbx | Pure-Python GeoJSON writer (OGR driver: GeoJSON) — single merged file. |
| GeoJSONL Writer | geojsonl_gbx | Multi-file newline-delimited GeoJSONL — one shard per partition, no driver merge. |
| GeoPackage Writer | gpkg_gbx | Pure-Python GeoPackage writer (OGR driver: GPKG). |
| GeoDatabase Writer | file_gdb_gbx | Pure-Python File Geodatabase writer (OGR driver: OpenFileGDB). |
| NetCDF Writer | netcdf_gbx | Pure-Python CF NetCDF writer — CF grids (raster) or CF-DSG points (vector), with singleFile / merge consolidation. |
| LiDAR Writer | lidar_gbx | Pure-Python LAS/LAZ point-cloud writer — one .laz per Spark partition by default, with singleFile / merge consolidation and keepParts control. |
See the Raster Writer page for full usage, options, and the nameCol / ext controls.
Benchmarks
Per-format timing results — spanning the vector writers (GeoJSON, Shapefile, GeoPackage, GeoJSONL) and the PMTiles writer — are published on the Benchmarking page, with the full methodology.
Every vector writer reads the CRS from the geom_0_srid column (EPSG/ESRI/OGC authority code) and passes it to the OGR driver via srs.SetFromUserInput. When srid is "0", the geom_0_srid_proj PROJ4 column is the fallback. Raster writers preserve the CRS from each tile's spatial reference metadata. See Coordinate reference systems for the full SRID-vs-CRS-string model and the ESRI/OGC authority-preservation behavior.
Next Steps
- Raster Writer — full details, options, and examples for raster output.
- GeoTIFF Writer — full details, options, and examples for GeoTIFF output.
- PMTiles Writer — full details, options, and examples for tile-pyramid output.
- Readers Overview — the corresponding read paths.
- Helios notebooks — worked end-to-end example using the PMTiles writer to package raster and terrain pyramids over a San Francisco AOI.