> For the complete documentation index, see [llms.txt](https://docs.carto.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/transformations.md).

# transformations

This module contains functions that compute geometric constructions, or alter geometry size or shape.

## ST\_CENTERMEAN <a href="#st_centermean" id="st_centermean"></a>

```sql
ST_CENTERMEAN(geom)
```

**Description**

Takes a Feature or FeatureCollection and returns the mean center (average of its vertices).

**Input parameters**

* `geom`: `GEOMETRY` for which to compute the mean center.

**Return type**

`GEOMETRY`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_CENTERMEAN(ST_GEOMFROMTEXT('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'));
-- POINT (25 27.5)
```

{% endcode %}

## ST\_CENTERMEDIAN <a href="#st_centermedian" id="st_centermedian"></a>

```sql
ST_CENTERMEDIAN(geom)
```

**Description**

Takes a FeatureCollection of points and computes the median center. The median center is understood as the point that requires the least total travel from all other points.

**Input parameters**

* `geog`: `GEOMETRY` for which to compute the center.

**Return type**

`GEOMETRY`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_CENTERMEDIAN(ST_GEOMFROMTEXT('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'));
-- POINT (26.3841869726 19.0088147377)
```

{% endcode %}

## ST\_CENTEROFMASS <a href="#st_centerofmass" id="st_centerofmass"></a>

```sql
ST_CENTEROFMASS(geom)
```

**Description**

Takes any Feature or a FeatureCollection and returns its center of mass. It is equivalent to [`ST_CENTROID`](#st_centroid).

**Input parameters**

* `geom`: `GEOMETRY` for which to compute the center of mass.

**Return type**

`GEOMETRY`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_CENTEROFMASS(ST_GEOMFROMTEXT('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'));
-- POINT (25.4545454545 26.9696969697)
```

{% endcode %}

## ST\_CENTROID <a href="#st_centroid" id="st_centroid"></a>

```sql
ST_CENTROID(geom)
```

**Description**

Takes any Feature or a FeatureCollection as input and returns its centroid. It is equivalent to [`ST_CENTEROFMASS`](#st_centerofmass).

**Input parameters**

* `geom`: `GEOMETRY` for which to compute the centroid.

**Return type**

`GEOMETRY`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_CENTROID(ST_GEOMFROMTEXT('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'));
-- POINT (25.4545454545 26.9696969697)
```

{% endcode %}

## ST\_DESTINATION <a href="#st_destination" id="st_destination"></a>

```sql
ST_DESTINATION(geom, distance, bearing, units)
```

**Description**

Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and a bearing in degrees. This uses the Haversine formula to account for global curvature.

**Input parameters**

* `geom`: `GEOMETRY` starting point.
* `distance`: `FLOAT8` distance from the origin point in the units specified.
* `bearing`: `FLOAT8` ranging from -180 to 180 (e.g. 0 is North, 90 is East, 180 is South, -90 is West).
* `units` (optional): `VARCHAR(15)` units of length. The supported options are: `miles`, `kilometers`, `degrees` or `radians`. If `NULL`the default value `kilometers` is used.

**Return type**

`GEOMETRY`

**Examples**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_DESTINATION(ST_MakePoint(-3.70325,40.4167), 10, 45);
-- POINT (-3.61964617436 40.4802614598)
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_DESTINATION(ST_MakePoint(-3.70325,40.4167), 10, 45, 'miles');
-- POINT (-3.56862505482 40.5189626778)
```

{% endcode %}

## ST\_GREATCIRCLE <a href="#st_greatcircle" id="st_greatcircle"></a>

```sql
ST_GREATCIRCLE(start_point, end_point, n_points)
```

**Description**

Calculates a great circle route as a LineString.

**Input parameters**

* `start_point`: `GEOMETRY` source point feature.
* `end_point`: `GEOMETRY` destination point feature.
* `n_points` (optional): `INT` number of points. Defaults to `100`.

**Return type**

`GEOMETRY`

**Examples**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_GREATCIRCLE(ST_MAKEPOINT(-3.70325,40.4167), ST_MAKEPOINT(-73.9385,40.6643));
-- LINESTRING (-3.70325 40.4167, -4.32969777937 40.6355528695, ...
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.ST_GREATCIRCLE(ST_MAKEPOINT(-3.70325,40.4167), ST_MAKEPOINT(-73.9385,40.6643), 20);
-- LINESTRING (-3.70325 40.4167, -7.01193184681 41.5188665219, ...
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/transformations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
