Skip to main content

Quick Start

This guide will help you get started with GeoBrix quickly after installation. All code below is copy-paste executable when you use the sample data paths shown.

Install and register​

Install the env wheel for your runtime, then register once per session. One wheel covers RasterX (every rst_* function), VectorX (gbx_st_*) and GridX (gbx_bng_*, gbx_quadbin_*, gbx_custom_*, gbx_h3_*), plus the readers and writers. It runs on Serverless, standard and dedicated clusters, ARM and Lakeflow pipelines.

# Stage the env wheel for your runtime in a Unity Catalog Volume (+env6: Serverless environment 6
# and DBR 19; +env5: environment 5 and DBR 17.3 / 18), then install it with the quoted
# PEP 508 "name @ file://" form (Serverless-safe); add feature extras as "geobrix[vizx] @ ...":
%pip install "geobrix @ file:///Volumes/<catalog>/<schema>/<volume>/geobrix-<version>+env6-py3-none-any.whl"

from databricks.labs import gbx
gbx.register(spark) # the gbx_* SQL functions and the *_gbx readers and writers
Quote the geobrix[<extras>] @ file://… requirement

Install with the named, quoted form above. Do not put an extra on the path ('/Volumes/…/…whl[vizx]'). On Serverless, %pip writes the requirement to a file including the quotes. Pip then reads [vizx] as part of the filename and fails. The error is "Expected package name at the start of dependency specifier." The named form installs cleanly on Serverless, standard/shared, and ARM.

GeoBrix picks the faster implementation the compute offers and says why when it falls back. A dedicated cluster can also add the GeoBrix JAR. See Installation for the install paths and Surfaces & Levels for how GeoBrix picks.

Set up sample data first

The examples on this page use sample data paths (e.g. /Volumes/.../geobrix-examples/nyc/...). To run them as-is, set up sample data first: Sample Data Guide — then use the same paths or volume in your notebook.

Prerequisites​

note

You do not need to register functions if you are only using the included readers.

Register Functions​

gbx.register(spark) registers every GeoBrix SQL function and the *_gbx readers and writers. Call it once per session.

# Register GeoBrix functions (required for gbx_rst_* in SQL)
from databricks.labs import gbx
gbx.register(spark)

register(spark, only=["gbx_rst_width"]) limits the functions it registers.

Scala registers no SQL. Register from Python or SQL, then call the SQL names from Scala:

Call GeoBrix from Scala
// Scala registers no SQL: register once from Python (databricks.labs.gbx.register(spark)),
// then call the SQL names.
spark.sql("SELECT gbx_rst_width(tile) FROM tiles")

Describe a Function​

-- Describe a function
DESCRIBE FUNCTION EXTENDED gbx_rst_boundingbox;
Example output
-DESCRIBE FUNCTION EXTENDED gbx_rst_boundingbox
Function: gbx_rst_boundingbox
Type: ...

Reading Data​

Paths below assume the Sample Data layout (e.g. Essential Bundle). The *_gbx readers are pure Python (no GDAL/OGR install) and run on every compute. To keep a table in sync with a landing folder rather than read it once, see Ingestion Pipelines.

gbx.register(spark) registers the readers. Load by format string (gtiff_gbx / raster_gbx for rasters; shapefile_gbx / geojson_gbx / gpkg_gbx / file_gdb_gbx for vectors).

Read GeoTIFF​

# Read GeoTIFF rasters (lightweight gtiff_gbx reader — pure-Python, no GDAL install)
from databricks.labs import gbx
gbx.register(spark) # register the lightweight readers once per session
rasters = spark.read.format("gtiff_gbx").load("/Volumes/main/default/geobrix_samples/geobrix-examples/nyc/sentinel2/nyc_sentinel2_red.tif")
rasters.limit(3).show()
Example output
+--------------------+----+-----+------+
|source |bbox|width|height|
+--------------------+----+-----+------+
|.../nyc/sentinel2/..|... |10980|10980 |
+--------------------+----+-----+------+
Virtual tiles by default

The raster reader returns virtual tiles by default. Each row carries a bytes-free (path, window) reference instead of the raster pixels, so a large file fans into tiles without accumulating memory. Pass .option("virtualTiles", "false") (or use materialize=True on a downstream rst_* call) when you need the bytes in-row.

Read Shapefile​

# Read shapefile (lightweight shapefile_gbx reader — pyogrio-backed, no OGR install)
from databricks.labs import gbx
gbx.register(spark) # register the lightweight readers once per session
shapes = spark.read.format("shapefile_gbx").load("/Volumes/main/default/geobrix_samples/geobrix-examples/nyc/subway/nyc_subway.shp.zip")
shapes.limit(3).show()
Example output
+----+--------+-----+
|path|geom_0 |... |
+----+--------+-----+
|... |[BINARY]|... |
+----+--------+-----+

Read GeoJSON​

# Read GeoJSON
geojson_df = spark.read.format("geojson_gbx").option("multi", "false").load(
"/Volumes/main/default/geobrix_samples/geobrix-examples/nyc/taxi-zones/nyc_taxi_zones.geojson"
)
geojson_df.limit(3).show()
Example output
+----------+--------+-----+
|path |geom_0 |... |
+----------+--------+-----+
|... |[BINARY]|... |
+----------+--------+-----+

Using RasterX, GridX, and VectorX​

RasterX​

Once registered, call the rx.rst_* functions from Python or the gbx_rst_* names from SQL.

# Register, load raster, apply RasterX
from databricks.labs import gbx
from databricks.labs.gbx.rasterx import functions as rx
gbx.register(spark)
rasters = spark.read.format("raster_gbx").load("/Volumes/main/default/geobrix_samples/geobrix-examples/nyc/sentinel2/nyc_sentinel2_red.tif")
rasters.select(rx.rst_boundingbox("tile").alias("bbox"), rx.rst_width("tile"), rx.rst_height("tile")).limit(3).show()
Example output
+--------------------+-----+------+
|bbox |width|height|
+--------------------+-----+------+
|POLYGON ((...)) |10980|10980 |
+--------------------+-----+------+

GridX​

All GridX grids — quadbin (gx.quadbin_* / gbx_quadbin_*), BNG (gbx_bng_*), custom grids (gbx_custom_*) and H3 (gbx_h3_*) — run on every compute.

Index a point to a quadbin cell and read its resolution:

# Register GeoBrix, index a point with quadbin, inspect the cell
from databricks.labs import gbx
from databricks.labs.gbx.gridx.quadbin import functions as qx
from pyspark.sql import Row
from pyspark.sql.functions import lit
gbx.register(spark)
# A point in NYC (WGS84 lon/lat) -> a resolution-15 quadbin cell, then its resolution
points = spark.createDataFrame([Row(lon=-73.985, lat=40.748)])
points.select(
qx.quadbin_pointascell("lon", "lat", lit(15)).alias("cell")
).select(
"cell",
qx.quadbin_resolution("cell").alias("res"),
).show()
Example output
+-------------------+---+
|cell |res|
+-------------------+---+
|5256690677307146239|15 |
+-------------------+---+

Use the BNG grid in SQL:

# Register GeoBrix, then use BNG in SQL (gbx_bng_cellarea returns square kilometres)
from databricks.labs import gbx
gbx.register(spark)
spark.sql("SELECT gbx_bng_cellarea('TQ3080') as area_km2").show()
Example output
+----------+
|area_km2 |
+----------+
|1.0 |
+----------+

VectorX​

Call the vx.st_* functions from Python or the gbx_st_* names from SQL.

# Register VectorX, create legacy point struct, convert to WKB
from databricks.labs import gbx
from databricks.labs.gbx.vectorx import functions as vx
from pyspark.sql import Row
from pyspark.sql.types import ArrayType, DoubleType, IntegerType, StructField, StructType
gbx.register(spark)
legacy_schema = StructType([
StructField("typeId", IntegerType()),
StructField("srid", IntegerType()),
StructField("boundaries", ArrayType(ArrayType(ArrayType(DoubleType())))),
StructField("holes", ArrayType(ArrayType(ArrayType(ArrayType(DoubleType()))))),
])
row = Row(geom_legacy=(1, 0, [[[30.0, 10.0]]], []))
shapes = spark.createDataFrame([row], StructType([StructField("geom_legacy", legacy_schema)]))
shapes.select(vx.st_legacyaswkb("geom_legacy").alias("wkb")).show()
Example output
+-----------+
|wkb |
+-----------+
|[BINARY] |
+-----------+

Using SQL​

The gbx_* SQL names are the same on every compute. The *_gbx readers load the data (see Reading Data).

-- Read shapefile and query in SQL
CREATE OR REPLACE TEMP VIEW my_shapes USING shapefile_gbx OPTIONS (path '/Volumes/main/default/geobrix_samples/geobrix-examples/nyc/subway/nyc_subway.shp.zip');

SELECT * FROM my_shapes LIMIT 3;
Example output
+----+--------+-----+
|path|geom_0 |... |
+----+--------+-----+
|... |[BINARY]|... |
+----+--------+-----+

Next Steps​