Skip to main content

VectorX Function Reference

Scala tags

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_asmvt aggregator and gbx_st_asmvt_pyramid generator for publishing Mapbox Vector Tile (MVT) layers
  • TIN surface modeling — gbx_st_triangulate, gbx_st_interpolateelevationbbox and gbx_st_interpolateelevationgeom for Delaunay triangulation and grid elevation interpolation from Z-valued points, with a constrained or conforming mode
  • CRS strings — gbx_st_crs, gbx_st_setcrs and gbx_st_transformcrs for reading, stamping and reprojecting a geometry's CRS by CRS string (ESRI codes, WKT, PROJ4 — not just an EPSG integer)
  • Geometry validity — gbx_st_makevalid and gbx_st_explainvalidity for repairing and diagnosing OGC-invalid geometries
  • Coverage validity — gbx_st_coverageisvalid, gbx_st_coverageinvalidedges (SQL grouped aggregates) and coverage_simplify (a Python helper) for validating and simplifying polygon coverages
  • Geometry cleaning — gbx_st_simplifypreservetopology, gbx_st_removerepeatedpoints, gbx_st_reduceprecision, gbx_st_node and gbx_st_snap for topology-safe simplification, vertex deduplication, precision reduction, noding and snapping
  • Antimeridian handling — gbx_st_shiftlongitude, gbx_st_wrapx and gbx_st_split for normalizing geometries that cross the 180° antimeridian
  • Legacy Mosaic conversion — gbx_st_legacyaswkb for migrating geometries written by DBLabs Mosaic

Vector files are read and written by the *_gbx readers and writers. See the readers overview.

Using these functions
  • Import paths — Python: databricks.labs.gbx.vectorx.functions. Python-only helpers such as coverage_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.
Coordinate reference systems

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.

FunctionLevelsNotes
st_asmvtPython
st_asmvt_pyramidPython
st_triangulatePython, JVMJVM level by default on a dedicated cluster; both modes run on every level
st_interpolateelevationbboxPython, JVMJVM level by default on a dedicated cluster; both modes run on every level
st_interpolateelevationgeomPythonBoth modes run on every level
st_crs, st_setcrsPython
st_transformcrsPython, JVMJVM level by default on a dedicated cluster
st_legacyaswkbPython, JVM, Unity CatalogJVM level by default on a dedicated cluster
st_makevalid, st_explainvalidityPython, Unity Catalog
st_wrapxPython, Unity Catalog
st_coverageisvalid, st_coverageinvalidedgesPython
coverage_simplifyPython helperNo SQL form
st_simplifypreservetopology, st_removerepeatedpoints, st_reduceprecision, st_node, st_snapPython
st_shiftlongitude, st_splitPython

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 / DataFrameSchemaBacked byBacks
tin_surveypts 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_featuresz 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_geomsgeom STRINGEWKT literal 'SRID=4326;POINT (13 42)'CRS examples: st_crs, st_setcrs, st_transformcrs
legacy_geomsgeom_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:

TabSurface
SQLSession SQL, after register(spark)
Unity Catalog SQLA <catalog>.<schema>.gbx_* function, where the function exists in Unity Catalog
PythonThe 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:

ArgumentDefaultDescription
layer_name"layer"MVT layer name embedded in the protobuf.
extent4096MVT 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
SurfaceCallReturns
SQL (session)gbx_st_asmvt(geom, attrs, layer_name)BINARY
Pythonvectorx.functions.st_asmvt(geom, attrs, layer_name)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGThe feature geometry in tile coordinates: WKB, EWKB, WKT or EWKT. A NULL or empty geometry is skipped.
attrsSTRUCTThe feature's attributes, a struct of any fields.
layer_nameSTRINGThe name of the layer.
Grouped-agg UDF

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 (STRING or str) — 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.

Since v0.4.0
SELECT z, x, y, gbx_st_asmvt(geom_wkb, attrs, 'layer') AS mvt
FROM mvt_features
GROUP BY z, x, y;
Example output
+-+-+-+--------+
|z|x|y|mvt |
+-+-+-+--------+
|0|0|0|[binary]|
+-+-+-+--------+
... (MVT binary)

st_asmvt_array​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.functions.st_asmvt_array(features, layer_name, extent=None)Column
ParameterSQL typeUC typeDefaultDescription
featuresarray<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_nameSTRINGSTRINGThe name of the layer.
extentINTINT4096The 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.

Since v0.6.0
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;
Example output
+-+-+-+--------+
|z|x|y|mvt |
+-+-+-+--------+
|0|0|0|[binary]|
+-+-+-+--------+
... (MVT binary)

st_asmvt_pyramid​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.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.

ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe feature geometry in EPSG:4326: WKB, EWKB, WKT or EWKT.
attrsSTRUCTSTRINGThe 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_zINTINTThe first zoom level, from 0.
max_zINTINTThe last zoom level, at least min_z and at most 20.
layer_nameSTRINGSTRING'layer'The layer name written into each tile.
extentINTINT4096The tile coordinate extent.
Streaming UDTF

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.

Since v0.4.0
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;
Example output
+-+-+-+---------+
|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'):

ModeLevelsBehavior
constrained (default)Every levelConstrained 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.
conformingEvery levelJTS 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:

  1. The break line vertices come first, then the mass points, each in input order.
  2. A point within merge_tolerance of a point kept before it merges into the nearest one. The first point kept wins, with its Z.
  3. So a mass point near a break line vertex merges into the vertex.
  4. With merge_tolerance 0, 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:

  1. A point within snap_tolerance of a break line moves onto the nearest one. On a tie, the first line wins.
  2. The point takes the line's Z there, interpolated along the segment. A 2D break line has Z 0.
  3. The point becomes a new vertex of the line, so no triangle has zero area.
  4. A point that lands within merge_tolerance of a line vertex merges into it. With merge_tolerance 0, only the same X and Y merges.
  5. A point that does not snap but lies within merge_tolerance of a new vertex merges into that vertex.
Invocation surface

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
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.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.

ParameterSQL typeUC typeDefaultDescription
points_arrayARRAY<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_arrayARRAY<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_toleranceDOUBLEDOUBLEPoints 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_toleranceDOUBLEDOUBLEPoints within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing.
split_point_finderSTRINGSTRINGThe 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.
xminDOUBLEDOUBLEThe west edge of the grid.
yminDOUBLEDOUBLEThe south edge of the grid.
xmaxDOUBLEDOUBLEThe east edge of the grid, above xmin.
ymaxDOUBLEDOUBLEThe north edge of the grid, above ymin.
width_pxINTINTThe number of grid columns, above 0.
height_pxINTINTThe number of grid rows, above 0.
sridINTINTThe SRID of the output points; 0 for none.
modeSTRINGSTRING'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.
Streaming UDTF

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.

Since v0.4.0
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
Example output
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 elevation grid, 9 rows)

st_interpolateelevationgeom​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.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.

ParameterSQL typeUC typeDefaultDescription
points_arrayARRAY<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_arrayARRAY<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_toleranceDOUBLEDOUBLEPoints 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_toleranceDOUBLEDOUBLEPoints within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing.
split_point_finderSTRINGSTRINGThe 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_originBINARY or STRINGGEOMETRYThe origin of the grid: a POINT in WKB, EWKB, WKT or EWKT. Its SRID is the SRID of the output.
grid_colsINTINTThe number of grid columns.
grid_rowsINTINTThe number of grid rows.
cell_size_xDOUBLEDOUBLEThe cell width in the geometry's units; a positive value steps east.
cell_size_yDOUBLEDOUBLEThe cell height in the geometry's units; a negative value steps south.
modeSTRINGSTRING'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.
Streaming UDTF

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.

Since v0.4.0
SELECT t.elevation_point
FROM tin_survey, LATERAL gbx_st_interpolateelevationgeom(pts, bl, 0, 0, 'NONENCROACHING', unhex('010100000000000000000000000000000000002440'), 3, 3, 3, -3, 'constrained') t
Example output
+---------------+
|elevation_point|
+---------------+
|[binary] |
|[binary] |
|... |
+---------------+
... (WKB binary — POINT Z geometries, 3×3 origin-anchored grid, 9 rows)

st_triangulate​

SQLUnity Catalog SQLPythonScala
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.functions.st_triangulate(df, points_array, breaklines_array, merge_tolerance, snap_tolerance, split_point_finder, mode=None)DataFrame

Rows: triangle BINARY.

ParameterSQL typeUC typeDefaultDescription
points_arrayARRAY<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_arrayARRAY<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_toleranceDOUBLEDOUBLEPoints 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_toleranceDOUBLEDOUBLEPoints within this distance of a break line are moved onto it, taking its Z, before triangulating. 0 snaps nothing.
split_point_finderSTRINGSTRINGThe 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.
modeSTRINGSTRING'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.
Streaming UDTF

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).

Since v0.4.0
SELECT t.triangle
FROM tin_survey, LATERAL gbx_st_triangulate(pts, bl, 0, 0, 'NONENCROACHING', 'constrained') t
Example output
+--------+
|triangle|
+--------+
|[binary]|
|[binary]|
+--------+
... (WKB binary — 2 Delaunay triangle polygons)
Both modes run at every level

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:

SituationResult
NULL geometryNULL
NULL target_crsNULL
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 parsedinput returned unchanged
target_crs cannot be parsedraises
gbx_st_setcrs given a CRS with no integer authority coderaises

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_transformcrs reprojects X and Y of every vertex and carries the Z through the transformation for the vertices that have one. The vertices without a Z stay NaN in the result, and their X and Y are still correct.
  • gbx_st_setcrs keeps 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.

Known limitations

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:4326 returns 11.000000000000002 where it started at 11 — 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_setcrs relabels without reprojecting, so stamping a CRS whose units do not match the coordinates leaves the geometry mislabelled. A later st_transformcrs then transforms from the wrong CRS. Projected metres tagged EPSG:4326 come back as Infinity coordinates on the Python level. The JVM level raises a projection error. Use st_transformcrs when 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 returns Infinity coordinates; 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 ZM geometry comes back as Z with the measure gone. A geometry carrying M but no Z comes back plain 2D, with no Z invented. The product's own geometry type does persist M.

st_crs​

SQLPython
SurfaceCallReturns
SQL (session)gbx_st_crs(geom)STRING
Pythonvectorx.functions.st_crs(geom)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGThe 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>.

Since v0.5.0
SELECT gbx_st_crs(geom) AS crs FROM vector_geoms;
Example output
+---------+
|crs |
+---------+
|EPSG:4326|
+---------+

st_setcrs​

SQLPython
SurfaceCallReturns
SQL (session)gbx_st_setcrs(geom, crs)BINARY
Pythonvectorx.functions.st_setcrs(geom, crs)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGThe geometry: WKB, EWKB, WKT or EWKT.
crsSTRING or INTThe 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 with EPSG:32633 at partial confidence, but a geometry SRID is an exact identity claim. A guess is never silently written into one. Use gbx_st_transformcrs if 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.

Since v0.5.0
SELECT gbx_st_setcrs(geom, 'EPSG:4326') AS stamped FROM vector_geoms;
Example output
+--------+
|stamped |
+--------+
|[binary]|
+--------+
... (EWKB binary — coordinates preserved, SRID=4326 embedded)

st_transformcrs​

SQLPythonScala
SurfaceCallReturns
SQL (session)gbx_st_transformcrs(geom, target_crs, [source_crs])BINARY
Pythonvectorx.functions.st_transformcrs(geom, target_crs, source_crs=None)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGThe geometry: WKB, EWKB, WKT or EWKT.
target_crsSTRING or INTThe target CRS: EPSG:<code> or ESRI:<code>, an integer, WKT, PROJJSON or PROJ4.
source_crsSTRING or INTNULLThe 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_crsExampleOutput
Has an integer authority code'EPSG:32633', 'ESRI:54008', 32633EWKB with that SRID stamped — a plain input is upgraded to carry one
Has no integer authority coderaw 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.

Converting the result to a product geometry

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.

Since v0.5.0
SELECT gbx_st_transformcrs(geom, 'EPSG:32633') AS utm33n FROM vector_geoms;
Example output
+--------+
|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
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_makevalid(geom, [level])BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_makevalid(geom, [level])GEOMETRY
Pythonvectorx.functions.st_makevalid(geom, level=None)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
levelSTRINGSTRING'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
SELECT gbx_st_makevalid('POLYGON((0 0,1 1,1 0,0 1,0 0))') AS clean
Example output
+--------+
|clean |
+--------+
|[binary]|
+--------+
... (WKB binary — repaired geometry; bowtie becomes a valid multi-polygon)

st_explainvalidity​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_explainvalidity(geom)STRING
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_explainvalidity(geom)STRING
Pythonvectorx.functions.st_explainvalidity(geom)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe 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.

Unity Catalog takes a parsed geometry

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
SELECT gbx_st_explainvalidity('POLYGON((0 0,1 1,1 0,0 1,0 0))') AS detail
Example output
+--------------------------------------------------------------------+
|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
SurfaceCallReturns
SQL (session)gbx_st_coverageisvalid(geom, [gap_width])BOOLEAN
Pythonvectorx.functions.st_coverageisvalid(geom, gap_width=None)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGA polygon of the coverage: WKB, EWKB, WKT or EWKT. A NULL or empty one is skipped.
gap_widthDOUBLE0.0The 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
SELECT cov_id, gbx_st_coverageisvalid(geom, 0.0) AS is_valid
FROM coverage_parcels
GROUP BY cov_id
Example output
+------+--------+
|cov_id|is_valid|
+------+--------+
|1 |true |
+------+--------+
... (BOOLEAN — true when the polygon group has no overlaps and no slivers narrower than gap_width)

st_coverageinvalidedges​

SQLPython
SurfaceCallReturns
SQL (session)gbx_st_coverageinvalidedges(geom, [gap_width])BINARY
Pythonvectorx.functions.st_coverageinvalidedges(geom, gap_width=None)Column
ParameterSQL typeDefaultDescription
geomBINARY or STRINGA polygon of the coverage: WKB, EWKB, WKT or EWKT. A NULL or empty one is skipped.
gap_widthDOUBLE0.0The 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
SELECT cov_id, gbx_st_coverageinvalidedges(geom, 0.0) AS bad_edges
FROM coverage_overlap
GROUP BY cov_id
Example output
+------+---------+
|cov_id|bad_edges|
+------+---------+
|1 |[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; empty geometry when the coverage is clean)

st_coverageisvalid_array​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_coverageisvalid_array(geoms, [gap_width])BOOLEAN
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_coverageisvalid_array(geoms, [gap_width])BOOLEAN
Pythonvectorx.functions.st_coverageisvalid_array(geoms, gap_width=None)Column
ParameterSQL typeUC typeDefaultDescription
geomsarray<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_widthDOUBLEDOUBLE0.0The 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.

Since v0.6.0
SELECT cov_id, gbx_st_coverageisvalid_array(collect_list(geom_wkb), 0.0) AS is_valid
FROM coverage_parcels
GROUP BY cov_id
Example output
+------+--------+
|cov_id|is_valid|
+------+--------+
|1 |true |
+------+--------+
... (BOOLEAN — true when the polygons have no overlap and no gap narrower than gap_width)

st_coverageinvalidedges_array​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_coverageinvalidedges_array(geoms, [gap_width])BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_coverageinvalidedges_array(geoms, [gap_width])BINARY
Pythonvectorx.functions.st_coverageinvalidedges_array(geoms, gap_width=None)Column
ParameterSQL typeUC typeDefaultDescription
geomsarray<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_widthDOUBLEDOUBLE0.0The 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.

Since v0.6.0
SELECT cov_id, gbx_st_coverageinvalidedges_array(collect_list(geom_wkb), 0.0) AS bad_edges
FROM coverage_overlap
GROUP BY cov_id
Example output
+------+---------+
|cov_id|bad_edges|
+------+---------+
|1 |[binary] |
+------+---------+
... (BINARY — union of the invalid edge segments; empty geometry when the coverage is clean)

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, default True) — 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
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_simplifypreservetopology(geom, tolerance)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_simplifypreservetopology(geom, tolerance)GEOMETRY
Pythonvectorx.functions.st_simplifypreservetopology(geom, tolerance)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
toleranceDOUBLEDOUBLEThe 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
SELECT gbx_st_simplifypreservetopology('POLYGON((0 0,0 5,0.001 8,0 10,10 10,10 0,0 0))', 1.0) AS simplified
Example output
+----------+
|simplified|
+----------+
|[binary] |
+----------+
... (WKB binary — simplified polygon with near-collinear vertex removed, topology preserved)

st_removerepeatedpoints​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_removerepeatedpoints(geom, [tolerance])BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_removerepeatedpoints(geom, [tolerance])GEOMETRY
Pythonvectorx.functions.st_removerepeatedpoints(geom, tolerance=None)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
toleranceDOUBLEDOUBLE0.0Vertices 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
SELECT gbx_st_removerepeatedpoints('LINESTRING(0 0,0 0,1 1,1 1,2 2)') AS deduped
Example output
+--------+
|deduped |
+--------+
|[binary]|
+--------+
... (WKB binary — linestring with duplicate consecutive vertices removed: LINESTRING(0 0,1 1,2 2))

st_reduceprecision​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_reduceprecision(geom, grid_size)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_reduceprecision(geom, grid_size)GEOMETRY
Pythonvectorx.functions.st_reduceprecision(geom, grid_size)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
grid_sizeDOUBLEDOUBLEThe 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
SELECT gbx_st_reduceprecision('POINT(1.234 5.678)', 1.0) AS snapped
Example output
+--------+
|snapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(1.0, 6.0): coordinates snapped to nearest 1.0 grid lines)

st_node​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_node(geom)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_node(geom)GEOMETRY
Pythonvectorx.functions.st_node(geom)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe 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
SELECT gbx_st_node('LINESTRING(0 0,10 10,0 10,10 0)') AS noded
Example output
+--------+
|noded |
+--------+
|[binary]|
+--------+
... (WKB binary — MultiLineString: figure-eight split into clean segments at the self-intersection)

st_snap​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_snap(geom, reference, tolerance)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_snap(geom, reference, tolerance)GEOMETRY
Pythonvectorx.functions.st_snap(geom, reference, tolerance)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
referenceBINARY or STRINGGEOMETRYThe geometry to snap onto: WKB, EWKB, WKT or EWKT.
toleranceDOUBLEDOUBLEThe 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
SELECT gbx_st_snap('LINESTRING(0 0.4,10 0.4)', 'LINESTRING(0 0,10 0)', 0.5) AS snapped
Example output
+--------+
|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
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_shiftlongitude(geom)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_shiftlongitude(geom)GEOMETRY
Pythonvectorx.functions.st_shiftlongitude(geom)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe 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
SELECT gbx_st_shiftlongitude('POLYGON((-170 -10, -150 -10, -150 10, -170 10, -170 -10))') AS shifted
Example output
+--------+
|shifted |
+--------+
|[binary]|
+--------+
... (WKB binary — polygon in [0,360] longitude space, x coordinates shifted to [190,210])

st_wrapx​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
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
Pythonvectorx.functions.st_wrapx(geom, wrap_x_origin, wrap_direction)Column
ParameterSQL typeUC typeDefaultDescription
geomBINARY or STRINGGEOMETRYThe geometry: WKB, EWKB, WKT or EWKT.
wrap_x_originDOUBLEDOUBLEThe x value the wrap starts from.
wrap_directionDOUBLEDOUBLEThe 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
SELECT gbx_st_wrapx('POINT(190 10)', 180, -360) AS wrapped
Example output
+--------+
|wrapped |
+--------+
|[binary]|
+--------+
... (WKB binary — POINT(-170, 10): x=190 wrapped back by -360)

st_split​

SQLUnity Catalog SQLPython
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_split(input_geom, blade_geom)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_split(input_geom, blade_geom)GEOMETRY
Pythonvectorx.functions.st_split(input_geom, blade_geom)Column
ParameterSQL typeUC typeDefaultDescription
input_geomBINARY or STRINGGEOMETRYThe geometry to split: WKB, EWKB, WKT or EWKT.
blade_geomBINARY or STRINGGEOMETRYThe 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
SELECT gbx_st_split('POLYGON((170 -10, 190 -10, 190 10, 170 10, 170 -10))', 'LINESTRING(180 -90, 180 90)') AS pieces
Example output
+--------+
|pieces |
+--------+
|[binary]|
+--------+
... (WKB binary — GeometryCollection with 2 polygon pieces split at x=180)

Legacy Mosaic conversion​

st_legacyaswkb​

SQLUnity Catalog SQLPythonScala
Also available as a Unity Catalog function for SQL warehouses. See Unity Catalog functions.
SurfaceCallReturns
SQL (session)gbx_st_legacyaswkb(geom)BINARY
SQL (Unity Catalog)<catalog>.<schema>.gbx_st_legacyaswkb(geom)GEOMETRY
Pythonvectorx.functions.st_legacyaswkb(geom)Column
ParameterSQL typeUC typeDefaultDescription
geomstruct<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_legacyaswkb with 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.
Since v0.2.0
SELECT gbx_st_legacyaswkb(geom_legacy) AS wkb FROM legacy_geoms;
Example output
+--------+
|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_explainvalidity and gbx_st_makevalid
  • Coverage Validity — validate and simplify polygon coverages with gbx_st_coverageisvalid, gbx_st_coverageinvalidedges, and coverage_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 .pmtiles archive
  • PMTiles Writer — DataSource for streaming large pyramids to a single .pmtiles file
  • Helios notebooks — worked end-to-end example: gbx_st_asmvt + gbx_st_asmvt_pyramid encode San Francisco building footprints into a PMTiles archive (NB01).
  • Benchmarking — timing method
  • API Overview — All GeoBrix APIs