# GeoSpatial Functions

For manipulating geospatial data, Pinot provides a set of functions for analyzing geometric components, determining spatial relationships, and manipulating geometries. In particular, geospatial functions that begin with the `ST_` prefix support the SQL/MM specification.

Following geospatial functions are available out of the box in Pinot:

### Aggregations

#### [**ST\_Union(geometry\[\] g1\_array) → Geometry**](/functions/geospatial/stunion.md)

This aggregate function returns a MULTI geometry or NON-MULTI geometry from a set of geometries. it ignores NULL geometries.

### Constructors

#### [**ST\_GeomFromText(String wkt) → Geometry**](/functions/geospatial/stgeomfromtext.md)

Returns a geometry type object from WKT representation, with the optional spatial system reference.

#### [**ST\_GeomFromWKB(bytes wkb) → Geometry**](/functions/geospatial/stgeomfromwkb.md)

Returns a geometry type object from WKB representation.

#### [**ST\_Point(double x, double y) → Point**](/functions/geospatial/stpoint.md)

Returns a geometry type point object with the given coordinate values.

#### [**ST\_Polygon(String wkt) → Polygon**](/functions/geospatial/stpolygon.md)

Returns a geometry type polygon object from [WKT representation](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry).

#### [**ST\_GeogFromWKB(bytes wkb) → Geography**](/functions/geospatial/stgeogfromwkb.md)

Creates a geography instance from a [Well-Known Binary geometry representation (WKB)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)

#### [**ST\_GeogFromText(String wkt) → Geography**](/functions/geospatial/stgeogfromtext.md)

Returns a specified geography value from [Well-Known Text representation or extended (WKT)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry).

### Measurements

#### **ST\_Area(Geometry/Geography g) → double**

For geometry type, it returns the 2D Euclidean area of a geometry. For geography, returns the area of a polygon or multi-polygon in square meters using a spherical model for Earth.

#### [**ST\_Distance(Geometry/Geography g1, Geometry/Geography g2) → double**](/functions/geospatial/stdistance.md)

For geometry type, returns the 2-dimensional cartesian minimum distance (based on spatial ref) between two geometries in projected units. For geography, returns the great-circle distance in meters between two SphericalGeography points. Note that g1, g2 shall have the same type.

#### [**ST\_GeometryType(Geometry g) → String**](/functions/geospatial/stgeometrytype.md)

Returns the type of the geometry as a string. e.g.: `ST_Linestring`, `ST_Polygon`,`ST_MultiPolygon` etc.

### Outputs

#### [**ST\_AsBinary(Geometry/Geography g) → bytes**](/functions/geospatial/stasbinary.md)

Returns the WKB representation of the geometry.

#### [**ST\_AsText(Geometry/Geography g) → string**](/functions/geospatial/stastext.md)

Returns the WKT representation of the geometry/geography.

### Conversion

#### [**toSphericalGeography(Geometry g) → Geography**](/functions/geospatial/tosphericalgeography.md)

Converts a Geometry object to a spherical geography object.

#### [**toGeometry(Geography g) → Geometry**](/functions/geospatial/togeometry.md)

Converts a spherical geographical object to a Geometry object.

### Relationship

#### [**ST\_Contains(Geometry/Geography, Geometry/Geography) → boolean**](/functions/geospatial/stcontains.md)

Returns true if and only if no points of the second geometry/geography lie in the exterior of the first geometry/geography, and at least one point of the interior of the first geometry lies in the interior of the second geometry. **Warning: ST\_Contains on Geography only give close approximation**

#### **ST\_Equals(Geometry, Geometry) → boolean**

Returns true if the given geometries represent the same geometry/geography.

#### **ST\_Within(Geometry, Geometry) → boolean**

Returns true if first geometry is completely inside second geometry.

## Additional Reference Pages

| Function                                                           | Function                                                           |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| [ST\_Union](/functions/geospatial/stunion.md)                      | [GridDistance](/functions/geospatial/griddistance.md)              |
| [GridDisk](/functions/geospatial/griddisk.md)                      | [ST\_AsGeoJSON](/functions/geospatial/st_asgeojson.md)             |
| [ST\_GeogFromGeoJSON](/functions/geospatial/st_geogfromgeojson.md) | [ST\_GeomFromGeoJSON](/functions/geospatial/st_geomfromgeojson.md) |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pinot.apache.org/functions/geospatial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
