Function Reference
A Scala tag on a function means the GeoBrix JAR has a faster JVM form of it. On dedicated compute with the JAR, GeoBrix runs that form for you. You still call the SQL or Python function. See Surfaces & Levels and Functions the JAR speeds up.
Overview
VectorX augments the product's native ST_* functions with vector-tile encoding, TIN surface modeling, authority-string CRS handling, antimeridian normalization, distributed-shapely geometry validity, cleaning, and coverage-validity. It also covers legacy-geometry migration.
Key Features
As of v0.5.0 it covers:
- Vector tile encoding —
gbx_st_asmvtaggregator andgbx_st_asmvt_pyramidgenerator for publishing Mapbox Vector Tile (MVT) layers - TIN surface modeling —
gbx_st_triangulate,gbx_st_interpolateelevationbboxandgbx_st_interpolateelevationgeomfor Delaunay triangulation and grid elevation interpolation from Z-valued points, with aconstrainedorconformingmode - CRS strings —
gbx_st_crs,gbx_st_setcrsandgbx_st_transformcrsfor reading, stamping and reprojecting a geometry's CRS by CRS string (ESRI codes, WKT, PROJ4 — not just an EPSG integer) - Geometry validity —
gbx_st_makevalidandgbx_st_explainvalidityfor repairing and diagnosing OGC-invalid geometries - Coverage validity —
gbx_st_coverageisvalid,gbx_st_coverageinvalidedges(SQL grouped aggregates) andcoverage_simplify(a Python helper) for validating and simplifying polygon coverages - Geometry cleaning —
gbx_st_simplifypreservetopology,gbx_st_removerepeatedpoints,gbx_st_reduceprecision,gbx_st_nodeandgbx_st_snapfor topology-safe simplification, vertex deduplication, precision reduction, noding and snapping - Antimeridian handling —
gbx_st_shiftlongitude,gbx_st_wrapxandgbx_st_splitfor normalizing geometries that cross the 180° antimeridian - Legacy Mosaic conversion —
gbx_st_legacyaswkbfor migrating geometries written by DBLabs Mosaic
Vector files are read and written by the *_gbx readers and writers. See the readers overview.
- Import paths — Python:
databricks.labs.gbx.vectorx.functions. Python-only helpers such ascoverage_simplify:databricks.labs.gbx.vectorx.helpers. - SQL examples — examples use SQL (and Python where shown); in SQL, VectorX functions are prefixed with
gbx_(e.g.gbx_st_legacyaswkb). For SQL and Python usage patterns, see Language Bindings. - Geometry input encodings — every
gbx_st_*geometry input accepts WKB, EWKB, WKT, and EWKT interchangeably. WKB/WKT carry no SRID; EWKB/EWKT carry one. Pass whichever encoding your upstream produces — no separate conversion step is required.
gbx_st_crs(geom) returns the geometry's canonical CRS string (e.g. "EPSG:4326", "ESRI:54008") or NULL for a geometry with no SRID. gbx_st_setcrs(geom, crs) stamps a CRS as a label-only change (raises for authority-less CRS — a geometry can only carry an integer SRID). gbx_st_transformcrs(geom, target_crs[, source_crs]) reprojects; an authority-less target reprojects and clears the stale SRID. All three accept WKB/EWKB/WKT/EWKT input and return BINARY (gbx_st_crs returns STRING). See Coordinate reference systems for the SRID-vs-CRS-string model, EPSG→ESRI resolution order, and ESRI/OGC authority-preservation behavior.
Levels by function
Every function runs on every compute through its Python level. On a dedicated cluster with the JAR, GeoBrix picks the JVM level for the functions in Functions the JAR speeds up. See Surfaces & Levels.
| Function | Levels | Notes |
|---|---|---|
st_asmvt | Python | |
st_asmvt_pyramid | Python | |
st_triangulate | Python, JVM | JVM level by default on a dedicated cluster; both modes run on every level |
st_interpolateelevationbbox | Python, JVM | JVM level by default on a dedicated cluster; both modes run on every level |
st_interpolateelevationgeom | Python | Both modes run on every level |
st_crs, st_setcrs | Python | |
st_transformcrs | Python, JVM | JVM level by default on a dedicated cluster |
st_legacyaswkb | Python, JVM, Unity Catalog | JVM level by default on a dedicated cluster |
st_makevalid, st_explainvalidity | Python, Unity Catalog | |
st_wrapx | Python, Unity Catalog | |
st_coverageisvalid, st_coverageinvalidedges | Python | |
coverage_simplify | Python helper | No SQL form |
st_simplifypreservetopology, st_removerepeatedpoints, st_reduceprecision, st_node, st_snap | Python | |
st_shiftlongitude, st_split | Python |
Setup
With GeoBrix already installed, register the functions once per session. Every example below assumes this setup.
from databricks.labs.gbx import register
from databricks.labs.gbx.vectorx import functions as vx
register(spark)
Legacy Mosaic geometries need no extra import. st_legacyaswkb is in the same vx module.
The examples on this page read from four canonical DataFrames, one per function family. Each is available as a temp view for SQL examples. Point the placeholders at your own data to reproduce the examples:
| View / DataFrame | Schema | Backed by | Backs |
|---|---|---|---|
tin_survey | pts ARRAY<BINARY>, bl ARRAY<BINARY> | 4 WKB POINT Z forming a 10×10 m square (elevations 0, 0, 10, 5 m) | TIN examples: st_triangulate, st_interpolateelevationbbox, st_interpolateelevationgeom |
mvt_features | z INT, x INT, y INT, geom_wkb BINARY, attrs STRUCT<name,id> | 2 tile-local WKB POINTs in tile (z=0, x=0, y=0) | Vector-tile examples: st_asmvt, st_asmvt_pyramid |
vector_geoms | geom STRING | EWKT literal 'SRID=4326;POINT (13 42)' | CRS examples: st_crs, st_setcrs, st_transformcrs |
legacy_geoms | geom_legacy STRUCT<typeId,srid,boundaries,holes> | Legacy Mosaic struct for POINT(13, 42) | Migration: st_legacyaswkb |
All four views are built from inline literals in the doc-test fixture helpers. There is no external file or /Volumes dependency, so the examples run anywhere. The views hold WKB POINT Z mass points for tin_survey, tile-local WKB points for mvt_features, an EWKT string for vector_geoms, and a legacy Mosaic struct for legacy_geoms.
Examples — Conventions
How to read the tabs
Every function on this page shows one example, expressed on each surface it runs on:
| Tab | Surface |
|---|---|
| SQL | Session SQL, after register(spark) |
| Unity Catalog SQL | A <catalog>.<schema>.gbx_* function, where the function exists in Unity Catalog |
| Python | The vectorx Python API |
The Scala tag has no tab: it links to Functions the JAR speeds up.
The tabs operate on the same input fixture with the same arguments. Where a genuine difference exists, such as a diverging output schema or a mode available at one level only, the affected tab carries a labeled :::note. A difference without a label is a documentation error.
In each Python example, df = spark.table("<view>") or an equivalent inline spark.sql(...) call loads the canonical fixture. Each SQL example reads FROM <view> or uses an inline CTE — no separate CREATE TEMP VIEW step is shown.
Output representation
The output cells in every function table follow a uniform convention so readers can compare tabs at a glance without decoding byte strings.
Binary geometry ([E]WKB) — geometry returned as BINARY is elided with one token and a format annotation. Use (WKB binary) when the output carries no embedded SRID; (EWKB binary) when an SRID is embedded:
... (WKB binary)
... (EWKB binary)
The WKB bytes are always the canonical output. Decode with ST_GeomFromWKB, ST_GeomFromEWKB, or any ISO WKB reader.
MVT bytes — st_asmvt and st_asmvt_pyramid return Mapbox Vector Tile protobufs (BINARY). Output is shown as:
... (MVT binary)
WKT / EWKT strings — short strings are shown in full; longer strings are truncated with a type annotation:
POINT (13 42)
MULTIPOLYGON (((... (WKT)
CRS strings — short authority strings (EPSG:4326, ESRI:54008) are shown in full; long WKT CRS definitions are truncated:
PROJCS["British National Grid", ...] (CRS)
Cell width — output cells are capped at approximately 60 characters. A longer value is truncated with ... and annotated with its type.
Identical values — when every tab produces the same result (e.g. EPSG:4326 from st_crs), each tab shows that value with the same annotation. Genuine differences are called out in a labeled :::note.
CRS-family functions return BINARY
gbx_st_setcrs and gbx_st_transformcrs return BINARY (WKB or EWKB) in all input encodings and every level — a STRING (WKT/EWKT) input still yields BINARY output. Only gbx_st_crs returns STRING. The clickable pointer to the CRS contract: Coordinate Reference Systems.
Generators are table functions
gbx_st_asmvt_pyramid, gbx_st_triangulate, gbx_st_interpolateelevationbbox and gbx_st_interpolateelevationgeom return many rows per input. Call them in the FROM clause with LATERAL, at every implementation level:
spark.sql("SELECT t.* FROM <view>, LATERAL gbx_<fn>(...) t")
The Python entry takes the input DataFrame first and returns it joined with the generated rows, for example vectorx.functions.st_triangulate(df, "pts", "bl", 0.0, 0.0, "NONENCROACHING").
Vector tile output
Encode features into Mapbox Vector Tile (MVT) protobufs. Pair the per-tile MVT bytes with gbx_pmtiles_agg or the PMTiles writer to publish a vector pyramid as a single .pmtiles archive. The archive targets MapLibre, deck.gl, Mapbox GL JS, or Felt.
st_asmvt and st_asmvt_pyramid have the same names and output columns on every compute. Call register(spark) once, then use them:
from databricks.labs.gbx import register
from databricks.labs.gbx.vectorx import functions as vx
register(spark)
Options
st_asmvt takes a layer_name argument (plain string or Column). st_asmvt_pyramid additionally accepts:
| Argument | Default | Description |
|---|---|---|
layer_name | "layer" | MVT layer name embedded in the protobuf. |
extent | 4096 | MVT tile extent in pixels (MVT v2 standard). |
Compute compatibility
The Python level of both functions runs on every compute: Serverless, standard, dedicated (x86 and Graviton) and Lakeflow declarative pipelines. It needs only the env wheel (install), with no JVM access.
Native attribute typing
Every level encodes MVT feature attributes with native protobuf value types:
- Integer / Long → int64 value
- Float / Double → double value
- Boolean → bool value
- String (and anything else) → string value
This means downstream clients (MapLibre GL JS, Mapbox GL JS, deck.gl) receive numbers as numbers and booleans as booleans. This enables numeric data-driven styles, filter expressions, and arithmetic without a client-side parseFloat call.
st_asmvt
SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_asmvt(geom, attrs, layer_name) | BINARY |
| Python | vectorx.functions.st_asmvt(geom, attrs, layer_name) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | The feature geometry in tile coordinates: WKB, EWKB, WKT or EWKT. A NULL or empty geometry is skipped. | |
attrs | STRUCT | The feature's attributes, a struct of any fields. | |
layer_name | STRING | The name of the layer. |
Aggregator that encodes a group of features into a single MVT protobuf blob for one
(z, x, y) tile. Each groupBy(z, x, y).agg(vx.st_asmvt(...)) call produces the
MVT bytes for exactly one tile. Every level exposes the same grouped-aggregate API
and produces identical output bytes.
geom(BINARY) — Feature geometry (WKB, EWKB, WKT, or EWKT) in tile-local coordinates (pixel space,0..extent). Clip and project each feature to the tile coordinate system upstream before calling this aggregator.attrs(STRUCT<...>) — Per-feature attribute struct. Integer, float, boolean, and string fields are encoded with native MVT protobuf value types.layer_name(STRINGorstr) — MVT layer name. Pass a plain Python string or a Column.
Returns: BINARY — the MVT protobuf for one tile layer. Feed directly into
gbx_pmtiles_agg or the PMTiles Writer.
Composability: The BINARY output is the natural input to gbx_pmtiles_agg for packaging
multiple (z, x, y) tiles into a single PMTiles file.
- SQL
- Python
SELECT z, x, y, gbx_st_asmvt(geom_wkb, attrs, 'layer') AS mvt
FROM mvt_features
GROUP BY z, x, y;
+-+-+-+--------+
|z|x|y|mvt |
+-+-+-+--------+
|0|0|0|[binary]|
+-+-+-+--------+
... (MVT binary)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from pyspark.sql import functions as f
df = spark.table("mvt_features")
result = df.groupBy("z", "x", "y").agg(
vectorx_api.st_asmvt("geom_wkb", f.col("attrs"), "layer").alias("mvt")
)
row = result.first()
+---+---+---+---------+
| z| x| y| mvt|
+---+---+---+---------+
| 0| 0| 0|[binary] |
+---+---+---+---------+
... (MVT binary)
st_asmvt_array
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_asmvt_array(features, layer_name, [extent]) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_asmvt_array(features, layer_name, [extent]) | BINARY |
| Python | vectorx.functions.st_asmvt_array(features, layer_name, extent=None) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
features | array<struct<geom:binary,attrs:string>> | array<struct<geom:binary,attrs:string>> | The tile's features as an array of structs (geom, attrs), for example collect_list(struct(geom, to_json(attrs))) after a GROUP BY of the tile key. geom is WKB or EWKB in tile coordinates; attrs is a JSON object text, or NULL for none. A NULL element, or one with a NULL or empty geometry, is skipped. | |
layer_name | STRING | STRING | The name of the layer. | |
extent | INT | INT | 4096 | The tile coordinate extent. |
Encode one tile's features from an array of (geom, attrs) structs, for example collect_list(struct(geom, to_json(attrs))) after a GROUP BY of the tile key. It is the array form of gbx_st_asmvt, so a Unity Catalog query can build a layer. The attributes are JSON object text, because a struct of any fields has no Unity Catalog type. Geometry is WKB or EWKB in tile coordinates.
Returns: BINARY, the MVT protobuf of one layer. An array with no usable feature gives an empty layer, and a NULL array gives NULL. An attribute text that is not a JSON object raises with a Fix, and so does an extent below 1. An array of more than 64 MiB is refused with a Fix that names gbx_st_asmvt. Use gbx_st_asmvt_pyramid to cut a feature into the tiles it touches first.
- SQL
- Python
SELECT z, x, y,
gbx_st_asmvt_array(
collect_list(struct(geom_wkb AS geom, to_json(attrs) AS attrs)),
'layer'
) AS mvt
FROM mvt_features
GROUP BY z, x, y;
+-+-+-+--------+
|z|x|y|mvt |
+-+-+-+--------+
|0|0|0|[binary]|
+-+-+-+--------+
... (MVT binary)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from pyspark.sql import functions as f
df = spark.table("mvt_features")
features = f.collect_list(
f.struct(f.col("geom_wkb").alias("geom"), f.to_json("attrs").alias("attrs"))
)
result = df.groupBy("z", "x", "y").agg(
vectorx_api.st_asmvt_array(features, "layer").alias("mvt")
)
row = result.first()
+---+---+---+---------+
| z| x| y| mvt|
+---+---+---+---------+
| 0| 0| 0|[binary] |
+---+---+---+---------+
... (MVT binary)
st_asmvt_pyramid
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_asmvt_pyramid(geom, attrs, min_z, max_z, [layer_name], [extent]) | rows |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_asmvt_pyramid(geom, attrs, min_z, max_z, [layer_name], [extent]) | rows |
| Python | vectorx.functions.st_asmvt_pyramid(df, geom, attrs, min_z, max_z, layer_name=None, extent=None) | DataFrame |
Rows: z INT, x INT, y INT, mvt_bytes BINARY.
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The feature geometry in EPSG:4326: WKB, EWKB, WKT or EWKT. | |
attrs | STRUCT | STRING | The feature's attributes, as a struct; each field becomes an MVT property. On Unity Catalog it is a JSON object text, for example to_json(struct(name, id)). | |
min_z | INT | INT | The first zoom level, from 0. | |
max_z | INT | INT | The last zoom level, at least min_z and at most 20. | |
layer_name | STRING | STRING | 'layer' | The layer name written into each tile. |
extent | INT | INT | 4096 | The tile coordinate extent. |
Generator that explodes one input feature into one row per intersecting (z, x, y) tile
across a zoom range, with MVT bytes already encoded in each row. The per-tile clip and
coordinate transform happen inside the function — no upstream ST_Intersection is needed.
Input geometry must be in EPSG:4326 lon/lat. The function handles per-tile projection
internally. max_z ≤ 20; total tile count across the zoom range capped at 10⁶.
Call it with LATERAL:
FROM features, LATERAL gbx_st_asmvt_pyramid(geom_wkb, attrs, 0, 12, 'layer', 4096) t
-- Output columns: t.z, t.x, t.y, t.mvt_bytes
The function runs at the Python level.
Full pipeline — vector pyramid to PMTiles:
from databricks.labs.gbx import register
from databricks.labs.gbx.vectorx import functions as vx
from databricks.labs.gbx.pmtiles import functions as px
from pyspark.sql import functions as F
register(spark)
# Step 1: explode features → per-tile MVT rows (distributed; LATERAL in SQL)
tiles_df = spark.sql("""
SELECT t.*
FROM features,
LATERAL gbx_st_asmvt_pyramid(geom_wkb, struct(name, id), 0, 10, 'roads', 4096) t
""")
# Step 2: aggregate the per-tile MVT bytes → single PMTiles archive
pmt_bytes = (
tiles_df.agg(
px.pmtiles_agg(
F.col("mvt_bytes"), F.col("z"), F.col("x"), F.col("y"),
'{"name":"roads","attribution":"© My Data"}',
).alias("pmt")
)
.collect()[0]["pmt"]
)
with open("/tmp/roads.pmtiles", "wb") as fh:
fh.write(pmt_bytes)
For larger pyramids that exceed the Spark cell limit, use the PMTiles Writer
(pmtiles_gbx for the Python level) instead of pmtiles_agg.
- SQL
- Python
WITH feats AS (
SELECT unhex('010100000000000000000000000000000000000000') AS geom_wkb,
named_struct('name', 'origin', 'id', 1L) AS attrs
)
SELECT t.z, t.x, t.y, t.mvt_bytes
FROM feats, LATERAL gbx_st_asmvt_pyramid(geom_wkb, attrs, 0, 2, 'layer', 4096) t;
+-+-+-+---------+
|z|x|y|mvt_bytes|
+-+-+-+---------+
|0|0|0|[binary] |
|1|1|1|[binary] |
|2|2|2|[binary] |
+-+-+-+---------+
... (MVT binary — one row per intersecting tile across zoom levels 0–2)
result = spark.sql(f"""
WITH feats AS (
SELECT unhex('{_WKB_POINT_0_0}') AS geom_wkb,
named_struct('name', 'origin', 'id', 1L) AS attrs
)
SELECT t.*
FROM feats, LATERAL gbx_st_asmvt_pyramid(geom_wkb, attrs, 0, 2, 'layer', 4096) t
""")
rows = result.collect()
+---+---+---+-----------+
| z| x| y| mvt_bytes|
+---+---+---+-----------+
| 0| 0| 0| [binary] |
| 1| 1| 1| [binary] |
| 2| 2| 2| [binary] |
+---+---+---+-----------+
... (MVT binary — one row per intersecting tile across zoom levels 0–2)
Triangulation and elevation
These generators build a Delaunay triangulated irregular network (TIN) from Z-valued mass points and optional breaklines. They then either expose the triangles directly or sample the surface on a regular grid to produce elevation points. Useful for surface modeling, DTM/DEM derivation, and elevation sampling from survey point clouds. All three run at every level; both honor break lines.
Triangulation modes: constrained vs conforming
Each TIN function takes a trailing mode argument (default 'constrained'):
| Mode | Levels | Behavior |
|---|---|---|
constrained (default) | Every level | Constrained Delaunay triangulation. Every breakline segment is a forced edge, with no Steiner points — the output vertex set is exactly your mass points, after the merge and the snap, plus breakline vertices. A point exactly on a breakline splits it there. The algorithm is the same at every level. |
conforming | Every level | JTS conforming-Delaunay triangulation: the mesh may insert additional Steiner points along breakline segments to satisfy the Delaunay property near constraints. Produces a smoother mesh around dense breaklines at the cost of extra vertices. |
Both modes give the same vertices and triangles at every level, Unity Catalog included. The Python level reproduces JTS 1.20, the library the JVM level runs. Where several triangulations are equally valid, such as four points on one circle in a grid, every level picks the one JTS picks. Each triangle runs counter-clockwise from its lowest vertex, the least X then the least Y, so every level writes the same WKB bytes.
The env wheel runs this triangulation as a Rust port of JTS, with the same triangles. A regular grid of 1 million points triangulates in 13-20 seconds, faster than the JVM level. Without the Rust module, as with the plain wheel, the Python form takes minutes on a grid of 250,000 points. The Rust kernel for TIN triangulation has the measurements.
In the conforming mode, split_point_finder places the extra points. 'NONENCROACHING' projects the point that breaks the Delaunay rule onto the break line. 'MIDPOINT' splits the segment in half. An extra point takes the Z of its break line.
The conforming mode raises with a Fix: when it cannot fit the break lines, for example where two break lines cross. Split crossing break lines at the crossing, or use 'constrained'.
The constrained mode raises with a Fix: where break lines cross, or a line crosses itself. Split the break lines at the crossing. It also raises where JTS cannot locate a point among sites very close together. Merge them with a merge_tolerance above 0.
Merging points
Both modes merge close points first, whether or not anything snaps:
- The break line vertices come first, then the mass points, each in input order.
- A point within
merge_toleranceof a point kept before it merges into the nearest one. The first point kept wins, with its Z. - So a mass point near a break line vertex merges into the vertex.
- With
merge_tolerance0, only points with the same X and Y merge.
Snapping points to break lines
A snap_tolerance above 0 moves points onto break lines before either mode triangulates:
- A point within
snap_toleranceof a break line moves onto the nearest one. On a tie, the first line wins. - The point takes the line's Z there, interpolated along the segment. A 2D break line has Z 0.
- The point becomes a new vertex of the line, so no triangle has zero area.
- A point that lands within
merge_toleranceof a line vertex merges into it. Withmerge_tolerance0, only the same X and Y merges. - A point that does not snap but lies within
merge_toleranceof a new vertex merges into that vertex.
Call them with LATERAL (for example FROM t, LATERAL gbx_st_triangulate(...) t), or through the Python entry, which takes the DataFrame first.
st_interpolateelevationbbox
SQLUnity Catalog SQLPythonScala| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_interpolateelevationbbox(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, xmin, ymin, xmax, ymax, width_px, height_px, srid, [mode]) | rows |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_interpolateelevationbbox(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, xmin, ymin, xmax, ymax, width_px, height_px, srid, [mode]) | rows |
| Python | vectorx.functions.st_interpolateelevationbbox(df, points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, xmin, ymin, xmax, ymax, width_px, height_px, srid, mode=None) | DataFrame |
Rows: elevation_point BINARY.
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
points_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The mass points: WKB, EWKB, WKT or EWKT, as an array. A multi-point element adds each of its points; a point without Z has Z 0. | |
breaklines_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The break lines (line strings in any of the four formats), as an array; NULL or empty for none. Each segment becomes an edge of the triangulation. | |
merge_tolerance | DOUBLE | DOUBLE | Points within this distance in X and Y merge into the first one kept. A break line vertex wins over a mass point. 0 merges only identical points. | |
snap_tolerance | DOUBLE | DOUBLE | Points within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing. | |
split_point_finder | STRING | STRING | The rule that places the extra points of the conforming mode: 'NONENCROACHING' or 'MIDPOINT', in any case. The constrained mode does not use it. Any other word raises. | |
xmin | DOUBLE | DOUBLE | The west edge of the grid. | |
ymin | DOUBLE | DOUBLE | The south edge of the grid. | |
xmax | DOUBLE | DOUBLE | The east edge of the grid, above xmin. | |
ymax | DOUBLE | DOUBLE | The north edge of the grid, above ymin. | |
width_px | INT | INT | The number of grid columns, above 0. | |
height_px | INT | INT | The number of grid rows, above 0. | |
srid | INT | INT | The SRID of the output points; 0 for none. | |
mode | STRING | STRING | 'constrained' | 'constrained', the default, adds no points. 'conforming' adds points along the break lines, so the triangles meet the Delaunay rule there. Any other word raises. |
Builds a TIN from mass points and breaklines, then samples elevation on a regular pixel grid covering an explicit bounding box. Use this when you already know the output extent in absolute coordinates. For example, snap to a fixed tile extent or align with a raster grid.
The env wheel triangulates with a Rust kernel at the Python level. See Triangulation modes and the measurements.
Generator: Emits one row per in-hull grid cell (cells whose centers fall outside the TIN convex hull are dropped). The output schema column is elevation_point (BINARY WKB POINT Z). Use with SQL LATERAL to materialize the grid.
- SQL
- Python
SELECT t.elevation_point
FROM tin_survey, LATERAL gbx_st_interpolateelevationbbox(pts, bl, 0, 0, 'NONENCROACHING', 0, 0, 10, 10, 3, 3, 0, 'constrained') t
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 elevation grid, 9 rows)
result = spark.sql("""
SELECT t.elevation_point
FROM tin_survey, LATERAL gbx_st_interpolateelevationbbox(pts, bl, 0, 0, 'NONENCROACHING', 0, 0, 10, 10, 3, 3, 0, 'constrained') t
""")
rows = result.collect()
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 elevation grid, 9 rows)
st_interpolateelevationgeom
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_interpolateelevationgeom(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, grid_origin, grid_cols, grid_rows, cell_size_x, cell_size_y, [mode]) | rows |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_interpolateelevationgeom(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, grid_origin, grid_cols, grid_rows, cell_size_x, cell_size_y, [mode]) | rows |
| Python | vectorx.functions.st_interpolateelevationgeom(df, points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, grid_origin, grid_cols, grid_rows, cell_size_x, cell_size_y, mode=None) | DataFrame |
Rows: elevation_point BINARY.
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
points_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The mass points: WKB, EWKB, WKT or EWKT, as an array. A multi-point element adds each of its points; a point without Z has Z 0. | |
breaklines_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The break lines (line strings in any of the four formats), as an array; NULL or empty for none. Each segment becomes an edge of the triangulation. | |
merge_tolerance | DOUBLE | DOUBLE | Points within this distance in X and Y merge into the first one kept. A break line vertex wins over a mass point. 0 merges only identical points. | |
snap_tolerance | DOUBLE | DOUBLE | Points within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing. | |
split_point_finder | STRING | STRING | The rule that places the extra points of the conforming mode: 'NONENCROACHING' or 'MIDPOINT', in any case. The constrained mode does not use it. Any other word raises. | |
grid_origin | BINARY or STRING | GEOMETRY | The origin of the grid: a POINT in WKB, EWKB, WKT or EWKT. Its SRID is the SRID of the output. | |
grid_cols | INT | INT | The number of grid columns. | |
grid_rows | INT | INT | The number of grid rows. | |
cell_size_x | DOUBLE | DOUBLE | The cell width in the geometry's units; a positive value steps east. | |
cell_size_y | DOUBLE | DOUBLE | The cell height in the geometry's units; a negative value steps south. | |
mode | STRING | STRING | 'constrained' | 'constrained', the default, adds no points. 'conforming' adds points along the break lines, so the triangles meet the Delaunay rule there. Any other word raises. |
Builds a TIN from mass points and breaklines, then samples elevation on a regular grid anchored to a geometry origin with explicit cell sizes. Use this when the grid must be defined relative to a known point. For example, the grid origin comes from data (a survey control point), or different rows need different grid placements.
The env wheel triangulates with a Rust kernel at the Python level. See Triangulation modes and the measurements.
Generator: Emits one row per in-hull grid cell. The output schema column is elevation_point (BINARY WKB POINT Z). Use with SQL LATERAL to materialize the grid.
- SQL
- Python
SELECT t.elevation_point
FROM tin_survey, LATERAL gbx_st_interpolateelevationgeom(pts, bl, 0, 0, 'NONENCROACHING', unhex('010100000000000000000000000000000000002440'), 3, 3, 3, -3, 'constrained') t
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 origin-anchored grid, 9 rows)
result = spark.sql(f"""
SELECT t.elevation_point
FROM tin_survey, LATERAL gbx_st_interpolateelevationgeom(pts, bl, 0, 0, 'NONENCROACHING', unhex('{_WKB_POINT_0_10}'), 3, 3, 3, -3, 'constrained') t
""")
rows = result.collect()
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 origin-anchored grid, 9 rows)
st_triangulate
SQLUnity Catalog SQLPythonScala| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_triangulate(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, [mode]) | rows |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_triangulate(points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, [mode]) | rows |
| Python | vectorx.functions.st_triangulate(df, points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, mode=None) | DataFrame |
Rows: triangle BINARY.
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
points_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The mass points: WKB, EWKB, WKT or EWKT, as an array. A multi-point element adds each of its points; a point without Z has Z 0. | |
breaklines_array | ARRAY<BINARY> or ARRAY<STRING> | ARRAY<GEOMETRY> | The break lines (line strings in any of the four formats), as an array; NULL or empty for none. Each segment becomes an edge of the triangulation. | |
merge_tolerance | DOUBLE | DOUBLE | Points within this distance in X and Y merge into the first one kept. A break line vertex wins over a mass point. 0 merges only identical points. | |
snap_tolerance | DOUBLE | DOUBLE | Points within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing. | |
split_point_finder | STRING | STRING | The rule that places the extra points of the conforming mode: 'NONENCROACHING' or 'MIDPOINT', in any case. The constrained mode does not use it. Any other word raises. | |
mode | STRING | STRING | 'constrained' | 'constrained', the default, adds no points. 'conforming' adds points along the break lines, so the triangles meet the Delaunay rule there. Any other word raises. |
Builds a Delaunay TIN from mass-point geometries (with Z values) and optional breakline geometries, emitting one triangle polygon per row. Use this when you need the raw triangulation — e.g., to inspect mesh quality, clip triangles to an area of interest, or feed a custom sampler.
The env wheel triangulates with a Rust kernel at the Python level. See Triangulation modes and the measurements.
Generator: Emits one row per output triangle. Use with SQL LATERAL to materialize the triangles; the output schema column is triangle (BINARY WKB polygon).
- SQL
- Python
SELECT t.triangle
FROM tin_survey, LATERAL gbx_st_triangulate(pts, bl, 0, 0, 'NONENCROACHING', 'constrained') t
+--------+
|triangle|
+--------+
|[binary]|
|[binary]|
+--------+
... (WKB binary — 2 Delaunay triangle polygons)
result = spark.sql("""
SELECT t.triangle
FROM tin_survey, LATERAL gbx_st_triangulate(pts, bl, 0, 0, 'NONENCROACHING', 'constrained') t
""")
rows = result.collect()
+--------+
|triangle|
+--------+
|[binary]|
|[binary]|
+--------+
... (WKB binary — 2 Delaunay triangle polygons)
The 'constrained' mode (default) and the 'conforming' mode run at every level. The 'conforming' mode inserts Steiner points along breakline segments for a smoother mesh. The examples on all tabs use the default 'constrained' mode.
Coordinate reference systems
Read, stamp, and reproject a geometry's CRS by CRS string — an ESRI code, a WKT definition, or a PROJ4 string, not only an EPSG integer. These complement the product's built-in ST_SRID / ST_SetSRID / ST_Transform, which take an integer SRID. Use the built-ins when an EPSG code is all you need. Use these when the CRS can only be named as a string. See Coordinate Reference Systems for the SRID-vs-CRS-string model shared with RasterX.
All three have the same names and results at every level.
Shared contracts
Geometry input — every geometry argument accepts WKB, EWKB, WKT, and EWKT. WKB/WKT carry no SRID; EWKB/EWKT carry one.
SQL output is always BINARY. gbx_st_setcrs and gbx_st_transformcrs return BINARY (WKB/EWKB) whichever encoding the geometry argument arrived in — a STRING geometry input still yields BINARY. One function has one declared return type. An input-dependent return type cannot be used in a view or any fixed schema. WKB is how the rest of gbx_st_* and the built-in ST_* functions exchange geometries. To read a CRS back as text, wrap the result in gbx_st_crs. To hand it to a built-in, use ST_GeomFromEWKB for EWKB output (a stamped SRID) and ST_GeomFromWKB for plain WKB. gbx_st_crs returns STRING.
Errors are the exception, not the rule. These functions degrade rather than fail a whole column:
| Situation | Result |
|---|---|
| NULL geometry | NULL |
NULL target_crs | NULL |
Geometry has no resolvable source CRS (plain WKB/WKT, no source_crs) | input returned unchanged |
Embedded SRID is in no registry (e.g. 999999) | input returned unchanged |
source_crs cannot be parsed | input returned unchanged |
target_crs cannot be parsed | raises |
gbx_st_setcrs given a CRS with no integer authority code | raises |
Z coordinates. A geometry whose vertices all carry a finite Z keeps its Z. A genuinely 2D geometry stays 2D — no Z ordinate is invented. Some geometries have a Z on only some vertices, such as LINESTRING Z (15 51 5, 16 52). Such a geometry keeps the Z values it has, and the missing ones are NaN.
gbx_st_transformcrsreprojects X and Y of every vertex and carries the Z through the transformation for the vertices that have one. The vertices without a Z stayNaNin the result, and their X and Y are still correct.gbx_st_setcrskeeps the Z as-is, since stamping an SRID never moves coordinates.
A missing Z never gets a substitute value such as 0, because downstream code cannot tell it from a surveyed elevation. A Z that exists is never dropped. Every level behaves identically here, in every input encoding.
These apply in every input encoding and at every level — they are properties of the operations, not of how you pass the geometry.
- Reprojecting out and back is not bit-exact. A round trip such as
EPSG:4326→EPSG:32633→EPSG:4326returns11.000000000000002where it started at11— a floating-point artifact of the projection math, in the last decimal place or two. It does not compound meaningfully: further round trips stay in that same last-place range rather than drifting away. Compare reprojected coordinates with a tolerance, never for exact equality. st_setcrsrelabels without reprojecting, so stamping a CRS whose units do not match the coordinates leaves the geometry mislabelled. A laterst_transformcrsthen transforms from the wrong CRS. Projected metres taggedEPSG:4326come back asInfinitycoordinates on the Python level. The JVM level raises a projection error. Usest_transformcrswhen you want the coordinates moved.- Coordinates outside the target CRS's valid domain behave the same way — for example a latitude of
100, which does not exist. The Python level returnsInfinitycoordinates; the JVM level raises a projection error. Filter to the target CRS's area of use before reprojecting if your input may contain out-of-range coordinates. - M (measure) values are dropped. Every level carries X, Y and Z only. A
ZMgeometry comes back asZwith the measure gone. A geometry carrying M but no Z comes back plain 2D, with noZinvented. The product's own geometry type does persist M.
st_crs
SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_crs(geom) | STRING |
| Python | vectorx.functions.st_crs(geom) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | The geometry: WKB, EWKB, WKT or EWKT. |
Returns the canonical CRS string for the geometry's embedded SRID, or NULL.
Returns: STRING — the authority string ('EPSG:4326', 'ESRI:54008', …), or NULL for a plain WKB/WKT geometry with no embedded SRID, a NULL input, or an SRID in no known registry.
An SRID is classified against the authoritative PROJ registries, so an ESRI-range code comes back as ESRI:<n> rather than being mislabelled EPSG:<n>.
- SQL
- Python
SELECT gbx_st_crs(geom) AS crs FROM vector_geoms;
+---------+
|crs |
+---------+
|EPSG:4326|
+---------+
from databricks.labs.gbx.vectorx import functions as vx
df = spark.table("vector_geoms")
result = df.select(vx.st_crs("geom").alias("crs")).first()
+---------+
|crs |
+---------+
|EPSG:4326|
+---------+
st_setcrs
SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_setcrs(geom, crs) | BINARY |
| Python | vectorx.functions.st_setcrs(geom, crs) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | The geometry: WKB, EWKB, WKT or EWKT. | |
crs | STRING or INT | The CRS to stamp: EPSG:<code> or ESRI:<code>, or an integer. A CRS with no integer code is an error. |
Stamps a CRS on a geometry without reprojecting — it relabels, it does not move coordinates. The counterpart to the built-in ST_SetSRID, taking a CRS string instead of an integer.
Returns: BINARY — EWKB with the new SRID embedded. Coordinate values are preserved exactly, to the last decimal place — no reprojection and no rounding. (The output bytes are not identical to the input's: embedding the SRID is what makes it EWKB.)
Raises when crs has no integer authority code, because a geometry can store only an integer SRID. That covers:
-
authority-less definitions — a raw
PROJCS[...]WKT or a PROJ4 string such as'+proj=utm +zone=33 +datum=WGS84'. PROJ's fuzzy matcher would pair that PROJ4 string withEPSG:32633at partial confidence, but a geometry SRID is an exact identity claim. A guess is never silently written into one. Usegbx_st_transformcrsif you want the coordinates in that CRS.This distinction is not academic: a PROJ4 string that resembles a registry CRS is not necessarily equivalent to it. One that omits a datum shift (
+towgs84=0,0,0,0,0,0,0) can place coordinates hundreds of metres from the EPSG code it superficially matches. GeoBrix treats such a definition as its own CRS throughout — including when selecting the transformation used to reproject — rather than silently substituting the near-match. If you want the registry CRS, name it explicitly ('EPSG:28992'). -
non-numeric authority codes —
'OGC:CRS84','IGNF:LAMB93': real, resolvable CRSes whose code simply is not an integer.
- SQL
- Python
SELECT gbx_st_setcrs(geom, 'EPSG:4326') AS stamped FROM vector_geoms;
+--------+
|stamped |
+--------+
|[binary]|
+--------+
... (EWKB binary — coordinates preserved, SRID=4326 embedded)
from databricks.labs.gbx.vectorx import functions as vx
df = spark.table("vector_geoms")
result = df.select(vx.st_setcrs("geom", "EPSG:4326").alias("stamped")).first()
+---------+
|stamped |
+---------+
|[binary] |
+---------+
... (EWKB binary — coordinates preserved, SRID=4326 embedded)
st_transformcrs
SQLPythonScala| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_transformcrs(geom, target_crs, [source_crs]) | BINARY |
| Python | vectorx.functions.st_transformcrs(geom, target_crs, source_crs=None) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | The geometry: WKB, EWKB, WKT or EWKT. | |
target_crs | STRING or INT | The target CRS: EPSG:<code> or ESRI:<code>, an integer, WKT, PROJJSON or PROJ4. | |
source_crs | STRING or INT | NULL | The CRS of a geometry that carries no SRID; ignored when it does. |
Reprojects a geometry's coordinates into target_crs. The counterpart to the built-in ST_Transform, taking a CRS string instead of an integer. An ESRI code, a WKT definition or a PROJ4 string can be the target.
Returns: BINARY — the reprojected geometry.
Which SRID comes out follows the target:
target_crs | Example | Output |
|---|---|---|
| Has an integer authority code | 'EPSG:32633', 'ESRI:54008', 32633 | EWKB with that SRID stamped — a plain input is upgraded to carry one |
| Has no integer authority code | raw PROJCS[...] WKT, '+proj=utm +zone=33 …', 'OGC:CRS84' | plain WKB: coordinates reprojected, and the now-stale source SRID cleared — leaving it would label the geometry with a CRS it is no longer in |
Source CRS resolution order: the geometry's embedded SRID first, then source_crs, and if neither resolves the geometry is returned unchanged.
When the output is EWKB (the SRID travels with the geometry), convert it with the built-in ST_GeomFromEWKB, not ST_GeomFromWKB. Use ST_GeomFromWKB only for the plain WKB that an authority-less target returns.
- SQL
- Python
SELECT gbx_st_transformcrs(geom, 'EPSG:32633') AS utm33n FROM vector_geoms;
+--------+
|utm33n |
+--------+
|[binary]|
+--------+
... (EWKB binary — POINT(13, 42) reprojected from EPSG:4326 to EPSG:32633)
from databricks.labs.gbx.vectorx import functions as vx
df = spark.table("vector_geoms")
result = df.select(vx.st_transformcrs("geom", "EPSG:32633").alias("utm33n")).first()
+--------+
|utm33n |
+--------+
|[binary]|
+--------+
... (EWKB binary — POINT(13, 42) reprojected from EPSG:4326 to EPSG:32633)
Geometry validity
Distributed shapely helpers — shapely/GEOS geometry operations running as Python UDFs across your Spark cluster — for diagnosing and repairing OGC-invalid geometries. These functions run at the Python level, on every compute. See Geometry Validity for the full conditional-repair workflow and invalidity reason codes.
st_makevalid
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_makevalid(geom, [level]) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_makevalid(geom, [level]) | GEOMETRY |
| Python | vectorx.functions.st_makevalid(geom, level=None) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
level | STRING | STRING | 'linework' | The repair strategy: 'linework', 'structure' or 'ogc' (no ring-orientation fix). |
Repairs a geometry to OGC-SFS validity. The default level='linework' nodes self-intersections and applies orient_polygons so output passes the product's stricter ST_IsValid (topology + orientation). level='structure' uses a more conservative overlay method. level='ogc' applies OGC-only repair without orientation normalization.
Returns: BINARY — WKB (or EWKB if input carried a SRID). The original CRS is preserved. Returns NULL for null or unparseable input.
See Geometry Validity.
Since v0.5.0- SQL
- Python
SELECT gbx_st_makevalid('POLYGON((0 0,1 1,1 0,0 1,0 0))') AS clean
+--------+
|clean |
+--------+
|[binary]|
+--------+
... (WKB binary — repaired geometry; bowtie becomes a valid multi-polygon)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
bowtie = from_wkt("POLYGON((0 0,1 1,1 0,0 1,0 0))")
df = spark.createDataFrame([(to_wkb(bowtie),)], ["geom"])
+--------+
|clean |
+--------+
|[binary]|
+--------+
... (WKB binary — repaired geometry; bowtie becomes a valid multi-polygon)
st_explainvalidity
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_explainvalidity(geom) | STRING |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_explainvalidity(geom) | STRING |
| Python | vectorx.functions.st_explainvalidity(geom) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. |
Diagnoses geometry validity and returns a JSON string with four fields. valid is a boolean, reason the GEOS reason, code a stable integer for the violation class, and location the violation site as a POINT(x y) WKT string. code and location are null when GEOS does not provide them. Use ST_IsValid as a cheap boolean gate and call gbx_st_explainvalidity only on flagged rows.
Returns: STRING — JSON {"valid": ..., "reason": ..., "code": ..., "location": ...}. Returns NULL for null or unparseable input.
The Unity Catalog form takes a GEOMETRY, so the warehouse's WKT parser runs first. It refuses some invalid text, such as a ring with too few points, with WKT_PARSE_ERROR. The session function returns {"valid": false, "code": 1} for the same text. Run the session function or the Python API on text the parser refuses.
See Geometry Validity.
Since v0.5.0- SQL
- Python
SELECT gbx_st_explainvalidity('POLYGON((0 0,1 1,1 0,0 1,0 0))') AS detail
+--------------------------------------------------------------------+
|detail |
+--------------------------------------------------------------------+
|{"valid": false, "reason": "Self-intersection[0.5 0.5]", "code": 10,|
+--------------------------------------------------------------------+
... (JSON string — {valid, reason, code, location} for SFS validity diagnosis)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
bowtie = from_wkt("POLYGON((0 0,1 1,1 0,0 1,0 0))")
df = spark.createDataFrame([(to_wkb(bowtie),)], ["geom"])
+----------------------------------------------------------------------+
|detail |
+----------------------------------------------------------------------+
|{"valid": false, "reason": "Self-intersection[0.5 0.5]", "code": 10, |
+----------------------------------------------------------------------+
... (JSON string — {valid, reason, code, location} for SFS validity diagnosis)
Coverage validity
Distributed shapely helpers validate and simplify polygon coverages. A coverage is a set of polygons that share edges and together partition a region. The helpers are grouped-aggregate SQL UDFs and a Python DataFrame helper. These functions run at the Python level, on every compute. See Coverage Validity for the gap_width semantics, scale-ceiling notes, and the comparison with per-geometry validity.
st_coverageisvalid
SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_coverageisvalid(geom, [gap_width]) | BOOLEAN |
| Python | vectorx.functions.st_coverageisvalid(geom, gap_width=None) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | A polygon of the coverage: WKB, EWKB, WKT or EWKT. A NULL or empty one is skipped. | |
gap_width | DOUBLE | 0.0 | The widest gap between polygons that still counts as a gap, in the CRS units. |
Returns true when the polygon group forms a valid coverage — no overlaps; no gaps thinner than gap_width. Use with GROUP BY to identify which coverage groups pass.
Returns: BOOLEAN. NULL when the group is empty.
See Coverage Validity.
Since v0.5.0- SQL
- Python
SELECT cov_id, gbx_st_coverageisvalid(geom, 0.0) AS is_valid
FROM coverage_parcels
GROUP BY cov_id
+------+--------+
|cov_id|is_valid|
+------+--------+
|1 |true |
+------+--------+
... (BOOLEAN — true when the polygon group has no overlaps and no slivers narrower than gap_width)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from shapely import to_wkb
from shapely.geometry import box
left = box(0.0, 0.0, 5.0, 5.0)
right = box(5.0, 0.0, 10.0, 5.0)
df = spark.createDataFrame(
[
(1, to_wkb(left)),
(1, to_wkb(right)),
],
["cov_id", "geom"],
)
result = df.groupBy("cov_id").agg(
vectorx_api.st_coverageisvalid("geom", 0.0).alias("is_valid")
)
+------+--------+
|cov_id|is_valid|
+------+--------+
| 1| true|
+------+--------+
... (BOOLEAN — true: the two adjacent squares share a clean edge with no overlap)
st_coverageinvalidedges
SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_coverageinvalidedges(geom, [gap_width]) | BINARY |
| Python | vectorx.functions.st_coverageinvalidedges(geom, gap_width=None) | Column |
| Parameter | SQL type | Default | Description |
|---|---|---|---|
geom | BINARY or STRING | A polygon of the coverage: WKB, EWKB, WKT or EWKT. A NULL or empty one is skipped. | |
gap_width | DOUBLE | 0.0 | The widest gap between polygons that still counts as a gap, in the CRS units. |
Returns the union of the boundary segments that violate the coverage as BINARY (WKB/EWKB). Empty geometry when the coverage is clean; non-empty when overlaps or slivers exist. Use the output geometry to highlight problem zones on a map.
Returns: BINARY — WKB/EWKB union of invalid edge segments. Empty geometry when clean. NULL when the group is empty.
See Coverage Validity.
Since v0.5.0- SQL
- Python
SELECT cov_id, gbx_st_coverageinvalidedges(geom, 0.0) AS bad_edges
FROM coverage_overlap
GROUP BY cov_id
+------+---------+
|cov_id|bad_edges|
+------+---------+
|1 |[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; empty geometry when the coverage is clean)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from shapely import to_wkb
from shapely.geometry import box
poly1 = box(0.0, 0.0, 6.0, 6.0)
poly2 = box(4.0, 4.0, 10.0, 10.0)
df = spark.createDataFrame(
[
(1, to_wkb(poly1)),
(1, to_wkb(poly2)),
],
["cov_id", "geom"],
)
result = df.groupBy("cov_id").agg(
vectorx_api.st_coverageinvalidedges("geom", 0.0).alias("bad_edges")
)
+------+---------+
|cov_id|bad_edges|
+------+---------+
| 1|[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; non-empty because the two squares overlap)
st_coverageisvalid_array
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_coverageisvalid_array(geoms, [gap_width]) | BOOLEAN |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_coverageisvalid_array(geoms, [gap_width]) | BOOLEAN |
| Python | vectorx.functions.st_coverageisvalid_array(geoms, gap_width=None) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geoms | array<binary> | array<binary> | The polygons of the coverage as an array of WKB or EWKB, for example collect_list(st_asewkb(geom)) after a GROUP BY. A NULL or empty element is skipped; an element that is no geometry gives NULL. | |
gap_width | DOUBLE | DOUBLE | 0.0 | The widest gap between polygons that still counts as a gap, in the CRS units. A negative or non-finite width raises. |
Say whether an array of polygons is a valid coverage, for example collect_list(st_asewkb(geom)) after a GROUP BY. It is the array form of gbx_st_coverageisvalid, so a Unity Catalog query can check a coverage. A NULL or empty member is skipped, and a member that is no geometry gives NULL. A negative or non-finite gap_width raises with a Fix.
Returns: BOOLEAN. NULL for a NULL array or one with no usable polygon. An array of more than 64 MiB is refused with a Fix that names gbx_st_coverageisvalid.
- SQL
- Python
SELECT cov_id, gbx_st_coverageisvalid_array(collect_list(geom_wkb), 0.0) AS is_valid
FROM coverage_parcels
GROUP BY cov_id
+------+--------+
|cov_id|is_valid|
+------+--------+
|1 |true |
+------+--------+
... (BOOLEAN — true when the polygons have no overlap and no gap narrower than gap_width)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from pyspark.sql import functions as f
from shapely import to_wkb
from shapely.geometry import box
df = spark.createDataFrame(
[
(1, bytearray(to_wkb(box(0.0, 0.0, 5.0, 5.0)))),
(1, bytearray(to_wkb(box(5.0, 0.0, 10.0, 5.0)))),
],
"cov_id INT, geom BINARY",
)
result = df.groupBy("cov_id").agg(
vectorx_api.st_coverageisvalid_array(f.collect_list("geom"), 0.0).alias(
"is_valid"
)
)
+------+--------+
|cov_id|is_valid|
+------+--------+
| 1| true|
+------+--------+
... (BOOLEAN — true: the two adjacent squares share a clean edge with no overlap)
st_coverageinvalidedges_array
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_coverageinvalidedges_array(geoms, [gap_width]) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_coverageinvalidedges_array(geoms, [gap_width]) | BINARY |
| Python | vectorx.functions.st_coverageinvalidedges_array(geoms, gap_width=None) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geoms | array<binary> | array<binary> | The polygons of the coverage as an array of WKB or EWKB, for example collect_list(st_asewkb(geom)) after a GROUP BY. A NULL or empty element is skipped; an element that is no geometry gives NULL. | |
gap_width | DOUBLE | DOUBLE | 0.0 | The widest gap between polygons that still counts as a gap, in the CRS units. A negative or non-finite width raises. |
Give the invalid edges of an array of polygons that should form a coverage, for example collect_list(st_asewkb(geom)) after a GROUP BY. It is the array form of gbx_st_coverageinvalidedges. Pass EWKB members to keep their SRID on the edges.
Returns: BINARY, the union of the invalid edges, empty when the coverage is valid. NULL for a NULL array or one with no usable polygon. An array of more than 64 MiB is refused with a Fix that names gbx_st_coverageinvalidedges.
- SQL
- Python
SELECT cov_id, gbx_st_coverageinvalidedges_array(collect_list(geom_wkb), 0.0) AS bad_edges
FROM coverage_overlap
GROUP BY cov_id
+------+---------+
|cov_id|bad_edges|
+------+---------+
|1 |[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; empty geometry when the coverage is clean)
from databricks.labs.gbx.vectorx import functions as vectorx_api
from pyspark.sql import functions as f
from shapely import to_wkb
from shapely.geometry import box
df = spark.createDataFrame(
[
(1, bytearray(to_wkb(box(0.0, 0.0, 6.0, 6.0)))),
(1, bytearray(to_wkb(box(4.0, 4.0, 10.0, 10.0)))),
],
"cov_id INT, geom BINARY",
)
result = df.groupBy("cov_id").agg(
vectorx_api.st_coverageinvalidedges_array(f.collect_list("geom"), 0.0).alias(
"bad_edges"
)
)
+------+---------+
|cov_id|bad_edges|
+------+---------+
| 1|[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; non-empty because the two squares overlap)
coverage_simplify
Python-API only — no SQL form. Topology-preserving simplification of a whole coverage. Unlike per-row simplification (gbx_st_simplifypreservetopology), this helper simplifies the coverage as a unit so shared edges stay aligned in both adjacent polygons after simplification.
Signature: coverage_simplify(df, group_col, geom_col, tolerance, simplify_boundary=True, out_col="geom_simplified")
Parameters:
df— Input Spark DataFrame.group_col— Column name defining coverage groups (e.g."admin_level").geom_col— Column name of the geometry (WKB/EWKB/WKT/EWKT).tolerance(float) — Simplification tolerance in coordinate units.simplify_boundary(bool, defaultTrue) — Whether to simplify the outer boundary.out_col(str, default"geom_simplified") — Output column name.
Returns: A Spark DataFrame — same rows, all original columns, plus out_col (BINARY). N→N.
from databricks.labs.gbx import register
from databricks.labs.gbx.vectorx.helpers import coverage_simplify
register(spark)
simplified_df = coverage_simplify(
df, group_col="admin_level", geom_col="geom_wkb", tolerance=50.0
)
See Coverage Validity.
Geometry cleaning
Distributed shapely helpers — shapely/GEOS operations running as Python UDFs — for improving the quality of already-valid geometries. If your geometry is invalid, repair it first with gbx_st_makevalid, then clean it. These functions run at the Python level, on every compute. See Geometry Cleaning for usage guidance and the comparison with the product's built-in simplify.
st_simplifypreservetopology
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_simplifypreservetopology(geom, tolerance) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_simplifypreservetopology(geom, tolerance) | GEOMETRY |
| Python | vectorx.functions.st_simplifypreservetopology(geom, tolerance) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
tolerance | DOUBLE | DOUBLE | The distance below which a vertex is dropped. |
Simplifies a geometry using the Douglas-Peucker algorithm with topology preservation (preserve_topology=True). Vertices that deviate less than tolerance from the simplified line are dropped. The output keeps the topological class of the input and stays valid. Use this instead of the product's st_simplify when ring connectivity must be maintained.
Returns: BINARY — WKB (or EWKB if input carried a SRID). The original CRS is preserved. Returns NULL for null or unparseable input.
See Geometry Cleaning.
Since v0.5.0- SQL
- Python
SELECT gbx_st_simplifypreservetopology('POLYGON((0 0,0 5,0.001 8,0 10,10 10,10 0,0 0))', 1.0) AS simplified
+----------+
|simplified|
+----------+
|[binary] |
+----------+
... (WKB binary — simplified polygon with near-collinear vertex removed, topology preserved)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
from pyspark.sql import functions as f
geom = from_wkt("POLYGON((0 0,0 5,0.001 8,0 10,10 10,10 0,0 0))")
df = spark.createDataFrame([(to_wkb(geom),)], ["geom"])
return df.select(
vx.st_simplifypreservetopology("geom", f.lit(1.0)).alias("simplified")
).first()["simplified"]
+----------+
|simplified|
+----------+
|[binary] |
+----------+
... (WKB binary — simplified polygon with near-collinear vertex removed, topology preserved)
st_removerepeatedpoints
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_removerepeatedpoints(geom, [tolerance]) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_removerepeatedpoints(geom, [tolerance]) | GEOMETRY |
| Python | vectorx.functions.st_removerepeatedpoints(geom, tolerance=None) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
tolerance | DOUBLE | DOUBLE | 0.0 | Vertices closer than this to the one before are dropped; 0 drops exact repeats only. |
Removes consecutive duplicate or near-duplicate vertices from a geometry. With the default tolerance=0.0, only exact duplicate consecutive coordinate pairs are removed. A positive tolerance collapses vertices within that distance of their predecessor into a single representative vertex.
Returns: BINARY — WKB (or EWKB if input carried a SRID). The original CRS is preserved. Returns NULL for null or unparseable input.
See Geometry Cleaning.
Since v0.5.0- SQL
- Python
SELECT gbx_st_removerepeatedpoints('LINESTRING(0 0,0 0,1 1,1 1,2 2)') AS deduped
+--------+
|deduped |
+--------+
|[binary]|
+--------+
... (WKB binary — linestring with duplicate consecutive vertices removed: LINESTRING(0 0,1 1,2 2))
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
geom = from_wkt("LINESTRING(0 0,0 0,1 1,1 1,2 2)")
df = spark.createDataFrame([(to_wkb(geom),)], ["geom"])
return df.select(
vx.st_removerepeatedpoints("geom").alias("deduped")
).first()["deduped"]
+--------+
|deduped |
+--------+
|[binary]|
+--------+
... (WKB binary — linestring with duplicate consecutive vertices removed: LINESTRING(0 0,1 1,2 2))
st_reduceprecision
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_reduceprecision(geom, grid_size) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_reduceprecision(geom, grid_size) | GEOMETRY |
| Python | vectorx.functions.st_reduceprecision(geom, grid_size) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
grid_size | DOUBLE | DOUBLE | The grid cell size; coordinates snap to its multiples. |
Snaps coordinates to a precision grid of size grid_size, rounding each coordinate to the nearest multiple of grid_size. Useful for eliminating floating-point noise, aligning data from different sources, or reducing coordinate storage size. Uses GEOS set_precision with mode="valid_output" so the output remains valid even if snapping would otherwise collapse a ring.
Returns: BINARY — WKB (or EWKB if input carried a SRID). The original CRS is preserved. Returns NULL for null or unparseable input.
See Geometry Cleaning.
Since v0.5.0- SQL
- Python
SELECT gbx_st_reduceprecision('POINT(1.234 5.678)', 1.0) AS snapped
+--------+
|snapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(1.0, 6.0): coordinates snapped to nearest 1.0 grid lines)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
from pyspark.sql import functions as f
geom = from_wkt("POINT(1.234 5.678)")
df = spark.createDataFrame([(to_wkb(geom),)], ["geom"])
return df.select(
vx.st_reduceprecision("geom", f.lit(1.0)).alias("snapped")
).first()["snapped"]
+--------+
|snapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(1.0, 6.0): coordinates snapped to nearest 1.0 grid lines)
st_node
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_node(geom) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_node(geom) | GEOMETRY |
| Python | vectorx.functions.st_node(geom) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. |
Nodes a geometry's linework by splitting at all self-intersections and pairwise intersections. The result is a MultiLineString (or LineString) where every segment endpoint is a valid node — no two segments cross without sharing an explicit endpoint. Noding is typically a prerequisite for polygonization, planar graph analysis, or building topologically clean networks from raw linework.
Returns: BINARY — WKB (or EWKB if input carried a SRID). The original CRS is preserved. Returns NULL for null or unparseable input.
See Geometry Cleaning.
Since v0.5.0- SQL
- Python
SELECT gbx_st_node('LINESTRING(0 0,10 10,0 10,10 0)') AS noded
+--------+
|noded |
+--------+
|[binary]|
+--------+
... (WKB binary — MultiLineString: figure-eight split into clean segments at the self-intersection)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
geom = from_wkt("LINESTRING(0 0,10 10,0 10,10 0)")
df = spark.createDataFrame([(to_wkb(geom),)], ["geom"])
+--------+
|noded |
+--------+
|[binary]|
+--------+
... (WKB binary — MultiLineString: figure-eight split into clean segments at the self-intersection)
st_snap
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_snap(geom, reference, tolerance) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_snap(geom, reference, tolerance) | GEOMETRY |
| Python | vectorx.functions.st_snap(geom, reference, tolerance) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
reference | BINARY or STRING | GEOMETRY | The geometry to snap onto: WKB, EWKB, WKT or EWKT. | |
tolerance | DOUBLE | DOUBLE | The distance within which a vertex moves onto the reference. |
Snaps geom's vertices onto reference where within tolerance. Any vertex in geom that lies within tolerance distance of a vertex or edge in reference is moved onto that nearest point. Useful for aligning features from different sources that should share boundaries but don't quite meet due to digitizing differences or floating-point noise.
Complements the product's ST_ClosestPoint (exact nearest point, no tolerance gate).
Returns: BINARY — WKB (or EWKB if input carried a SRID). The SRID of geom is preserved. Returns NULL if either input is null or unparseable.
See Geometry Cleaning.
Since v0.5.0- SQL
- Python
SELECT gbx_st_snap('LINESTRING(0 0.4,10 0.4)', 'LINESTRING(0 0,10 0)', 0.5) AS snapped
+--------+
|snapped |
+--------+
|[binary]|
+--------+
... (WKB binary — linestring with near-miss vertices snapped onto the reference at y=0)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import from_wkt, to_wkb
from pyspark.sql import functions as f
geom = from_wkt("LINESTRING(0 0.4,10 0.4)")
ref = from_wkt("LINESTRING(0 0,10 0)")
df = spark.createDataFrame([(to_wkb(geom), to_wkb(ref))], ["geom", "ref"])
return df.select(
vx.st_snap("geom", "ref", f.lit(0.5)).alias("snapped")
).first()["snapped"]
+--------+
|snapped |
+--------+
|[binary]|
+--------+
... (WKB binary — linestring with near-miss vertices snapped onto the reference at y=0)
Antimeridian handling
These three functions are distributed shapely helpers — shapely/GEOS geometry operations running as Python UDFs across your Spark cluster. They run at the Python level, on every compute. See Antimeridian for the full composition pattern.
st_shiftlongitude
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_shiftlongitude(geom) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_shiftlongitude(geom) | GEOMETRY |
| Python | vectorx.functions.st_shiftlongitude(geom) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. |
Shifts all longitude (x) coordinates of a geometry from [-180, 180] space into [0, 360] space by adding 360 to any negative x value. Use this as the first step when normalizing a geometry that crosses the 180° antimeridian. After the shift, the crossing polygon is contiguous around x=180 and splits cleanly there.
Returns: BINARY — WKB with all negative x coordinates shifted by +360.
See Antimeridian.
Since v0.5.0- SQL
- Python
SELECT gbx_st_shiftlongitude('POLYGON((-170 -10, -150 -10, -150 10, -170 10, -170 -10))') AS shifted
+--------+
|shifted |
+--------+
|[binary]|
+--------+
... (WKB binary — polygon in [0,360] longitude space, x coordinates shifted to [190,210])
from databricks.labs.gbx.vectorx import functions as vx
from shapely import to_wkb
from shapely.geometry import Point
df = spark.createDataFrame([(to_wkb(Point(-170.0, 10.0)),)], ["geom"])
+--------+
|shifted |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(190.0, 10.0): x shifted from -170 to 190)
st_wrapx
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_wrapx(geom, wrap_x_origin, wrap_direction) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_wrapx(geom, wrap_x_origin, wrap_direction) | GEOMETRY |
| Python | vectorx.functions.st_wrapx(geom, wrap_x_origin, wrap_direction) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | BINARY or STRING | GEOMETRY | The geometry: WKB, EWKB, WKT or EWKT. | |
wrap_x_origin | DOUBLE | DOUBLE | The x value the wrap starts from. | |
wrap_direction | DOUBLE | DOUBLE | The amount added to the coordinates that qualify: negative moves those at or east of the origin, positive those at or west of it. |
Wraps x coordinates that exceed a threshold back by a fixed offset. The primary use is the reverse of gbx_st_shiftlongitude: after splitting at x=180, apply gbx_st_wrapx(geom, 180, -360) to the eastern pieces to move them from [180, 360] back into [-180, 0]. Apply only to the pieces where ST_XMax(piece) > 180 — wrapping the western piece's shared 180° edge would produce a malformed geometry.
Returns: BINARY — WKB with qualifying x coordinates shifted by wrap_direction.
See Antimeridian.
Since v0.5.0- SQL
- Python
SELECT gbx_st_wrapx('POINT(190 10)', 180, -360) AS wrapped
+--------+
|wrapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(-170, 10): x=190 wrapped back by -360)
from pyspark.sql import functions as f
from databricks.labs.gbx.vectorx import functions as vx
from shapely import to_wkb
from shapely.geometry import Point
df = spark.createDataFrame([(to_wkb(Point(190.0, 10.0)),)], ["geom"])
return df.select(
vx.st_wrapx("geom", f.lit(180.0), f.lit(-360.0)).alias("wrapped")
).first()["wrapped"]
+--------+
|wrapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(-170.0, 10.0): x=190 wrapped back by -360)
st_split
SQLUnity Catalog SQLPython| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_split(input_geom, blade_geom) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_split(input_geom, blade_geom) | GEOMETRY |
| Python | vectorx.functions.st_split(input_geom, blade_geom) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
input_geom | BINARY or STRING | GEOMETRY | The geometry to split: WKB, EWKB, WKT or EWKT. | |
blade_geom | BINARY or STRING | GEOMETRY | The geometry to split by: WKB, EWKB, WKT or EWKT. |
Splits a geometry by a blade geometry, returning a GEOMETRYCOLLECTION containing all resulting pieces. The primary use is cutting an antimeridian-crossing polygon at the 180° meridian: pass the polygon (already shifted into [0, 360] space by gbx_st_shiftlongitude) and the blade 'LINESTRING(180 -90, 180 90)'.
Returns: BINARY — WKB GEOMETRYCOLLECTION of the resulting pieces.
See Antimeridian.
Since v0.5.0- SQL
- Python
SELECT gbx_st_split('POLYGON((170 -10, 190 -10, 190 10, 170 10, 170 -10))', 'LINESTRING(180 -90, 180 90)') AS pieces
+--------+
|pieces |
+--------+
|[binary]|
+--------+
... (WKB binary — GeometryCollection with 2 polygon pieces split at x=180)
from databricks.labs.gbx.vectorx import functions as vx
from shapely import to_wkb
from shapely.geometry import LineString, Polygon
input_poly = Polygon([(170, -10), (190, -10), (190, 10), (170, 10), (170, -10)])
blade_line = LineString([(180, -90), (180, 90)])
df = spark.createDataFrame(
[(to_wkb(input_poly), to_wkb(blade_line))],
["input_geom", "blade_geom"],
)
return df.select(
vx.st_split("input_geom", "blade_geom").alias("pieces")
).first()["pieces"]
+--------+
|pieces |
+--------+
|[binary]|
+--------+
... (WKB binary — GeometryCollection with 2 polygon pieces split at x=180)
Legacy Mosaic conversion
st_legacyaswkb
SQLUnity Catalog SQLPythonScala| Surface | Call | Returns |
|---|---|---|
| SQL (session) | gbx_st_legacyaswkb(geom) | BINARY |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_st_legacyaswkb(geom) | GEOMETRY |
| Python | vectorx.functions.st_legacyaswkb(geom) | Column |
| Parameter | SQL type | UC type | Default | Description |
|---|---|---|---|---|
geom | struct<typeId:int,srid:int,boundaries:array<array<array<double>>>,holes:array<array<array<array<double>>>>> | struct<typeId:int,srid:int,boundaries:array<array<array<double>>>,holes:array<array<array<array<double>>>>> | The legacy Mosaic geometry struct: typeId, srid, boundaries and holes. |
Migrates a legacy DBLabs Mosaic geometry value to standard Well-Known Binary (WKB). Pass the raw legacy geometry column through st_legacyaswkb to get a WKB binary that every downstream ST_* function accepts. This is the first step when moving a Mosaic-era table onto the product's native GEOMETRY and GEOGRAPHY types.
Migration notes:
- Z values are preserved. 3D legacy geometries round-trip through
st_legacyaswkbwith their Z coordinate intact. - Polygon holes (interior rings) are preserved.
- SRID is applied separately at ingestion. The output is plain WKB and carries no SRID; assign the CRS when you read it back, e.g.
ST_GeomFromWKB(gbx_st_legacyaswkb(geom_legacy), 27700). - M (measure) values are out of scope for this conversion.
- SQL
- Python
SELECT gbx_st_legacyaswkb(geom_legacy) AS wkb FROM legacy_geoms;
+--------+
|wkb |
+--------+
|[binary]|
+--------+
... (WKB binary)
from databricks.labs.gbx.vectorx import functions as vx
df = spark.table("legacy_geoms")
result = df.select(vx.st_legacyaswkb("geom_legacy").alias("wkb")).first()
+--------+
|wkb |
+--------+
|[binary]|
+--------+
... (WKB binary)
Next Steps
- Quick Start — Register and use VectorX with the legacy example
- Geometry Validity — diagnose and repair OGC-invalid geometries with
gbx_st_explainvalidityandgbx_st_makevalid - Coverage Validity — validate and simplify polygon coverages with
gbx_st_coverageisvalid,gbx_st_coverageinvalidedges, andcoverage_simplify - Geometry Cleaning — topology-safe simplification, vertex deduplication, precision reduction, linework noding, and feature snapping
- Antimeridian — antimeridian composition pattern with full example
- Surfaces & Levels — how GeoBrix picks the implementation
- PMTiles Function Reference — Aggregate MVT tiles into a single
.pmtilesarchive - PMTiles Writer — DataSource for streaming large pyramids to a single
.pmtilesfile - Helios notebooks — worked end-to-end example:
gbx_st_asmvt+gbx_st_asmvt_pyramidencode San Francisco building footprints into a PMTiles archive (NB01). - Benchmarking — timing method
- API Overview — All GeoBrix APIs