Analytics Toolbox for Redshift

Analytics Toolbox for Redshift

transformations

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

ST_CENTERMEAN

Description

Takes a Feature or FeatureCollection as input and returns the mean center.

  • geom: GEOMETRY for which to compute the mean center.

Return type

GEOMETRY

Example

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

ST_CENTERMEDIAN

Description

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

  • geom: GEOMETRY for which to compute the median center.

Return type

GEOMETRY

Example

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

ST_CENTEROFMASS

Description

Takes any Feature or a FeatureCollection as input and returns its center of mass using this formula: Centroid of Polygon. It is equivalent to ST_CENTROID.

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

Return type

GEOMETRY

Example

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

ST_CENTROID

Description

Takes any Feature or a FeatureCollection as input and returns its centroid. It is equivalent to ST_CENTEROFMASS.

  • geom: GEOMETRY for which to compute the centroid.

Return type

GEOMETRY

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
SELECT carto.ST_CENTROID(ST_GEOMFROMTEXT('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'));
-- POINT (25.4545454545 26.9696969697)

### ST_DESTINATION





  




<div class="banner-note banner-note--code u-mb24" data-title="">
  
carto.ST_DESTINATION(geom, distance, bearing, units)

</div>

**Description**

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

* `geom`: `GEOMETRY` starting point.
* `distance`: `FLOAT8` distance from the origin point.
* `bearing`: `FLOAT8` ranging from -180 to 180.
* `units` (optional): `VARCHAR(15)` units of length. The supported options are: miles, kilometers, degrees or radians. If not specified, its default value is `kilometers`.

**Return type**

`GEOMETRY`

**Examples**

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

ST_GREATCIRCLE

Description

Calculates a great circle route as a LineString.

  • 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

1
2
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, ...
1
2
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, ...