GeoDatabase Writer
Since: file_gdb_gbx v0.4.0
file_gdb_gbx — a pure-Python DataSource V2 writer like the other *_gbx writers. It
encodes the .gdb with the OpenFileGDB driver in pyogrio's bundled GDAL, so it needs no
native GDAL. It round-trips with the file_gdb_gbx reader; the
schema (attrs..., geom_0, geom_0_srid, geom_0_srid_proj) is shared across the
*_gbx vector readers and writers.
- Large datasets: this writer assembles the
.gdbon a single node. GDAL's FileGDB writer keeps per-feature index state in memory, so driver memory grows with the feature count. It uses about 120 bytes per feature; a 14-million-polygon write peaked at 1.9 GB. For very large outputs, use a classic cluster with ample memory or switch to the distributedgeojsonl_gbxwriter. See Choosing a writer for large datasets. - Compute:
file_gdb_gbxruns at the Python level, for writing and for reading. It runs wherever the env wheel runs: Serverless, standard and dedicated clusters, x86 and ARM. See Benchmarking for timings and methodology.
- Register first — call
register(spark)once before using any*_gbxformat (see the Writers Overview). - Output path — must end in
.gdb(or.gdb.zipwithzip=true). - Esri field limits — Esri field-name and type limits apply. A name that is an SQL
reserved word (for example
by) is renamed with a trailing underscore. - Column types — each column is written with the type of its DataFrame column. An
intstays a 32-bit integer and asmallinta 16-bit integer (the earlier encoder wrote them as doubles). Afloatstays a single-precision float. Abooleanis stored as an integer, and adecimalas a double. - ArcGIS version — the
targetArcGisVersionoption decides which Esri clients can open the layer. By default (auto) a DataFrame with a long (64-bit integer), date or timestamp column targets ArcGIS Pro 3.2 or later. Those columns keep their exact types (64-bit integer, date-only and timestamp-with-offset fields). They are not rounded to a double or written as a date-time with no offset. The option stamps the whole layer as needing a 3.2 client. An older Esri client may therefore refuse to open it, even for a layer whose other columns are plain. A DataFrame with none of those columns is written for every Esri client. An integerOBJECTIDcolumn is the feature id, not a field, so it does not count. PassALLto write for every client and accept the rounding, orARCGIS_PRO_3_2_OR_LATERto always target Pro 3.2. GeoBrix's readers, and any reader built on GDAL 3.11 or later, open a Pro 3.2 layer; other readers depend on the GDAL they bundle. - Geometry — a layer holds one geometry type: points, lines or polygons, or their multi-part
forms. A polygon and a multipolygon can share a layer. A point and a line cannot, and GDAL
fails the write. Z coordinates are kept. A NULL geometry is written as a feature with no
geometry. The type and CRS come from the first geometry found, whatever its partition. If
every geometry is NULL, the type cannot be inferred and the write stops with an error asking
for the
geometryTypeoption. - Reserved column names — the geometry field of a File Geodatabase layer is
SHAPE, so a column namedshapein any letter case is refused with an error. Rename it first (for exampleshape_attr). A column namedOBJECTID(the match ignores case) is not written as an attribute. GDAL uses an integer one as the feature ids, so rename it to keep its values as ordinary data. A non-integerOBJECTIDcolumn, or integer values that are0, negative, above 2^31 or repeated, fail the write with a GDAL error. The warning about anOBJECTIDcolumn is raised inside Spark's Python worker and may not show in your notebook output. This page is where to look for it. Other writers (GeoPackage, GeoJSON, Shapefile) accept columns with these names. - Input geometry — provide geometry as WKB (binary) or WKT (text), with the CRS in
the companion
*_srid/*_srid_projcolumns. EWKB, EWKT, and GeoJSON-encoded geometry are not accepted. Writing from a DatabricksGEOMETRY/GEOGRAPHYcolumn? Export to WKB first withST_AsBinary(orST_AsTextfor WKT) — see the Schema section below — and avoidST_GeomAsEWKB/ST_AsEWKT/ST_AsGeoJSON.
Options
| Option | Default | Behavior |
|---|---|---|
driverName | OpenFileGDB (preset) | OGR driver. Preset by this named writer; override only if needed. |
mode | overwrite | overwrite only; append is rejected. |
fileName | (none) | Name the output unit explicitly. When set, .save(path) treats path as the parent directory (created if missing) and writes path/<fileName>.gdb (or path/<fileName>.gdb.zip when zip=true; extension auto-completed). See Output naming. |
zip | false | When true, produce a single .gdb.zip archive (the .gdb directory packed at the archive root) instead of a .gdb directory. The output path is normalised automatically: .save("roads") → roads.gdb.zip; .save("roads.gdb") → roads.gdb.zip. The reader opens .gdb.zip transparently. Ignored for non-FileGDB drivers. |
geometryType | inferred from the data | Override the OGR geometry type. |
layerName | layer | Output layer (feature class) name. |
targetArcGisVersion | auto | Which Esri clients can open the layer, matched without regard to case. auto targets ArcGIS Pro 3.2 or later only when the DataFrame has a long, date or timestamp column; ALL writes for every client (a long is stored as a double, a date as a date-time and a timestamp as a date-time with no offset); ARCGIS_PRO_3_2_OR_LATER always targets Pro 3.2 and keeps those types exactly. The Pro 3.2 target stamps the whole layer with RequiredGeodatabaseClientVersion 13.2. Any other value raises an error. |
geomCol | auto-detected from the *_srid column | Override the geometry column name. Locates the geometry and its SRID companion (<geomCol>_srid). See Named Vector Formats. |
sridCol | <geomCol>_srid | Override the SRID column name. Required — supplies the CRS authority code (e.g. "4326", or "0" if unknown). |
projCol | <geomCol>_srid_proj | Override the PROJ4 column name (optional fallback CRS when sridCol is "0"). |
Schema
file_gdb_gbx uses the shared vector column contract — a geometry column
plus its *_srid (required) / *_srid_proj (optional) CRS companions; every other column
becomes an attribute. Point the writer at your columns with geomCol / sridCol / projCol,
or coerce to the geom_0 convention.
(df # geometry + CRS under your own column names
.write.format("file_gdb_gbx")
.option("geomCol", "the_geom") # WKB or WKT
.option("sridCol", "epsg") # REQUIRED — CRS authority code
.option("projCol", "crs_proj") # optional — PROJ4 fallback
.mode("overwrite").save("/Volumes/cat/sch/vol/parcels.gdb"))
For coercing an arbitrary frame to this shape and for exporting Databricks GEOMETRY /
GEOGRAPHY columns, see the Vector Writer schema.
Output: an ESRI File Geodatabase (a .gdb directory, or a single .gdb.zip with
zip=true — see below); the geometry is stored in a named field (default SHAPE).
Producing a portable ZIP archive
Pass zip=true to write a single self-contained .gdb.zip instead of a .gdb directory —
the .gdb folder is packed at the archive root, the layout GDAL expects. The output path is
normalised regardless of the extension you supply — .save("roads"), .save("roads.gdb"),
and .save("roads.gdb.zip") all land at roads.gdb.zip:
(df.write.format("file_gdb_gbx")
.option("zip", "true")
.mode("overwrite").save("/Volumes/cat/sch/vol/parcels")) # -> parcels.gdb.zip
The file_gdb_gbx reader opens a .gdb.zip directly
(via GDAL's /vsizip/), so the archive round-trips with no extra step.
How it scales
Unlike a single-node pyogrio.write_* call that serializes one file on one machine, the
file_gdb_gbx writer runs as a Spark DataSource V2 two-phase write. Each executor
writes its partition concurrently to a scratch fragment. Then the driver merges the
fragments into one output file. The merge is sequential and rename-free, so it is safe on
FUSE-mounted cloud storage (Unity Catalog Volumes, DBFS). Repartition the input to control
write parallelism.
Output naming
file_gdb_gbx applies the standard single-file output naming contract. The canonical extension is .gdb (or .gdb.zip when zip=true). Rules evaluated in order:
| Case | .save(path) / fileName | Resolved output |
|---|---|---|
fileName given | .option("fileName","parcels").save("/out/exports") | /out/exports/parcels.gdb |
No fileName; path is an existing directory | .save("/out/exports") | /out/exports/exports.gdb |
No fileName; path is a stem | .save("/out/exports/parcels") | /out/exports/parcels.gdb |
With zip=true replace .gdb with .gdb.zip in the table above. Extension auto-completion: parcels → parcels.gdb; parcels.gdb → unchanged; parcels.gdb.zip → unchanged (when zip=true). Passing a name ending in a different recognized geo extension (e.g. .gpkg) raises a clear error.
Example
# Lightweight GeoDatabase writer (pyogrio; OGR driver preset to "OpenFileGDB")
from databricks.labs.gbx import register
register(spark)
src = f"{SAMPLE_DATA_BASE}/nyc/filegdb/NYC_Sample.gdb.zip"
df = spark.read.format("file_gdb_gbx").load(src)
out = "/tmp/NYC_Sample.gdb" # FileGDB output path must end in .gdb
df.write.format("file_gdb_gbx").mode("overwrite").save(out)
back = spark.read.format("file_gdb_gbx").load(out)
assert back.count() == df.count()
Typical pipeline: export a table to a single file
Export a table of vector data to a File Geodatabase — no coalesce needed (the writer merges partitions into a single file on commit). The output path must end in .gdb:
df = spark.table("main.geo.parcels") # vector data in a (Delta) table
df.write.format("file_gdb_gbx").mode("overwrite").save("/Volumes/main/geo/exports/parcels.gdb")
Each partition is written concurrently, then merged into one output file. See Benchmarking for export timings.
Common functions: used vs excluded
See GBX Common Functions for the full catalog of shared file-access primitives. The table below shows which are active in this writer and which are not, and why.
| Common capability | Used here? | How / why |
|---|---|---|
list_local_files (session-free enumeration) | Not used by the writer | Writers do not enumerate source files; they write a DataFrame's output partitions. |
gbx_file_write / FILE-tier write | Not in the DataSource | The DataSource writer (df.write.format("file_gdb_gbx")) is session-less on Connect and commits via FUSE. FILE-tier writes use vector_file_write at the function layer instead. |
gbx_file_read (FILE-tier read) | Not in the DataSource | FILE-tier reads for vector data go through vector_file_read at the function layer. |
The writer reads the CRS from the geom_0_srid column (or sridCol) and writes it into the layer's spatial reference. An EPSG or ESRI authority code is accepted; if srid is "0", the geom_0_srid_proj PROJ4 fallback is used. The CRS is stored in the FileGDB's spatial reference record. See Coordinate reference systems for the full CRS model.
The *_gbx writers commit via the shared file_gbx file-access base — file_mode, layout, and the no-gating rule are described there. See also file_gbx Writer for the write API.