Skip to main content

GeoJSON Reader

Since: geojson_gbx v0.4.0

geojson_gbx reads GeoJSON and GeoJSONSeq, as well as ESRIJSON, TopoJSON and JSON-FG. It is pure Python (pyogrio-backed) and needs no JAR. It produces the (attrs..., geom_0, geom_0_srid, geom_0_srid_proj) schema.

Options​

The driver (GeoJSON) is preset. Each file is read with the GeoJSON-family driver GDAL detects for it: GeoJSON (FeatureCollection), GeoJSONSeq (newline-delimited), ESRIJSON, TopoJSON or JSON-FG. A .geojsonl file therefore needs no option. A file named for another format (e.g. data.csv) is read with the first of those drivers that opens it. A file none of them opens fails. The error names the file and, when GDAL recognizes it as another format, the reader to use instead. When GDAL cannot recognize it as any format, the error says so. A JSON file with no features fails with a "no features/fields found" error.

OptionDefaultDescription
asWKB"true"Output geometry as WKB (binary) vs WKT (text).
chunkSize"10000"Features per streamed batch: the layer is read in batches of this many features, so per-task memory scales with chunkSize, not layer size.
layerNumber"0"Layer index to read (0-based).
layerName""Layer name to read; takes precedence over layerNumber when set.
multi"false""true" reads a folder of GeoJSONSeq shards (.geojsonl / .geojsons, e.g. written by geojsonl_gbx) instead of its .geojson / .json files. A single file reads the same either way.

Basic usage​

# Lightweight GeoJSON reader (pyogrio; no JAR)
from databricks.labs.gbx import register
register(spark)
df = spark.read.format("geojson_gbx").load(SAMPLE) # (attrs..., geom_0, geom_0_srid, geom_0_srid_proj)
df.show()

The reader has Python and SQL bindings.

Typical pipeline: ingest into a table​

The common pattern is to land GeoJSON files in a table for downstream analytics — on Databricks a managed table is Delta:

df = spark.read.format("geojson_gbx").load("/Volumes/main/geo/raw/") # a folder of .geojson files
df.write.mode("overwrite").saveAsTable("main.geo.boroughs") # Delta table on Databricks

Reading a folder fans the files across the cluster, one partition per file, so ingest scales with the data. A single-node pyogrio.read_* parses one file on one machine. See Benchmarking for ingest figures.

Output Schema​

The output maintains attribute columns and adds three columns for geometry:

root
|-- geom_0: binary (geometry in WKB format)
|-- geom_0_srid: integer (spatial reference ID)
|-- geom_0_srid_proj: string (projection definition)
|-- <properties>: various types (GeoJSON properties)

GeoJSON vs GeoJSONSeq​

A standard GeoJSON file holds one FeatureCollection. A GeoJSONSeq file (.geojsonl, .geojsons) holds one feature per line. The reader detects the form from the file, so you need no option. To read a folder of GeoJSONSeq shards, such as the output of geojsonl_gbx, set multi to "true".

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 reader and which are not, and why.

Common capabilityUsed here?How / why
list_local_files (session-free enumeration)UsedDirectory reads — recursive, include_hidden, extensions, and path_glob_filter are routed through this shared predicate for all format-specific readers.
gbx_file_read / FILE-tier readNot in the DataSourceThe DataSource is session-less on Connect; FILE-tier reads go through vector_file_read (function layer) which injects _file_ref on the driver before mapInPandas.
gbx_file_write / FILE-tier writeNot in the DataSourceFILE-tier writes go through vector_file_write (function layer). The DataSource writer commits via FUSE.
Shared file-access layer

The *_gbx readers use the shared file_gbx file-access base for FILE / FUSE routing and enumeration — capability tiers, the no-gating rule, and layout options are described there.