Skip to content

Commit

Permalink
Update sql-reference in spatial-extension-bq
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus89 committed Apr 30, 2021
1 parent 05928c7 commit 3121397
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 54 deletions.
5 changes: 4 additions & 1 deletion app/content/spatial-extension-bq/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ cascade:
- "placekey"
- "random"
- "data"
- "transformation"
- "constructors"
- "transformations"
- "measurements"
- "clustering"
---
48 changes: 48 additions & 0 deletions app/content/spatial-extension-bq/sql-reference/clustering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## clustering

<div class="badge advanced"></div>

### ST_CLUSTERKMEANS

{{% bannerNote type="code" %}}
clustering.ST_CLUSTERKMEANS(geog, numberOfClusters)
{{%/ bannerNote %}}

**Description**

Takes a set of points and partition them into clusters using the k-mean. It uses the k-means algorithm. Returns an array with the cluster index for each of the input features. https://turfjs.org/docs/#clustersKmeans

* `geog`: `ARRAY<GEOGRAPHY>` points to be clustered.
* `numberOfClusters`: `INT64`|`NULL` numberOfClusters that will be generated. If `NULL` the default value `Math.sqrt(<NUMBER OF POINTS>/2)` is used.

**Return type**

`ARRAY<INT64>`

**Example**

```sql
SELECT bqcarto.clustering.ST_CLUSTERKMEANS([ST_GEOGPOINT(0, 0), ST_GEOGPOINT(0, 1), ST_GEOGPOINT(5, 0), ST_GEOGPOINT(1, 0)], 2);
-- [1, 1, 0, 1]
```

### VERSION

{{% bannerNote type="code" %}}
clustering.VERSION()
{{%/ bannerNote %}}

**Description**

Returns the current version of the clustering module.

**Return type**

`STRING`

**Example**

```sql
SELECT bqcarto.clustering.VERSION();
-- 1.0.0
```
117 changes: 117 additions & 0 deletions app/content/spatial-extension-bq/sql-reference/constructors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
## constructors

<div class="badge core"></div>

This module contains functions that create geographies from coordinates or already existing geographies.

### ST_BEZIERSPLINE

{{% bannerNote type="code" %}}
constructors.ST_BEZIERSPLINE(geog, resolution, sharpness)
{{%/ bannerNote %}}

**Description**

Takes a line and returns a curved version by applying a Bezier spline algorithm. https://turfjs.org/docs/#bezierSpline

* `geog`: `GEOGRAPHY` input LineString.
* `resolution`: `INT64`|`NULL` time in milliseconds between points. If `NULL` the default value `10000` is used.
* `sharpness`: `FLOAT64`|`NULL` a measure of how curvy the path should be between splines. If `NULL` the default value `0.85` is used.

```sql
SELECT bqcarto.constructors.ST_BEZIERSPLINE(ST_GEOGFROMTEXT("LINESTRING (-76.091308 18.427501,-76.695556 18.729501,-76.552734 19.40443,-74.61914 19.134789,-73.652343 20.07657,-73.157958 20.210656)"), 10000, 0.9);
-- LINESTRING(-76.091308 18.427501, -76.0916216712943 ...
```

### ST_MAKEELLIPSE

{{% bannerNote type="code" %}}
constructors.ST_MAKEELLIPSE(geog, xSemiAxis, ySemiAxis, angle, units, steps)
{{%/ bannerNote %}}

**Description**

Takes a Point and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision. https://github.com/Turfjs/turf/tree/master/packages/turf-ellipse

* `center`: `GEOGRAPHY` center point.
* `xSemiAxis`: `FLOAT64` semi (major) axis of the ellipse along the x-axis.
* `ySemiAxis`: `FLOAT64` semi (minor) axis of the ellipse along the y-axis.
* `angle`: `FLOAT64`|`NULL` angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise. If `NULL` the default value `0` is used.
* `units`: `STRING`|`NULL` any of the options supported by turf units: miles, kilometers, and degrees. If `NULL`the default value `kilometers` is used.
* `steps`: `INT64`|`NULL` number of steps. If `NULL` the default value `64` is used.

```sql
SELECT bqcarto.constructors.ST_MAKEELLIPSE(ST_GEOGPOINT(-73.9385,40.6643), 5, 3, -30, "miles", 80);
-- POLYGON((-73.8558575786687 40.7004828957859 ...
```

### ST_MAKEENVELOPE

{{% bannerNote type="code" %}}
constructors.ST_MAKEENVELOPE(xmin, ymin, xma, ymax)
{{%/ bannerNote %}}

**Description**
Creates a rectangular Polygon from the minimum and maximum values for X and Y.


* `xmin`: `FLOAT64` minimum value for X.
* `ymin`: `FLOAT64` minimum value for Y.
* `xmax`: `FLOAT64` maximum value for X.
* `ymax`: `FLOAT64` maximum value for Y.

**Return type**

`GEOGRAPHY`

**Example**

``` sql
SELECT bqcarto.constructors.ST_MAKEENVELOPE(0,0,1,1);
-- POLYGON((1 0, 1 1, 0 1, 0 0, 1 0))
```

### ST_TILEENVELOPE

{{% bannerNote type="code" %}}
constructors.ST_TILEENVELOPE(zoomLevel, xTile, yTile)
{{%/ bannerNote %}}

**Description**
Returns the boundary polygon of a tile given its zoom level and its X and Y indices.

* `zoomLevel`: `INT64` zoom level of the tile.
* `xTile`: `INT64` X index of the tile.
* `yTile`: `INT64` Y index of the tile.

**Return type**

`GEOGRAPHY`

**Example**

``` sql
SELECT bqcarto.constructors.ST_TILEENVELOPE(10,384,368);
-- POLYGON((-45 45.089035564831, -45 44.840290651398, -44.82421875 44.840290651398, -44.6484375 44.840290651398, -44.6484375 45.089035564831, -44.82421875 45.089035564831, -45 45.089035564831))
```

### VERSION

{{% bannerNote type="code" %}}
constructors.VERSION()
{{%/ bannerNote %}}

**Description**

Returns the current version of the constructors module.

**Return type**

`STRING`

**Example**

```sql
SELECT bqcarto.constructors.VERSION();
-- 1.1.0
```
99 changes: 99 additions & 0 deletions app/content/spatial-extension-bq/sql-reference/measurements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
## measurements

<div class="badge core"></div>

### ST_ANGLE

{{% bannerNote type="code" %}}
measurements.ST_ANGLE(startPoint, midPoint, endPoint, mercator)
{{%/ bannerNote %}}

**Description**

Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise) angle with origin on the startPoint-midPoint segment, or its explementary angle if required. https://github.com/Turfjs/turf/tree/master/packages/turf-angle

* `startPoint`: `GEOGRAPHY` start Point Coordinates.
* `midPoint`: `GEOGRAPHY` mid Point Coordinates.
* `endPoint`: `GEOGRAPHY` end Point Coordinates.
* `mercator`: `BOOLEAN`|`NULL` if calculations should be performed over Mercator or WGS84 projection. If `NULL` the default value `false` is used.

**Return type**

`FLOAT64`

**Example**

``` sql
SELECT bqcarto.measurements.ST_ANGLE(ST_GEOGPOINT(-3.70325 ,40.4167), ST_GEOGPOINT(-4.70325 ,10.4167), ST_GEOGPOINT(-5.70325 ,40.4167), false);
-- 3.933094586038578
```

### ST_AZIMUTH

{{% bannerNote type="code" %}}
measurements.ST_AZIMUTH(startPoint, endPoint)
{{%/ bannerNote %}}

**Description**

Takes two points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north line (0 degrees). https://turfjs.org/docs/#bearing

* `startPoint`: `GEOGRAPHY` starting Point.
* `endPoint`: `GEOGRAPHY` ending Point.

**Return type**

`FLOAT64`

**Example**

``` sql
SELECT bqcarto.measurements.ST_AZIMUTH(ST_GEOGPOINT(-3.70325 ,40.4167), ST_GEOGPOINT(-4.70325 ,41.4167));
-- -36.75052908494255
```

### ST_MINKOWSKIDISTANCE

{{% bannerNote type="code" %}}
measurements.ST_MINKOWSKIDISTANCE(geog, p)
{{%/ bannerNote %}}

**Description**

Calculate the Minkowski p-norm distance between two features. https://github.com/Turfjs/turf/tree/master/packages/turf-distance-weight

* `geog`: `ARRAY<GEOGRAPHY>` featureCollection.
* `p`: `FLOAT64` minkowski p-norm distance parameter. 1: Manhattan distance. 2: Euclidean distance. 1 =< p <= infinity. If `NULL` the default value `2` is used.

**Return type**

`ARRAY<STRING>`

**Example**

``` sql
SELECT bqcarto.measurements.ST_MINKOWSKIDISTANCE([ST_GEOGPOINT(10,10),ST_GEOGPOINT(13,10)],2);
-- ["0,0.3333333333333333","0.3333333333333333,0"]
```


### VERSION

{{% bannerNote type="code" %}}
measurements.VERSION()
{{%/ bannerNote %}}

**Description**

Returns the current version of the measurements module.

**Return type**

`STRING`

**Example**

```sql
SELECT bqcarto.measurements.VERSION();
-- 1.0.0
```
2 changes: 1 addition & 1 deletion app/content/spatial-extension-bq/sql-reference/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The CARTO Spatial Extension's procedures and functions are organized in modules
| Placekey | Core | <ul style="list-style:none"><li><a href="../placekey/#h3_asplacekey">H3_ASPLACEKEY</a></li><li><a href="../placekey/#placekey_ash3">PLACEKEY_ASH3</a></li><li><a href="../placekey/#isvalid">ISVALID</a></li><li><a href="../placekey/#version">VERSION</a></li></ul>|
| Random | Advanced | <ul style="list-style:none"><li><a href="../random/#st_generatepoints">ST_GENERATEPOINTS</a></li></li><li><a href="../random/#version">VERSION</a></li></ul>|
| Data | Advanced | <ul style="list-style:none"><li><a href="../data/#st_getpopulationdensity">ST_GETPOPULATIONDENSITY</a></li></li><li><a href="../data/#version">VERSION</a></li></ul>|
| Transformation | Core | <ul style="list-style:none"><li><a href="../transformation/#st_buffer">ST_BUFFER</a></li></li><li><a href="../transformation/#version">VERSION</a></li></ul>|
| Transformations | Core | <ul style="list-style:none"><li><a href="../transformations/#st_buffer">ST_BUFFER</a></li></li><li><a href="../transformations/#version">VERSION</a></li></ul>|

### Release notes

Expand Down
50 changes: 0 additions & 50 deletions app/content/spatial-extension-bq/sql-reference/transformation.md

This file was deleted.

Loading

0 comments on commit 3121397

Please sign in to comment.