GeoPackage Reader
Since: gpkg_gbx v0.4.0
gpkg_gbx reads OGC GeoPackage files. It is pure Python (pyogrio-backed) and needs no JAR.
It produces the (attrs..., <geom>, <geom>_srid, <geom>_srid_proj) schema, where <geom> is the geometry column's name in the layer (geom in the sample file).
Options
GeoPackage files can contain multiple layers. gpkg_gbx presets the GPKG driver and exposes a layer selector.
| Option | Default | Description |
|---|---|---|
chunkSize | "10000" | Features per unit of work. The layer is streamed in batches of this many features, so per-task memory scales with chunkSize, not layer size. |
layerNumber | "0" | Layer index to read (0-based). Ignored when layerName is set. |
layerName | "" | Layer name to read; takes precedence over the layer index when set. |
asWKB | "true" | Output geometry as WKB (binary) vs WKT (text). |
codedDomains | "code" | Fields with a coded-value domain return the stored code in the field's declared type ("code", the default) or the domain's description as a string ("description"; a code not listed in the domain returns the code as text). Range domains pass through unchanged. |
All other vector reader options (driverName, …) are also available.
Basic usage
# Lightweight GeoPackage reader (pyogrio; no JAR)
from databricks.labs.gbx import register
register(spark)
df = spark.read.format("gpkg_gbx").load(SAMPLE) # (attrs..., <geom>, <geom>_srid, <geom>_srid_proj)
df.show()
The reader has Python and SQL bindings.
Typical pipeline: ingest into a table
The common pattern is to land GeoPackage files in a table for downstream analytics — on Databricks a managed table is Delta:
df = spark.read.format("gpkg_gbx").load("/Volumes/main/geo/raw/") # a folder of .gpkg files
df.write.mode("overwrite").saveAsTable("main.geo.districts") # 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.
Regular-expression filters (REGEXP)
REGEXP is an operator of GDAL's SQLite SQL dialect. It is available when GDAL is built with PCRE2, as the GeoBrix env
wheels' GDAL is. On a GeoPackage, select with sql_dialect="INDIRECT_SQLITE". A GeoPackage is itself an SQLite
database, so the plain SQLITE dialect, like the readers' where option, runs in the file's own SQLite, which has no
REGEXP. For files that are not SQLite databases (Shapefile, GeoJSON, FlatGeobuf, ...), sql_dialect="SQLITE" takes
REGEXP directly.
# Rows whose name matches a regular expression, read from a GeoPackage
import pyogrio
df = pyogrio.read_dataframe(
SAMPLE,
sql="SELECT boroname FROM boroughs WHERE boroname REGEXP '^M.*n$' ORDER BY boroname",
sql_dialect="INDIRECT_SQLITE", # a GeoPackage's own SQLite has no REGEXP
)
print(list(df["boroname"]))
REGEXP_GPKG_output = "['Manhattan']"
Output Schema
The output keeps the attribute columns and adds the geometry columns. The geometry column has the name the layer gives it (geom in the sample file) and is followed by its _srid and _srid_proj columns:
root
|-- <attribute_columns>: various types
|-- geom: binary (geometry in WKB format)
|-- geom_srid: string (spatial reference ID)
|-- geom_srid_proj: string (projection definition)
Next Steps
- View API Reference
- Check Examples
- Other Readers
- Learn about VectorX
- Ingestion Pipelines — ingest new and changed files incrementally
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 capability | Used here? | How / why |
|---|---|---|
list_local_files (session-free enumeration) | Used | Directory 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 read | Not in the DataSource | The 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 write | Not in the DataSource | FILE-tier writes go through vector_file_write (function layer). The DataSource writer commits via FUSE. |
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.