Skip to main content
Apache Pinot provides a comprehensive set of geospatial functions that follow the SQL/MM specification with the ST_ prefix. These functions enable you to create, manipulate, measure, and analyze spatial data.

Function Categories

Constructors

Create geospatial objects from coordinates, WKT, WKB, and GeoJSON

Measurements

Calculate distances, areas, and geometric properties

Relationships

Test spatial relationships like containment and intersection

Outputs

Convert geospatial objects to various formats

Conversions

Transform between geometry and geography types

Aggregations

Combine multiple geometries into collections

Constructors

Functions for creating geospatial objects from various input formats.

ST_Point

Creates a point geometry from X,Y coordinates.
Examples:

ST_GeomFromText

Creates geometry from Well-Known Text (WKT) representation.
Examples:

ST_GeomFromWKB

Creates geometry from Well-Known Binary (WKB) representation.
Examples:

ST_Polygon

Creates a polygon geometry from WKT representation.
Examples:

ST_GeogFromText

Creates geography from Well-Known Text with spherical calculations.
Examples:

ST_GeogFromWKB

Creates geography from Well-Known Binary representation.
Examples:

ST_GeomFromGeoJson

Creates geometry from GeoJSON string.
Examples:

ST_GeogFromGeoJson

Creates geography from GeoJSON string.
Examples:

Measurements

Functions for calculating spatial measurements and properties.

ST_Distance

Calculates distance between two geometries or geographies.
For Geometry: Returns 2D Cartesian distance in coordinate units
For Geography: Returns great-circle distance in meters
Geography Limitation: When using geography types, ST_Distance only accepts POINT geometries. For other geometry types (LINESTRING, POLYGON), use geometry types instead.
Examples:

ST_Area

Calculates the area of a polygon geometry or geography.
For Geometry: Returns 2D Euclidean area in coordinate units²
For Geography: Returns area in square meters using spherical model
Examples:

ST_GeometryType

Returns the type of a geometry or geography as a string.
Examples:

Relationships

Functions for testing spatial relationships between geometries.

ST_Contains

Tests if the first geometry completely contains the second.
Returns true if no points of g2 lie outside g1, and at least one interior point of g1 lies in the interior of g2.
Note: ST_Contains on Geography types provides close approximation, not exact results.
Examples:

ST_Within

Tests if the first geometry is completely within the second.
Returns true if every point of g1 is a point of g2, and the interiors of the two geometries have at least one point in common. Examples:

ST_Equals

Tests if two geometries or geographies represent the same geometry.
Returns true if g1 and g2 have at least one point in common, and no point of either lies in the exterior of the other. Examples:

Outputs

Functions for converting geospatial objects to various output formats.

ST_AsText

Converts geometry or geography to Well-Known Text (WKT).
Examples:

ST_AsBinary

Converts geometry or geography to Well-Known Binary (WKB).
Examples:

ST_AsGeoJson

Converts geometry or geography to GeoJSON format.
Examples:

Conversions

Functions for converting between geometry and geography types.

toSphericalGeography

Converts a Geometry object to spherical geography.
Examples:

toGeometry

Converts a spherical geography object to geometry.
Examples:

Aggregations

Functions for combining multiple geometries.

ST_Union

Combines multiple geometries into a single MULTI geometry.
This aggregate function returns a MULTI geometry or NON-MULTI geometry from a set of geometries. It ignores NULL geometries. Examples:

Function Usage with Indexes

Functions that Use H3 Index

These functions automatically leverage geospatial indexes when properly configured: Index-Optimized Query Patterns:

Checking Index Usage

Use EXPLAIN PLAN FOR to verify index usage:
Look for these operators in the query plan:
  • FILTER_H3_INDEX - ST_Distance queries using index
  • INCLUSION_FILTER_H3_INDEX - ST_Within/ST_Contains queries using index

Best Practices

Performance Tips

  • Use geography types for global applications requiring meter-based distances
  • Use geometry types for regional analysis where coordinate units are acceptable
  • Index your spatial columns with appropriate H3 resolutions
  • Structure queries to leverage indexes (proper argument order)

Function Selection Guide