PMTiles Reader
Since: pmtiles_gbx v0.4.0
The pmtiles_gbx reader produces a tile pyramid as
(z, x, y, bytes) rows. It has two sources, chosen by the source option:
source="raster"— build an XYZ (slippy-map) tile mosaic pyramid from a directory of Cloud-Optimized GeoTIFFs / rasters. Each slippy tile in the area of interest is rendered (one composited PNG per(z, x, y)) across the cluster.source="archive"— read tiles back out of an existing.pmtilesarchive, one row per stored tile.
Both sources emit the same (z, x, y, bytes) schema. This is exactly the
input schema the PMTiles writer expects, so a read feeds
straight into a write with no reshaping.
pmtiles_gbx is a pure-Python DataSource V2 reader: no JAR,
and it runs on Serverless, standard (shared), and ARM clusters. The
pmtiles_gbx reader documented here is the read path for PMTiles in GeoBrix.
Register the *_gbx DataSources once per session:
# Register the lightweight DataSources (once per session)
from databricks.labs.gbx import register
register(spark)
Output schema
Both sources produce the same four columns — identical to the PMTiles writer input:
root
|-- z: integer (zoom level, not null)
|-- x: integer (slippy tile column, not null)
|-- y: integer (slippy tile row, not null)
|-- bytes: binary (tile payload — a rendered PNG for source="raster",
| the stored tile bytes verbatim for source="archive")
source="raster" — mosaic pyramid from rasters
Point the reader at a directory of rasters and an area of interest. It enumerates
the slippy tiles across the zoom range, attaches only the sources that intersect
each tile, and renders one tile per (z, x, y) with rio-tiler.
# source="raster": tile a directory of COGs into an XYZ pyramid.
# Emits one rendered (z, x, y, bytes) tile row per slippy tile in the AOI.
df = (spark.read.format("pmtiles_gbx")
.option("source", "raster")
.option("bbox", "-122.50,37.74,-122.40,37.79") # minx,miny,maxx,maxy (WGS84)
.option("minZoom", "12")
.option("maxZoom", "16")
.option("tileFormat", "png")
.load("/Volumes/main/geobrix_samples/naip/sf/"))
# columns: z (int), x (int), y (int), bytes (binary — a rendered PNG tile)
df.show()
Because the output is already the writer's input schema, packaging the pyramid
into a .pmtiles archive is a direct hand-off:
# The (z, x, y, bytes) rows feed straight into the pmtiles writer —
# no reshaping — packaging the mosaic pyramid into a single archive.
(df.write.format("pmtiles_gbx")
.option("shardZoom", "0") # 0 = one single .pmtiles archive
.mode("overwrite")
.save("/Volumes/main/geobrix_samples/naip/sf.pmtiles"))
Options — source="raster"
| Option | Default | Description |
|---|---|---|
path (.load(...)) | — (required) | Directory of source rasters. |
bbox | source union | Area of interest as "minx,miny,maxx,maxy" in WGS84. Absent → the combined bounds of all sources. |
minZoom / maxZoom | "0" / "0" | Inclusive slippy-map zoom range to render. |
tileFormat | "png" | Rendered tile encoding. |
tilesPerPartition | "64" | Tiles per Spark partition (fan-out granularity). |
filterRegex | ".*\.tif$" | Keep only source files whose path matches. |
pixelSelection | "first" | Mosaic pixel-selection method. Only "first" is supported in v1; any other value raises. |
An AOI (or bbox) that intersects zero tiles for the requested zoom range logs a
warning. The result is an empty DataFrame with the standard schema, not an error.
source="archive" — read an existing .pmtiles
Read the tiles stored in a .pmtiles file back into a DataFrame, one row per
tile. The tile bytes are returned verbatim (whatever encoding the archive
stores — PNG/JPEG/WebP/MVT).
# source="archive": read tiles back out of an existing .pmtiles file.
df = (spark.read.format("pmtiles_gbx")
.option("source", "archive")
.load("/Volumes/main/geobrix_samples/naip/sf.pmtiles"))
# same (z, x, y, bytes) schema — bytes are the stored tile payload, verbatim
df.show()
Options — source="archive"
| Option | Default | Description |
|---|---|---|
path (.load(...)) | — (required) | The .pmtiles archive to read. |
tilesPerPartition | "2048" | Tiles per Spark partition. |
Next Steps
- PMTiles Writer — package
(z, x, y, bytes)rows into archives. - VizX — PMTiles viewer — inspect a
.pmtilesarchive in a notebook. - Helios notebooks — end-to-end tiling to PMTiles over a San Francisco AOI.
- 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 | All directory reads — recursive, include_hidden, extensions, path_glob_filter options are routed through this shared predicate. |
enumerate_files (FILE-tier enumeration) | Not in the DataSource | The DataSource is session-less on Connect and does not call enumerate_files; FILE-tier enumeration is only available through gbx_file_read at the function layer. |
gbx_file_read / gbx_file_write (FILE tier) | Not in the DataSource | The DataSource is FUSE-only (session-less on Connect); FILE reads go through gbx_file_read → rst_fromfile at the function 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.