Skip to content

Spatial Functions ​

Beacon holds 123 spatial functions with PostGIS names: 118 scalar functions, 3 aggregate functions and 2 window functions. This page lists every one of them.

A name is case insensitive. ST_Distance and st_distance are the same function.

Types in the tables below ​

TypeMeaning
GEOMETRYA geometry value. A GeoParquet column holds one. ST_Point builds one.
BOXA bounding box. It holds four DOUBLE values. ST_Envelope and ST_Extent return one.
DOUBLEA 64 bit float.
INTEGERA 32 bit integer.
BOOLEANTrue or false.
VARCHARText.
VARBINARYBytes.
LISTA list of VARBINARY. ST_Dump returns one.

constant after an argument type means the argument must be a literal. A column in that position gives an error at plan time. Such an argument drives a setup step per batch, so the function cannot rebuild it per row.

Build a geometry ​

A netCDF, Zarr, CSV or Parquet table holds coordinate columns, not geometry. ST_Point builds a geometry from two columns:

sql
SELECT ST_AsText(ST_Point(longitude, latitude)) AS point
FROM read_parquet(['obs/*.parquet'])

A column without geometry metadata also reads as a geometry. A VARCHAR column reads as WKT. A VARBINARY column reads as WKB. So a raw CSV column needs no cast.

A GeoParquet file holds a geometry column, and Beacon decodes it to native GeoArrow on read. Every function here reads such a column directly:

sql
SELECT ST_AsText(ST_Extent(geometry)) AS extent
FROM read_geoparquet(['spatial/stations/*.geoparquet'])

TIP

A filter over a GeoParquet geometry column also skips row groups. See what the scan skips.

Accessors ​

An accessor reads one property of a geometry.

FunctionArgumentsReturnsDescription
ST_X(geom)geom GEOMETRYDOUBLEX ordinate of a point. It copies no data on a point column with separate coordinates.
ST_Y(geom)geom GEOMETRYDOUBLEY ordinate of a point.
ST_Z(geom)geom GEOMETRYDOUBLEZ ordinate. A 2D geometry returns NULL.
ST_M(geom)geom GEOMETRYDOUBLEMeasure value. A geometry without a measure returns NULL.
ST_SRID(geom)geom GEOMETRYINTEGERCoordinate reference system of the column. Every row returns the same value.
ST_GeometryType(geom)geom GEOMETRYVARCHARType name, such as ST_Point.
ST_Dimension(geom)geom GEOMETRYINTEGERTopological dimension: 0, 1 or 2.
ST_CoordDim(geom)geom GEOMETRYINTEGERNumber of ordinates per coordinate: 2, 3 or 4.
ST_NPoints(geom)geom GEOMETRYINTEGERNumber of coordinates, at any depth.
ST_NumPoints(geom)geom GEOMETRYINTEGERNumber of points of a line string. Another type returns NULL.
ST_NumGeometries(geom)geom GEOMETRYINTEGERNumber of parts of a collection.
ST_NumInteriorRings(geom)geom GEOMETRYINTEGERNumber of holes of a polygon.
ST_IsEmpty(geom)geom GEOMETRYBOOLEANTrue for an empty geometry.
ST_IsClosed(geom)geom GEOMETRYBOOLEANTrue when the start point equals the end point.
ST_IsRing(geom)geom GEOMETRYBOOLEANTrue for a line string that is closed and simple.
ST_IsSimple(geom)geom GEOMETRYBOOLEANTrue when a geometry crosses itself nowhere. An areal geometry is always simple.

Components ​

A component function returns one part of a geometry.

FunctionArgumentsReturnsDescription
ST_StartPoint(geom)geom GEOMETRYGEOMETRYFirst point of a line string.
ST_EndPoint(geom)geom GEOMETRYGEOMETRYLast point of a line string.
ST_PointN(geom, n)geom GEOMETRY, n INTEGERGEOMETRYPoint n of a line string. The index starts at 1. An index outside the line returns NULL.
ST_ExteriorRing(geom)geom GEOMETRYGEOMETRYShell of a polygon, as a line string.
ST_InteriorRingN(geom, n)geom GEOMETRY, n INTEGERGEOMETRYHole n of a polygon. The index starts at 1.
ST_GeometryN(geom, n)geom GEOMETRY, n INTEGERGEOMETRYPart n of a collection. Index 1 returns the input when the input is no collection.

Constructors ​

A constructor builds a geometry from plain columns.

FunctionArgumentsReturnsDescription
ST_Point(x, y[, z])x DOUBLE, y DOUBLE, z DOUBLEGEOMETRYPoint from two or three ordinate columns. It adopts the input buffers and copies nothing. A third argument sets z, not the SRID.
ST_MakePoint(x, y[, z])x DOUBLE, y DOUBLE, z DOUBLEGEOMETRYThe same function, under the PostGIS alias.
ST_PointZ(x, y[, z])x DOUBLE, y DOUBLE, z DOUBLEGEOMETRYThe same function. Two arguments return a 2D point. PostGIS needs three.
ST_MakeLine(a, b)a GEOMETRY, b GEOMETRYGEOMETRYTwo-point line from two point columns. There is no aggregate form.
ST_MakePolygon(ring)ring GEOMETRYGEOMETRYPolygon from a closed line string. It builds the shell only, with no holes.
ST_MakeEnvelope(x1, y1, x2, y2)four DOUBLEGEOMETRYRectangle from four ordinates. It adopts all four input buffers. There is no fifth srid argument.
ST_MakeBox2D(x1, y1, x2, y2)four DOUBLEBOXBox from four ordinates. PostGIS takes two points here.

Input and output ​

FunctionArgumentsReturnsDescription
ST_AsText(geom)geom GEOMETRYVARCHARWKT text. There is no maxdecimaldigits argument.
ST_AsBinary(geom)geom GEOMETRYVARBINARYWKB bytes.
ST_AsEWKB(geom)geom GEOMETRYVARBINARYExtended WKB bytes. The SRID comes from the column metadata.
ST_AsGeoJSON(geom)geom GEOMETRYVARCHARGeoJSON text. It accepts a geometry only, not a row.
ST_GeomFromText(wkt)wkt VARCHARGEOMETRYGeometry from WKT. There is no srid argument. Call ST_SetSRID after it.
ST_GeomFromWKB(bytes)bytes VARBINARYGEOMETRYGeometry from WKB.
ST_GeomFromEWKB(bytes)bytes VARBINARYGEOMETRYGeometry from extended WKB. The SRID inside the value is lost. Call ST_SetSRID after it.
ST_GeomFromGeoJSON(json)json VARCHARGEOMETRYGeometry from GeoJSON.
ST_GeoHash(geom[, prec])geom GEOMETRY, prec INTEGERVARCHARGeohash of a point. Another type returns NULL. The default precision is 20.
ST_PointFromGeoHash(hash)hash VARCHARGEOMETRYCentre point of a geohash cell. There is no precision argument.

Predicates ​

A predicate compares two geometries and returns true or false. Each one runs a bounding box test first. The exact test then runs on the rows that pass.

FunctionArgumentsReturnsDescription
ST_Intersects(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the two share a point.
ST_Disjoint(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the two share no point.
ST_Contains(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when a holds b.
ST_ContainsProperly(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when a holds b and the boundaries meet nowhere.
ST_Within(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when b holds a.
ST_Covers(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when every point of b lies in a.
ST_CoveredBy(a, b)a GEOMETRY, b GEOMETRYBOOLEANThe reverse of ST_Covers.
ST_Touches(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when only the boundaries meet.
ST_Crosses(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the interiors cross.
ST_Overlaps(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the two overlap in part.
ST_Equals(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the two cover the same points.
ST_Relate(a, b)a GEOMETRY, b GEOMETRYVARCHARThe nine character DE-9IM matrix.
ST_Relate(a, b, pattern)a GEOMETRY, b GEOMETRY, pattern VARCHAR constantBOOLEANTrue when the matrix matches the pattern.
ST_DWithin(a, b, d)a GEOMETRY, b GEOMETRY, d DOUBLE constantBOOLEANTrue when the distance is d or less.
ST_DFullyWithin(a, b, d)a GEOMETRY, b GEOMETRY, d DOUBLE constantBOOLEANTrue when every point pair lies within d.
ST_BBoxIntersects(a, b)a GEOMETRY, b GEOMETRYBOOLEANTrue when the two bounding boxes overlap. PostGIS writes this as the && operator.

Measurement ​

Every measurement is planar. Longitude and latitude data therefore returns degrees, not metres. ST_DistanceSphere and ST_DistanceSpheroid are the two exceptions. Both return metres.

FunctionArgumentsReturnsDescription
ST_Area(geom)geom GEOMETRYDOUBLEArea.
ST_Length(geom)geom GEOMETRYDOUBLELength of the lineal parts. A polygon returns zero.
ST_Perimeter(geom)geom GEOMETRYDOUBLEPerimeter of the areal parts.
ST_Distance(a, b)a GEOMETRY, b GEOMETRYDOUBLEShortest distance.
ST_MaxDistance(a, b)a GEOMETRY, b GEOMETRYDOUBLELargest distance between two vertices. The cost is the product of the two vertex counts.
ST_HausdorffDistance(a, b)a GEOMETRY, b GEOMETRYDOUBLEHausdorff distance. There is no densifyFrac argument.
ST_FrechetDistance(a, b)a GEOMETRY, b GEOMETRYDOUBLEFréchet distance of two line strings. Another type returns NULL.
ST_DistanceSphere(a, b)a GEOMETRY, b GEOMETRYDOUBLEDistance of two points on a sphere, in metres. It takes two points only.
ST_DistanceSpheroid(a, b)a GEOMETRY, b GEOMETRYDOUBLEDistance of two points on WGS 84, in metres. There is no spheroid argument.

Linear reference ​

FunctionArgumentsReturnsDescription
ST_ClosestPoint(a, b)a GEOMETRY, b GEOMETRYGEOMETRYPoint of a nearest to b.
ST_ShortestLine(a, b)a GEOMETRY, b GEOMETRYGEOMETRYLine between the two nearest points.
ST_LineLocatePoint(line, pt)line GEOMETRY, pt GEOMETRYDOUBLEPosition of a point on a line, from 0 to 1.
ST_LineInterpolatePoint(line, f)line GEOMETRY, f DOUBLEGEOMETRYPoint at fraction f of a line. A fraction outside 0 to 1 returns NULL.

Overlay ​

Each overlay function takes areal arguments only. Another type returns NULL.

FunctionArgumentsReturnsDescription
ST_Union(a, b)a GEOMETRY, b GEOMETRYGEOMETRYUnion of two areal geometries.
ST_Intersection(a, b)a GEOMETRY, b GEOMETRYGEOMETRYCommon part of two areal geometries.
ST_Difference(a, b)a GEOMETRY, b GEOMETRYGEOMETRYPart of a outside b.
ST_SymDifference(a, b)a GEOMETRY, b GEOMETRYGEOMETRYPart of either one, but not of both.

ST_Union with one argument is an error. PostGIS gives that name to an aggregate, and one name cannot serve both registries here. The aggregate is ST_MemUnion.

Processing ​

FunctionArgumentsReturnsDescription
ST_Buffer(geom, d)geom GEOMETRY, d DOUBLEGEOMETRYArea within distance d. It uses round joins and round caps. There is no style argument.
ST_ConvexHull(geom)geom GEOMETRYGEOMETRYSmallest convex polygon around a geometry.
ST_ConcaveHull(geom, pct)geom GEOMETRY, pct DOUBLEGEOMETRYConcave hull. It supports no holes.
ST_OrientedEnvelope(geom)geom GEOMETRYGEOMETRYSmallest rectangle of any angle.
ST_Boundary(geom)geom GEOMETRYGEOMETRYBoundary of a geometry. A collection returns an empty boundary.
ST_Centroid(geom)geom GEOMETRYGEOMETRYCentre of mass.
ST_PointOnSurface(geom)geom GEOMETRYGEOMETRYA point that lies on the geometry.
ST_Simplify(geom, tol)geom GEOMETRY, tol DOUBLEGEOMETRYRamer-Douglas-Peucker simplification. There is no preserveCollapsed flag.
ST_SimplifyVW(geom, tol)geom GEOMETRY, tol DOUBLEGEOMETRYVisvalingam-Whyatt simplification.
ST_Segmentize(geom, max)geom GEOMETRY, max DOUBLEGEOMETRYSplit every segment longer than max. A length of zero or less returns NULL.
ST_RemoveRepeatedPoints(geom)geom GEOMETRYGEOMETRYDrop repeated coordinates. There is no tolerance argument.
ST_Reverse(geom)geom GEOMETRYGEOMETRYReverse the coordinate order.
ST_ForcePolygonCCW(geom)geom GEOMETRYGEOMETRYCounter-clockwise shell.
ST_ForcePolygonCW(geom)geom GEOMETRYGEOMETRYClockwise shell.
ST_Force2D(geom)geom GEOMETRYGEOMETRYDrop the Z ordinate. It drops one buffer handle and copies nothing.
ST_Force3D(geom)geom GEOMETRYGEOMETRYAdd a Z ordinate of zero.
ST_FlipCoordinates(geom)geom GEOMETRYGEOMETRYSwap X and Y. It swaps two buffer handles and copies nothing.
ST_SetSRID(geom, srid)geom GEOMETRY, srid INTEGER constantGEOMETRYSet the coordinate reference system. It reads no row, because it changes the column type.

ST_SimplifyPreserveTopology is absent. The library behind these functions has no topology-safe simplification. ST_SimplifyVW is close, but it gives no guarantee.

Validity ​

FunctionArgumentsReturnsDescription
ST_IsValid(geom)geom GEOMETRYBOOLEANTrue for a valid geometry.
ST_IsValidReason(geom)geom GEOMETRYVARCHARText that names the fault. A valid geometry returns Valid Geometry.
ST_MakeValid(geom)geom GEOMETRYGEOMETRYRepair an areal geometry. Another type passes through.

Affine ​

Every argument after the geometry must be a constant.

FunctionArgumentsReturnsDescription
ST_Translate(geom, dx, dy)geom GEOMETRY, dx DOUBLE constant, dy DOUBLE constantGEOMETRYMove a geometry. There is no 3D form.
ST_Scale(geom, xf, yf)geom GEOMETRY, xf DOUBLE constant, yf DOUBLE constantGEOMETRYScale about the origin.
ST_Rotate(geom, rad)geom GEOMETRY, rad DOUBLE constantGEOMETRYRotate about the origin. The angle is in radians.
ST_Affine(geom, a, b, d, e, xoff, yoff)geom GEOMETRY, six DOUBLE constantGEOMETRY2D affine transform. There is no twelve argument 3D form.

Bounding box ​

A box column holds four DOUBLE buffers. An ordinate accessor therefore hands back one buffer and allocates nothing.

FunctionArgumentsReturnsDescription
ST_Envelope(geom)geom GEOMETRYBOXBounding box of a geometry. It reads as ST_Polygon.
ST_Expand(geom, d)geom GEOMETRY, d DOUBLEBOXBounding box grown by d. There is no per-axis form.
ST_XMin(geom)geom GEOMETRY or BOXDOUBLESmallest X.
ST_YMin(geom)geom GEOMETRY or BOXDOUBLESmallest Y.
ST_XMax(geom)geom GEOMETRY or BOXDOUBLELargest X.
ST_YMax(geom)geom GEOMETRY or BOXDOUBLELargest Y.
ST_ZMin(geom)geom GEOMETRY or BOXDOUBLEAlways NULL. The box pass is two-dimensional.
ST_ZMax(geom)geom GEOMETRY or BOXDOUBLEAlways NULL.

Tessellation ​

FunctionArgumentsReturnsDescription
ST_DelaunayTriangles(geom)geom GEOMETRYGEOMETRYDelaunay triangulation. It always returns a collection.
ST_VoronoiPolygons(geom)geom GEOMETRYGEOMETRYVoronoi cells as polygons. It clips each cell to the input extent plus 50 percent.
ST_VoronoiLines(geom)geom GEOMETRYGEOMETRYVoronoi cell edges as lines.
ST_ChaikinSmoothing(geom, n)geom GEOMETRY, n INTEGERGEOMETRYChaikin smoothing. The limit is 8 rounds, because each round doubles the vertex count.

Bearings ​

FunctionArgumentsReturnsDescription
ST_Azimuth(a, b)a GEOMETRY, b GEOMETRYDOUBLEBearing of two points, in radians clockwise from north, on WGS 84. Two equal points return NULL.
ST_Project(pt, dist, azim)pt GEOMETRY, dist DOUBLE, azim DOUBLEGEOMETRYPoint at a distance in metres and a bearing in radians, on WGS 84.

Edits ​

FunctionArgumentsReturnsDescription
ST_Multi(geom)geom GEOMETRYGEOMETRYWrap a geometry in its multi form.
ST_Points(geom)geom GEOMETRYGEOMETRYEvery coordinate as one multi point.
ST_SnapToGrid(geom, size)geom GEOMETRY, size DOUBLEGEOMETRYRound every coordinate onto a grid. One size serves both axes. A size of zero or less returns NULL.
ST_AddPoint(line, pt[, pos])line GEOMETRY, pt GEOMETRY, pos INTEGERGEOMETRYAdd a point to a line string. The index starts at 0. It appends when you omit the position.
ST_RemovePoint(line, pos)line GEOMETRY, pos INTEGERGEOMETRYRemove a point from a line string. It returns NULL when fewer than two vertices remain.
ST_SetPoint(line, pos, pt)line GEOMETRY, pos INTEGER, pt GEOMETRYGEOMETRYReplace a point of a line string. Note the order: the position comes first.
ST_Dump(geom)geom GEOMETRYLISTParts of a collection, as a list of WKB.

ST_Dump returns a list, because a scalar function returns one value per row. Expand it with unnest:

sql
SELECT ST_AsText(unnest(ST_Dump(geometry))) AS part
FROM read_geoparquet(['shapes/*.geoparquet'])

The parts are WKB, not geometry. unnest drops the metadata of the child field, so a list of geometry arrives as a plain struct. A VARBINARY column always reads as WKB, so the parts stay usable with no cast.

Aggregate functions ​

An aggregate function reads every row of a group and returns one value.

FunctionArgumentsReturnsDescription
ST_Extent(geom)geom GEOMETRYBOXBounding box of every row. The state is four DOUBLE values, so it builds no geometry.
ST_Collect(geom)geom GEOMETRYGEOMETRYEvery row as one geometry collection. PostGIS returns a multi type for one input type.
ST_MemUnion(geom)geom GEOMETRYGEOMETRYUnion of every row. PostGIS also calls this ST_Union.

Read the box of ST_Extent with the four ordinate accessors:

sql
SELECT ST_XMin(ST_Extent(ST_Point(longitude, latitude))) AS west,
       ST_XMax(ST_Extent(ST_Point(longitude, latitude))) AS east,
       ST_YMin(ST_Extent(ST_Point(longitude, latitude))) AS south,
       ST_YMax(ST_Extent(ST_Point(longitude, latitude))) AS north
FROM read_parquet(['obs/*.parquet'])

Window functions ​

Both cluster functions read every row of a partition at once. PostGIS defines them as window functions, and so does Beacon. Each one needs OVER ().

FunctionArgumentsReturnsDescription
ST_ClusterKMeans(geom, k)geom GEOMETRY, k INTEGERINTEGERGroup the rows into k clusters. A fixed seed makes the query repeatable. There is no max_radius argument.
ST_ClusterDBSCAN(geom, eps, min)geom GEOMETRY, eps DOUBLE, min INTEGERINTEGERGroup the rows by density. Noise returns NULL.

Both functions cluster the centroids. PostGIS uses the whole geometry, so a large geometry can give another answer.

sql
SELECT platform,
       ST_ClusterKMeans(ST_Point(longitude, latitude), 5) OVER () AS cluster
FROM read_parquet(['obs/*.parquet'])

Reprojection ​

FunctionArgumentsReturnsDescription
ST_Transform(geom, srid)geom GEOMETRY, srid INTEGER constantGEOMETRYReproject a geometry to the target srid.

The source system comes from the column metadata. Set it first when the file states none:

sql
SELECT ST_AsText(ST_Transform(ST_SetSRID(ST_Point(longitude, latitude), 4326), 3035)) AS point
FROM read_parquet(['obs/*.parquet'])

The function takes an EPSG code, not a PROJ string.

ST_Transform links PROJ, a C++ library, and a standard Beacon build ships it. A build from source therefore needs PROJ 9.6.2 or later, beside the netCDF and HDF5 it already needs:

bash
sudo apt-get install -y libproj-dev pkg-config   # Debian and Ubuntu
brew install proj pkg-config                     # macOS

Two build options cover a machine without PROJ. --features spatial-proj-bundled builds PROJ from source. --no-default-features drops ST_Transform, and the other 122 functions stay.

Differences from PostGIS ​

Four rules explain most of the differences. Each table above marks the rest per function.

  • The coordinate reference system belongs to the column. GeoArrow holds it once, in the column metadata. ST_SRID therefore returns one value for every row, and ST_SetSRID needs a constant. One PostGIS column can hold rows in different systems. A Beacon column cannot.
  • A constant argument stays constant. A radius, a pattern, an SRID or a matrix drives a setup step per batch. A column in that position gives an error at plan time.
  • A row that does not fit returns NULL. PostGIS raises an error for a wrong geometry type. One bad row does not stop a query here. A wrong static type is still an error at plan time.
  • A plain column reads by its type. A VARCHAR column reads as WKT. A VARBINARY column reads as WKB. One surprise follows: ST_AsText on any text column returns that text. Pass such a column through ST_GeomFromText to check the parse step.

Functions that are absent ​

AreaPostGIS functionsReason
Geography typeevery geography overloadIt needs a second type and a spherical algorithm set.
EditsST_Snap, ST_Node, ST_Split, ST_LineMerge, ST_LineSubstring, ST_SubdivideThe library behind these functions has no equivalent.
3DST_3DDistance, ST_3DIntersects, ST_3DLength and the restThat library is two-dimensional.
Other outputST_AsGML, ST_AsKML, ST_AsSVG, ST_AsMVTBeacon needs a writer per format.
SimplificationST_SimplifyPreserveTopologyNo topology-safe simplification exists there.
Set outputST_DumpPoints, ST_DumpRingsThese have the shape of ST_Dump. ST_Points covers the common use.

:::note SHOW FUNCTIONS lists 10 of these functions. It reads information_schema.parameters, and a function that accepts any argument type states no argument types. Such a function gets no row there. Every function on this page runs, listed or not. Use this page as the reference. See datafusion-spatial#1. :::

Released under the AGPL-3.0 License.