Skip to main content

GeoJSONL Writer (multi-file)

Since: geojsonl_gbx v0.4.0

Emit a directory of newline-delimited GeoJSONL shards (OGR driver GeoJSONSeq, one Feature per line) — one shard per partition, no driver merge. The single-file GeoJSON writer merges every partition into one FeatureCollection file on the driver. In the GeoJSONL writer the shards are the dataset, so write throughput scales with partitions. An optional maxRecordsPerFile splits a partition into several shards.

The geojsonl_gbx writer is pure-Python and Serverless-safe (pyogrio). It produces a directory of part-<uuid>.geojsonl shards that round-trips with the GeoJSON reader's directory mode: read it back via geojson_gbx with option("multi","true").

Compute & scale
  • Large datasets: GeoJSONL is the recommended writer for large data — one shard per partition, no driver assembly, write throughput scales with partitions. See Choosing a writer for large datasets for a comparison with the single-file writers.
  • Compute: the geojsonl_gbx writer needs no JAR and runs on every compute, Serverless and standard (shared) clusters included. See Benchmarking for timings and methodology.
Before you write
  • Register first — call register(spark) once before using any *_gbx format (see the Writers Overview).
  • Input geometry — provide geometry as WKB (binary) or WKT (text), with the CRS in the companion *_srid / *_srid_proj columns. EWKB, EWKT, and GeoJSON-encoded geometry are not accepted. Writing from a Databricks GEOMETRY / GEOGRAPHY column? Export to WKB first with ST_AsBinary (or ST_AsText for WKT) — see the Schema section below — and avoid ST_GeomAsEWKB / ST_AsEWKT / ST_AsGeoJSON.

Options​

OptionDefaultBehavior
maxRecordsPerFileunset (one shard per partition)If set, split each partition into multiple shards of at most this many features.
modeoverwriteoverwrite only; append is rejected. The target directory is cleared once before the shards land.
geometryTypeinferred from the dataOverride the OGR geometry type.
layerNamedriver defaultOutput layer name where supported.
geomColauto-detected from the *_srid columnOverride the geometry column name. Locates the geometry and its SRID companion (<geomCol>_srid). See Named Vector Formats.
sridCol<geomCol>_sridOverride the SRID column name. Required — supplies the CRS authority code (e.g. "4326", or "0" if unknown).
projCol<geomCol>_srid_projOverride the PROJ4 column name (optional fallback CRS when sridCol is "0").

Schema​

geojsonl_gbx uses the shared vector column contract — a geometry column plus its *_srid (required) / *_srid_proj (optional) CRS companions; every other column becomes a feature attribute. Point the writer at your columns with geomCol / sridCol / projCol, or coerce to the geom_0 convention.

Output: a directory (out/) containing one part-<uuid>.geojsonl shard per non-empty partition (plus an advisory _SUCCESS marker). Each shard is a sequence of newline-delimited GeoJSON Feature objects; attributes are written as feature properties.

Write it​

Name your geometry/CRS columns with options (or coerce to the geom_0 convention — see the Vector Writer schema for that and for exporting Databricks GEOMETRY / GEOGRAPHY columns), then write:

(df # geometry + CRS under your own column names
.write.format("geojsonl_gbx")
.option("geomCol", "the_geom") # WKB or WKT
.option("sridCol", "epsg") # REQUIRED — CRS authority code
.mode("overwrite").save("/Volumes/cat/sch/vol/out"))

Read it back with the GeoJSON reader's directory mode — multi=true enumerates the .geojsonl shards and parses each as a GeoJSONSeq sequence:

back = spark.read.format("geojson_gbx").option("multi", "true").load("/Volumes/cat/sch/vol/out")

How it scales​

The single-file GeoJSON writer writes one merged file: each partition writes a fragment, then the driver concatenates all fragments into a single FeatureCollection. That driver-side merge is sequential — fine for "one file for the table", but a single-node bottleneck at scale.

The GeoJSONL writer writes one shard per partition with no driver merge. Each executor encodes its partition to a worker-local GeoJSONL shard. It then copies the shard sequentially into the output directory (rename-free, so safe on FUSE-mounted Unity Catalog Volumes / DBFS). Because GeoJSONL is splittable and concatenable, the directory of shards is the dataset. There is nothing to assemble on the driver, so write throughput scales with the number of partitions. Use df.repartition(n, "<col>") to set shard granularity, or maxRecordsPerFile to cap features per shard (splitting a large partition into several shards). The writer parallelizes per partition with pyogrio.

Serverless: repartition by a column

On Serverless, hash by a column — df.repartition(n, "<key>") — to control parallelism. A number-only df.repartition(n) (round-robin) is coalesced by AQE back toward a single partition on small data (= serial write), and AQE can't be disabled there. Hashing by any high-cardinality column (an id/key) is respected. On classic clusters either form works.

Choose the single-file GeoJSON writer when you want one file; choose GeoJSONL for large, streaming, or highly parallel writes.

Typical pipeline: export a table to a sharded directory​

Export a table of vector data to a directory of GeoJSONL shards — repartition to control write parallelism (one shard per partition):

StepCode
1. Load a tabledf = spark.table("main.geo.parcels")
2. Set parallelismdf = df.repartition(64, "id")  (by a column — see Serverless note above)
3. Write shardeddf.write.format("geojsonl_gbx").mode("overwrite").save("/Volumes/main/geo/exports/parcels")
4. Read backspark.read.format("geojson_gbx").option("multi","true").load("/Volumes/main/geo/exports/parcels")
df = spark.table("main.geo.parcels") # vector data in a (Delta) table
df.repartition(64, "id").write.format("geojsonl_gbx").mode("overwrite").save(
"/Volumes/main/geo/exports/parcels" # hash by a column (Serverless-safe; see note above)
)
# -> a directory of 64 part-<uuid>.geojsonl shards, written in parallel, no driver merge

To cap features per shard regardless of partition size:

df.write.format("geojsonl_gbx").mode("overwrite").option(
"maxRecordsPerFile", "50000"
).save("/Volumes/main/geo/exports/parcels")

Next Steps​

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 capabilityUsed here?How / why
list_local_files (session-free enumeration)Not used by the writerWriters do not enumerate source files; they write a DataFrame's output partitions.
gbx_file_write / FILE-tier writeNot in the DataSourceThe DataSource writer (df.write.format("geojsonl_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 DataSourceFILE-tier reads for vector data go through vector_file_read at the function layer.
Coordinate reference systems

The writer reads the CRS from the geom_0_srid column (or sridCol) and passes it to the OGR GeoJSONSeq driver. Per RFC 7946, each Feature is WGS84. If srid is "0", or an integer code that is neither an EPSG nor an ESRI code, the geom_0_srid_proj PROJ4 fallback is used. See Coordinate reference systems for the full CRS model.

Shared file-access layer

The 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.