

 Amazon Redshift will no longer support the creation of new Python UDFs starting Patch 198. Existing Python UDFs will continue to function until June 30, 2026. For more information, see the [ blog post ](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# Spatial functions
<a name="geospatial-functions"></a>

Relationships between geometry objects are based on the Dimensionally Extended nine-Intersection Model (DE-9IM). This model defines predicates such as equals, contains, and covers. For more information about the definition of spatial relationships, see [DE-9IM](https://en.wikipedia.org/wiki/DE-9IM) in Wikipedia.

For more information about how to use spatial data with Amazon Redshift, see [Querying spatial data in Amazon Redshift](geospatial-overview.md).

Amazon Redshift provides spatial functions that work with `GEOMETRY` and `GEOGRAPHY` data types. The following lists the functions that support the `GEOGRAPHY` data type:
+ [ST\$1Area](ST_Area-function.md)
+ [ST\$1AsEWKT](ST_AsEWKT-function.md)
+ [ST\$1AsGeoJSON](ST_AsGeoJSON-function.md)
+ [ST\$1AsHexEWKB](ST_AsHexEWKB-function.md)
+ [ST\$1AsHexWKB](ST_AsHexWKB-function.md)
+ [ST\$1AsText](ST_AsText-function.md)
+ [ST\$1Distance](ST_Distance-function.md)
+ [ST\$1GeogFromText](ST_GeogFromText-function.md)
+ [ST\$1GeogFromWKB](ST_GeogFromWKB-function.md)
+ [ST\$1Length](ST_Length-function.md)
+ [ST\$1NPoints](ST_NPoints-function.md)
+ [ST\$1Perimeter](ST_Perimeter-function.md)

The following lists the full set of spatial functions supported by Amazon Redshift. 

**Topics**
+ [

# AddBBox
](AddBBox-function.md)
+ [

# DropBBox
](DropBBox-function.md)
+ [

# GeometryType
](GeometryType-function.md)
+ [

# H3\$1Boundary
](H3_Boundary-function.md)
+ [

# H3\$1Center
](H3_Center-function.md)
+ [

# H3\$1FromLongLat
](H3_FromLongLat-function.md)
+ [

# H3\$1FromPoint
](H3_FromPoint-function.md)
+ [

# H3\$1IsValid
](H3_IsValid-function.md)
+ [

# H3\$1Polyfill
](H3_Polyfill-function.md)
+ [

# H3\$1Resolution
](H3_Resolution-function.md)
+ [

# H3\$1ToChildren
](H3_ToChildren-function.md)
+ [

# H3\$1ToParent
](H3_ToParent-function.md)
+ [

# ST\$1AddPoint
](ST_AddPoint-function.md)
+ [

# ST\$1Angle
](ST_Angle-function.md)
+ [

# ST\$1Area
](ST_Area-function.md)
+ [

# ST\$1AsBinary
](ST_AsBinary-function.md)
+ [

# ST\$1AsEWKB
](ST_AsEWKB-function.md)
+ [

# ST\$1AsEWKT
](ST_AsEWKT-function.md)
+ [

# ST\$1AsGeoJSON
](ST_AsGeoJSON-function.md)
+ [

# ST\$1AsHexWKB
](ST_AsHexWKB-function.md)
+ [

# ST\$1AsHexEWKB
](ST_AsHexEWKB-function.md)
+ [

# ST\$1AsText
](ST_AsText-function.md)
+ [

# ST\$1Azimuth
](ST_Azimuth-function.md)
+ [

# ST\$1Boundary
](ST_Boundary-function.md)
+ [

# ST\$1Buffer
](ST_Buffer-function.md)
+ [

# ST\$1Centroid
](ST_Centroid-function.md)
+ [

# ST\$1Collect
](ST_Collect-function.md)
+ [

# ST\$1Contains
](ST_Contains-function.md)
+ [

# ST\$1ContainsProperly
](ST_ContainsProperly-function.md)
+ [

# ST\$1ConvexHull
](ST_ConvexHull-function.md)
+ [

# ST\$1CoveredBy
](ST_CoveredBy-function.md)
+ [

# ST\$1Covers
](ST_Covers-function.md)
+ [

# ST\$1Crosses
](ST_Crosses-function.md)
+ [

# ST\$1Dimension
](ST_Dimension-function.md)
+ [

# ST\$1Disjoint
](ST_Disjoint-function.md)
+ [

# ST\$1Distance
](ST_Distance-function.md)
+ [

# ST\$1DistanceSphere
](ST_DistanceSphere-function.md)
+ [

# ST\$1DWithin
](ST_DWithin-function.md)
+ [

# ST\$1EndPoint
](ST_EndPoint-function.md)
+ [

# ST\$1Envelope
](ST_Envelope-function.md)
+ [

# ST\$1Equals
](ST_Equals-function.md)
+ [

# ST\$1ExteriorRing
](ST_ExteriorRing-function.md)
+ [

# ST\$1Force2D
](ST_Force2D-function.md)
+ [

# ST\$1Force3D
](ST_Force3D-function.md)
+ [

# ST\$1Force3DM
](ST_Force3DM-function.md)
+ [

# ST\$1Force3DZ
](ST_Force3DZ-function.md)
+ [

# ST\$1Force4D
](ST_Force4D-function.md)
+ [

# ST\$1GeoHash
](ST_GeoHash-function.md)
+ [

# ST\$1GeogFromText
](ST_GeogFromText-function.md)
+ [

# ST\$1GeogFromWKB
](ST_GeogFromWKB-function.md)
+ [

# ST\$1GeometryN
](ST_GeometryN-function.md)
+ [

# ST\$1GeometryType
](ST_GeometryType-function.md)
+ [

# ST\$1GeomFromEWKB
](ST_GeomFromEWKB-function.md)
+ [

# ST\$1GeomFromEWKT
](ST_GeomFromEWKT-function.md)
+ [

# ST\$1GeomFromGeoHash
](ST_GeomFromGeoHash-function.md)
+ [

# ST\$1GeomFromGeoJSON
](ST_GeomFromGeoJSON-function.md)
+ [

# ST\$1GeomFromGeoSquare
](ST_GeomFromGeoSquare-function.md)
+ [

# ST\$1GeomFromText
](ST_GeomFromText-function.md)
+ [

# ST\$1GeomFromWKB
](ST_GeomFromWKB-function.md)
+ [

# ST\$1GeoSquare
](ST_GeoSquare-function.md)
+ [

# ST\$1InteriorRingN
](ST_InteriorRingN-function.md)
+ [

# ST\$1Intersects
](ST_Intersects-function.md)
+ [

# ST\$1Intersection
](ST_Intersection-function.md)
+ [

# ST\$1IsPolygonCCW
](ST_IsPolygonCCW-function.md)
+ [

# ST\$1IsPolygonCW
](ST_IsPolygonCW-function.md)
+ [

# ST\$1IsClosed
](ST_IsClosed-function.md)
+ [

# ST\$1IsCollection
](ST_IsCollection-function.md)
+ [

# ST\$1IsEmpty
](ST_IsEmpty-function.md)
+ [

# ST\$1IsRing
](ST_IsRing-function.md)
+ [

# ST\$1IsSimple
](ST_IsSimple-function.md)
+ [

# ST\$1IsValid
](ST_IsValid-function.md)
+ [

# ST\$1Length
](ST_Length-function.md)
+ [

# ST\$1LengthSphere
](ST_LengthSphere-function.md)
+ [

# ST\$1Length2D
](ST_Length2D-function.md)
+ [

# ST\$1LineFromMultiPoint
](ST_LineFromMultiPoint-function.md)
+ [

# ST\$1LineInterpolatePoint
](ST_LineInterpolatePoint-function.md)
+ [

# ST\$1M
](ST_M-function.md)
+ [

# ST\$1MakeEnvelope
](ST_MakeEnvelope-function.md)
+ [

# ST\$1MakeLine
](ST_MakeLine-function.md)
+ [

# ST\$1MakePoint
](ST_MakePoint-function.md)
+ [

# ST\$1MakePolygon
](ST_MakePolygon-function.md)
+ [

# ST\$1MemSize
](ST_MemSize-function.md)
+ [

# ST\$1MMax
](ST_MMax-function.md)
+ [

# ST\$1MMin
](ST_MMin-function.md)
+ [

# ST\$1Multi
](ST_Multi-function.md)
+ [

# ST\$1NDims
](ST_NDims-function.md)
+ [

# ST\$1NPoints
](ST_NPoints-function.md)
+ [

# ST\$1NRings
](ST_NRings-function.md)
+ [

# ST\$1NumGeometries
](ST_NumGeometries-function.md)
+ [

# ST\$1NumInteriorRings
](ST_NumInteriorRings-function.md)
+ [

# ST\$1NumPoints
](ST_NumPoints-function.md)
+ [

# ST\$1Perimeter
](ST_Perimeter-function.md)
+ [

# ST\$1Perimeter2D
](ST_Perimeter2D-function.md)
+ [

# ST\$1Point
](ST_Point-function.md)
+ [

# ST\$1PointN
](ST_PointN-function.md)
+ [

# ST\$1Points
](ST_Points-function.md)
+ [

# ST\$1Polygon
](ST_Polygon-function.md)
+ [

# ST\$1RemovePoint
](ST_RemovePoint-function.md)
+ [

# ST\$1Reverse
](ST_Reverse-function.md)
+ [

# ST\$1SetPoint
](ST_SetPoint-function.md)
+ [

# ST\$1SetSRID
](ST_SetSRID-function.md)
+ [

# ST\$1Simplify
](ST_Simplify-function.md)
+ [

# ST\$1SRID
](ST_SRID-function.md)
+ [

# ST\$1StartPoint
](ST_StartPoint-function.md)
+ [

# ST\$1Touches
](ST_Touches-function.md)
+ [

# ST\$1Transform
](ST_Transform-function.md)
+ [

# ST\$1Union
](ST_Union-function.md)
+ [

# ST\$1Within
](ST_Within-function.md)
+ [

# ST\$1X
](ST_X-function.md)
+ [

# ST\$1XMax
](ST_XMax-function.md)
+ [

# ST\$1XMin
](ST_XMin-function.md)
+ [

# ST\$1Y
](ST_Y-function.md)
+ [

# ST\$1YMax
](ST_YMax-function.md)
+ [

# ST\$1YMin
](ST_YMin-function.md)
+ [

# ST\$1Z
](ST_Z-function.md)
+ [

# ST\$1ZMax
](ST_ZMax-function.md)
+ [

# ST\$1ZMin
](ST_ZMin-function.md)
+ [

# SupportsBBox
](SupportsBBox-function.md)

# AddBBox
<a name="AddBBox-function"></a>

AddBBox returns a copy of the input geometry that supports encoding with a precomputed bounding box. For more information about support for bounding boxes, see [Bounding box](spatial-terminology.md#spatial-terminology-bounding-box).

## Syntax
<a name="AddBBox-function-syntax"></a>

```
AddBBox(geom)
```

## Arguments
<a name="AddBBox-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="AddBBox-function-return"></a>

`GEOMETRY`

If *geom* is null, then null is returned.

## Examples
<a name="AddBBox-function-examples"></a>

The following SQL returns a copy of an input polygon geometry that supports being encoded with a bounding box. 

```
SELECT ST_AsText(AddBBox(ST_GeomFromText('POLYGON((0 0,1 0,0 1,0 0))')));
```

```
 st_astext
----------
 POLYGON((0 0,1 0,0 1,0 0))
```

# DropBBox
<a name="DropBBox-function"></a>

DropBBox returns a copy of the input geometry that doesn't support encoding with a precomputed bounding box. For more information about support for bounding boxes, see [Bounding box](spatial-terminology.md#spatial-terminology-bounding-box).

## Syntax
<a name="DropBBox-function-syntax"></a>

```
DropBBox(geom)
```

## Arguments
<a name="DropBBox-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="DropBBox-function-return"></a>

`GEOMETRY`

If *geom* is null, then null is returned.

## Examples
<a name="DropBBox-function-examples"></a>

The following SQL returns a copy of an input polygon geometry that doesn't support being encoded with a bounding box. 

```
SELECT ST_AsText(DropBBox(ST_GeomFromText('POLYGON((0 0,1 0,0 1,0 0))')));
```

```
 st_astext
----------
 POLYGON((0 0,1 0,0 1,0 0))
```

# GeometryType
<a name="GeometryType-function"></a>

GeometryType returns the subtype of an input geometry as a string. 

## Syntax
<a name="GeometryType-function-syntax"></a>

```
GeometryType(geom)
```

## Arguments
<a name="GeometryType-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="GeometryType-function-return"></a>

`VARCHAR` representing the subtype of *geom*. 

If *geom* is null, then null is returned. 

The values returned are as follows.


| Returned string value for 2D, 3DZ, 4D geometries | Returned string value for 3DM geometries | Geometry subtype | 
| --- | --- | --- | 
| `POINT` | `POINTM` | Returned if *geom* is a `POINT` subtype  | 
| `LINESTRING` | `LINESTRINGM` | Returned if *geom* is a `LINESTRING` subtype  | 
| `POLYGON` | `POLYGONM` | Returned if *geom* is a `POLYGON` subtype  | 
| `MULTIPOINT` | `MULTIPOINTM` | Returned if *geom* is a `MULTIPOINT` subtype  | 
| `MULTILINESTRING` | `MULTILINESTRINGM` | Returned if *geom* is a `MULTILINESTRING` subtype  | 
| `MULTIPOLYGON` | `MULTIPOLYGONM` | Returned if *geom* is a `MULTIPOLYGON` subtype  | 
| `GEOMETRYCOLLECTION` | `GEOMETRYCOLLECTIONM` | Returned if *geom* is a `GEOMETRYCOLLECTION` subtype  | 

## Examples
<a name="GeometryType-function-examples"></a>

The following SQL converts a well-known text (WKT) representation of a polygon and returns the `GEOMETRY` subtype as a string.

```
SELECT GeometryType(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'));
```

```
geometrytype
-------------
 POLYGON
```

# H3\$1Boundary
<a name="H3_Boundary-function"></a>

H3\$1Boundary returns the boundary of an H3 cell ID from an input index. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_Boundary-function-syntax"></a>

```
H3_Boundary(index)
```

## Arguments
<a name="H3_Boundary-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR` that represents the index of an H3 cell. Or, an expression that evaluates to one of these data types.

## Return type
<a name="H3_Boundary-function-return"></a>

`POLYGON` – represents the polygon with spatial reference system identifier (SRID) of `0`.

If *index* is not valid, then an error is returned.

## Examples
<a name="H3_Boundary-function-examples"></a>

The following SQL inputs a `VARCHAR` that represents the index of an H3 cell, and returns a POLYGON with SRID 0 that represents the boundary of the input H3 cell. The output of H3\$1Boundary is input to ST\$1AwEWKT to display in extended well-known text (EWKT) representation.

```
SELECT ST_AsEWKT(H3_Boundary('8025fffffffffff'));
```

```
 st_asewkt
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POLYGON((87.7729641223953 52.6542030078627,86.7082098104731 40.3127667561966,98.2285042557705 33.6210697806835,110.694610548823 37.163896485796,116.212895637138 47.3094513028131,106.40349563788 56.210610737585,87.7729641223953 52.6542030078627))
```

The following SQL inputs a `BIGINT` that represents the index of an H3 cell, and returns a POLYGON with SRID 0 that represents the boundary of the input H3 cell. The output of H3\$1Boundary is input to ST\$1AwEWKT to display in extended well-known text (EWKT) representation.

```
SELECT ST_AsEWKT(H3_Boundary(577129255373111295)); 
```

```
 st_asewkt
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON((87.7729641223953 52.6542030078627,86.7082098104731 40.3127667561966,98.2285042557705 33.6210697806835,110.694610548823 37.163896485796,116.212895637138 47.3094513028131,106.40349563788 56.210610737585,87.7729641223953 52.6542030078627))
```

# H3\$1Center
<a name="H3_Center-function"></a>

H3\$1Center returns the centroid of an H3 cell ID from an input index. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_Center-function-syntax"></a>

```
H3_Center(index)
```

## Arguments
<a name="H3_Center-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR` that represents the index of an H3 cell. Or, an expression that evaluates to one of these data types.

## Return type
<a name="H3_Center-function-return"></a>

`POINT` – represents the centroid of the H3 cell with spatial reference system identifier (SRID) of `0`.

If *index* is not valid, then an error is returned.

## Examples
<a name="H3_Center-function-examples"></a>

The following SQL inputs a `VARCHAR` that represents the index of an H3 cell, and returns a POINT with SRID of 0 that represents the centroid of the input H3 cell.

```
SELECT H3_Center('8025fffffffffff');
```

```
 h3_center
--------------------------------------------
 010100000070707A550B605940AEE9D70B327E4640
```

The following SQL inputs a `BIGINT` that represents the index of an H3 cell, and returns a POINT with SRID 0 that represents the centroid of the input H3 cell.

```
SELECT H3_Center(577129255373111295);
```

```
 h3_center
--------------------------------------------
 010100000070707A550B605940AEE9D70B327E4640
```

The following SQL inputs a `VARCHAR` that represents the index of an H3 cell, and returns a POINT with SRID 0 that represents the centroid of the input H3 cell. The output of H3\$1Center is input to ST\$1AwEWKT to display in extended well-known text (EWKT) representation.

```
SELECT ST_AsEWKT(H3_Center('8075fffffffffff'));
```

```
 st_asewkt
-----------------------------------------
POINT(-5.24539029677733 2.30088211162675)
```

# H3\$1FromLongLat
<a name="H3_FromLongLat-function"></a>

H3\$1FromLongLat returns the corresponding H3 cell ID from an input longitude, latitude, and resolution. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_FromLongLat-function-syntax"></a>

```
H3_FromLongLat(longitude, latitude, resolution)
```

## Arguments
<a name="H3_FromLongLat-function-arguments"></a>

 *longitude*   
A value of data type `DOUBLE PRECISION` or an expression that evaluates to a `DOUBLE PRECISION` type.

 *latitude*   
A value of data type `DOUBLE PRECISION` or an expression that evaluates to a `DOUBLE PRECISION` type.

 *resolution*   
A value of data type `INTEGER` or an expression that evaluates to an `INTEGER` type. The value represents the resolution of the H3 grid system. The value must be an integer between 0–15, inclusive. With `0` being the coarsest and `15` being the finest. 

## Return type
<a name="H3_FromLongLat-function-return"></a>

`BIGINT` – represents the H3 cell ID.

If *resolution* is out of bounds, then an error is returned.

## Examples
<a name="H3_FromLongLat-function-examples"></a>

The following SQL returns the H3 cell ID from longitude `0`, latitude `0`, and resolution `10`. 

```
SELECT H3_FromLongLat(0, 0, 10);
```

```
 h3_fromlonglat
-------------------
 623560421467684863
```

# H3\$1FromPoint
<a name="H3_FromPoint-function"></a>

H3\$1FromPoint returns the corresponding H3 cell ID from an input geometry point and resolution. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_FromPoint-function-syntax"></a>

```
H3_FromPoint(geom, resolution)
```

## Arguments
<a name="H3_FromPoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The *geom* must be a `POINT`.

 *resolution*   
A value of data type `INTEGER` or an expression that evaluates to an `INTEGER` type. The value represents the resolution of the H3 grid system. The value must be an integer between 0–15, inclusive. With `0` being the coarsest and `15` being the finest. 

## Return type
<a name="H3_FromPoint-function-return"></a>

`BIGINT` – represents the H3 cell ID.

If *geom* is not a `POINT`, then an error is returned.

If *resolution* is out of bounds, then an error is returned.

If *geom* is empty, then NULL is returned.

## Examples
<a name="H3_FromPoint-function-examples"></a>

The following SQL returns the H3 cell ID from point `0,0`, and resolution `10`. 

```
SELECT H3_FromPoint(ST_GeomFromText('POINT(0 0)'), 10);
```

```
 h3_frompoint
-------------------
 623560421467684863
```

# H3\$1IsValid
<a name="H3_IsValid-function"></a>

H3\$1IsValid returns true if the input represents an H3 cell ID, otherwise false. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_IsValid-function-syntax"></a>

```
H3_IsValid(index)
```

## Arguments
<a name="H3_IsValid-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR`, or an expression that evaluates to one of these data types.

## Return type
<a name="H3_IsValid-function-return"></a>

`BOOLEAN` – true if the input represents a valid H3 cell ID, false otherwise.

If *index* is NULL, then NULL is returned.

## Examples
<a name="H3_IsValid-function-examples"></a>

The following SQL inputs a VARCHAR that represents an H3 cell ID, and returns true.

```
SELECT H3_IsValid('8025fffffffffff');
```

```
 h3_isvalid
------------
 true
```

The following SQL inputs a BIGINT that represents an H3 cell ID, and returns true.

```
SELECT H3_IsValid(577129255373111295);
```

```
 h3_isvalid
------------
 true
```

The following SQL inputs an invalid H3 cell ID and returns false.

```
SELECT H3_IsValid('');
```

```
 h3_isvalid
------------
 false
```

# H3\$1Polyfill
<a name="H3_Polyfill-function"></a>

H3\$1Polyfill returns the corresponding H3 cell IDs that correspond to the hexagons and pentagons that are contained in the input polygon of the given resolution. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_Polyfill-function-syntax"></a>

```
H3_Polyfill(geom, resolution)
```

## Arguments
<a name="H3_Polyfill-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The *geom* must be a `POLYGON`.

 *resolution*   
A value of data type `INTEGER` or an expression that evaluates to an `INTEGER` type. The value represents the resolution of the H3 grid system. The value must be an integer between 0–15, inclusive. With `0` being the coarsest and `15` being the finest. 

## Return type
<a name="H3_Polyfill-function-return"></a>

`SUPER` – represents a list of H3 cell IDs.

If *geom* is not a `POLYGON`, then an error is returned.

If *resolution* is out of bounds, then an error is returned.

If *geom* is empty, then NULL is returned.

## Examples
<a name="H3_Polyfill-function-examples"></a>

The following SQL returns a SUPER data type array of H3 cell IDs from a polygon and resolution `4`. 

```
SELECT H3_Polyfill(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'), 4);
```

```
 h3_polyfill
----------------------------------------------------------------------------------------------------------------------------------------------------------
 [596538848238895103,596538805289222143,596538856828829695,596538813879156735,596537920525959167,596538685030137855,596538693620072447,596538839648960511]
```

# H3\$1Resolution
<a name="H3_Resolution-function"></a>

H3\$1Resolution returns the resolution of an H3 cell ID from an input index. Resolution is an integer from 0 (coarsest) to 15 (finest). For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_Resolution-function-syntax"></a>

```
H3_Resolution(index)
```

## Arguments
<a name="H3_Resolution-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR` that represents the index of an H3 cell, or an expression that evaluates to one of these data types.

## Return type
<a name="H3_Resolution-function-return"></a>

`INTEGER` – represents the resolution of the input H3 cell ID.

If *index* is NULL, then NULL is returned.

If *index* is not valid, then an error is returned.

## Examples
<a name="H3_Resolution-function-examples"></a>

The following SQL inputs a VARCHAR that represents the index of an H3 cell, and returns an INTEGER that represents the resolution of the input H3 cell.

```
SELECT H3_Resolution('8025fffffffffff');
```

```
 h3_resolution
---------------
 0
```

The following SQL inputs a BIGINT that represents the index of an H3 cell, and returns an INTEGER that represents the resolution of the input H3 cell.

```
SELECT H3_Resolution(614553222213795839);
```

```
 h3_resolution
---------------
 8
```

# H3\$1ToChildren
<a name="H3_ToChildren-function"></a>

H3\$1ToChildren returns a list of child H3 cell IDs at a specified resolution for a given H3 index. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_ToChildren-function-syntax"></a>

```
H3_ToChildren(index, resolution)
```

## Arguments
<a name="H3_ToChildren-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR` that represents the index of an H3 cell, or an expression that evaluates to one of these data types.

 *resolution*   
A value of data type `INTEGER` or an expression that evaluates to an `INTEGER` type. The value represents the resolution of the children cell IDs. The value must be an integer between the resolution of the input *index* and 15, inclusive.

## Return type
<a name="H3_ToChildren-function-return"></a>

`SUPER` – represents a list of H3 cell IDs.

If either *index* or *resolution* is NULL, then NULL is returned.

If *index* is not valid, then an error is returned.

If *resolution* is not between the resolution of *index* and 15, inclusive, then an error is returned.

If the output size exceeds the maximum SUPER size limit, then an error is returned.

## Examples
<a name="H3_ToChildren-function-examples"></a>

The following SQL inputs a VARCHAR that represents the index of an H3 cell, and an INTEGER that represents the desired resolution of all the children, and returns a SUPER array containing the children at resolution 6.

```
SELECT H3_ToChildren('85283473fffffff', 6);
```

```
 h3_tochildren                                                
--------------------------------------------------------------------------------------------------------------------------------------
 [604189641121202175,604189641255419903,604189641389637631,604189641523855359,604189641658073087,604189641792290815,604189641926508543]
```

The following SQL inputs a BIGINT that represents the index of an H3 cell, and an INTEGER that represents the desired resolution of all the children, and returns a SUPER array containing the children at resolution 6.

```
SELECT H3_ToChildren(599686042433355775, 6);
```

```
 h3_tochildren                                              
--------------------------------------------------------------------------------------------------------------------------------------
 [604189641121202175,604189641255419903,604189641389637631,604189641523855359,604189641658073087,604189641792290815,604189641926508543]
```

Note: A difference of 7 or less between *resolution* and *index* resolution is safe.

The following example demonstrates a workaround for queries that exceed the SUPER size limit. When the resolution difference between the input H3 index and the desired child resolution is too large (greater than 7). This procedure solves the problem by incrementally expanding children in smaller steps (maximum 5 resolution levels at a time) and storing the final results in a user-created table.

```
CREATE OR REPLACE PROCEDURE generate_h3_children()
LANGUAGE plpgsql
AS $$
BEGIN
    -- Drop and create h3_children table that will contain the results
    DROP TABLE IF EXISTS h3_children;
    CREATE TABLE h3_children (
        h3_index BIGINT,
        child_res INTEGER,
        children SUPER
    );

    -- Create temporary table for steps
    DROP TABLE IF EXISTS h3_steps;
    CREATE TABLE h3_steps (
        h3_index BIGINT,
        current_res INTEGER,
        target_res INTEGER,
        h3_array SUPER
    );

    -- Initial insert into h3_steps
    INSERT INTO h3_steps
    SELECT h3_index, H3_Resolution(h3_index), child_res, ARRAY(h3_index)
    FROM h3_indexes; -- Insert from your table with h3_index and child_res as columns

    -- Loop until we reach target resolution
    -- We expect at most 3 iterations considering that we can start at resolution
    -- 0 and target/child resolution equal to 15 (0 -> 5 -> 10 -> 15)
    WHILE EXISTS (
        SELECT 1
        FROM h3_steps h
        GROUP BY h3_index, target_res
        HAVING MAX(current_res) < target_res
    ) LOOP
        -- Populate the h3_steps table with the tables that need to
        -- reach closer to the target res
        INSERT INTO h3_steps
        SELECT
            h.h3_index,
            LEAST(h.current_res + 5, h.target_res), -- Do not exceed target res
            h.target_res,
            -- Take the children of the child cell at resolution current_res of the
            -- h3_index
            H3_ToChildren(c.child::BIGINT, LEAST(h.current_res + 5, h.target_res))
        FROM h3_steps h, UNNEST(h.h3_array) AS c(child)
        WHERE h.current_res < h.target_res
        AND h.current_res = (SELECT MAX(current_res)
                           FROM h3_steps
                           WHERE h3_index = h.h3_index
        );
    END LOOP;

    -- Store final results
    INSERT INTO h3_children
    SELECT h3_index AS h3_index, target_res AS child_res, h3_array AS children
    FROM h3_steps
    WHERE current_res = target_res;
END;
$$;

-- Create the source table for H3_ToChildren queries
CREATE TABLE h3_indexes (
    h3_index BIGINT,
    child_res INTEGER,
    PRIMARY KEY (h3_index, child_res)
);
INSERT INTO h3_indexes (h3_index, child_res)
VALUES (x'8001fffffffffff'::BIGINT, 11);

-- Execute the procedure
CALL generate_h3_children();

-- View results
SELECT * FROM h3_children;
```

# H3\$1ToParent
<a name="H3_ToParent-function"></a>

H3\$1ToParent returns the parent H3 cell ID at a specified parent resolution for a given H3 index. For information about H3 indexing, see [H3](spatial-terminology.md#spatial-terminology-h3).

## Syntax
<a name="H3_ToParent-function-syntax"></a>

```
H3_ToParent(index, resolution)
```

## Arguments
<a name="H3_ToParent-function-arguments"></a>

 *index*   
A value of data type `BIGINT` or `VARCHAR` that represents the index of an H3 cell, or an expression that evaluates to one of these data types.

 *resolution*   
A value of data type `INTEGER` or an expression that evaluates to an `INTEGER` type. The value represents the resolution of the parent cell ID. The value must be between 0 and the resolution of *index*, inclusive.

## Return type
<a name="H3_ToParent-function-return"></a>

`BIGINT` – represents the parent's H3 cell ID.

If either *index* or *resolution* is NULL, then NULL is returned.

If *index* is not valid, then an error is returned.

If *resolution* is less than 0 or greater than the resolution of *index*, then an error is returned.

## Examples
<a name="H3_ToParent-function-examples"></a>

The following SQL inputs a VARCHAR that represents the index of an H3 cell, and an INTEGER that represents the desired resolution of the desired parent, and returns a BIGINT that represents the parent at resolution 0 of the input H3 cell.

```
SELECT H3_ToParent('85283473fffffff', 0);
```

```
 h3_toparent
--------------------
 577199624117288959
```

The following SQL inputs a BIGINT that represents the index of an H3 cell, and an INTEGER that represents the desired resolution of the desired parent, and returns a BIGINT that represents the parent at resolution 0 of the input H3 cell.

```
SELECT H3_ToParent(646078419604526808, 8);
```

```
 h3_toparent
--------------------
 614553222213795839
```

# ST\$1AddPoint
<a name="ST_AddPoint-function"></a>

ST\$1AddPoint returns a linestring geometry that is the same as the input geometry with a point added. If an index is provided, then the point is added at the index position. If the index is -1 or not provided, then the point is appended to the linestring. 

The index is zero-based. The spatial reference system identifier (SRID) of the result is the same as that of the input geometry. 

The dimension of the returned geometry is the same as that of the *geom1* value. If *geom1* and *geom2* have different dimensions, *geom2* is projected to the dimension of *geom1*.

## Syntax
<a name="ST_AddPoint-function-syntax"></a>

```
ST_AddPoint(geom1, geom2)
```

```
ST_AddPoint(geom1, geom2, index)
```

## Arguments
<a name="ST_AddPoint-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. The point can be the empty point.

 *index*   
A value of data type `INTEGER` that represents the position of a zero-based index. 

## Return type
<a name="ST_AddPoint-function-return"></a>

`GEOMETRY` 

If *geom1*, *geom2*, or *index* is null, then null is returned. 

If *geom2* is the empty point, then a copy of *geom1* is returned. 

If *geom1* is not a `LINESTRING`, then an error is returned. 

If *geom2* is not a `POINT`, then an error is returned. 

If *index* is out of range, then an error is returned. Valid values for the index position are -1 or a value between 0 and `ST_NumPoints(geom1)`. 

## Examples
<a name="ST_AddPoint-function-examples"></a>

The following SQL adds a point to a linestring to make it a closed linestring. 

```
WITH tmp(g) AS (SELECT ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5)',4326))
SELECT ST_AsEWKT(ST_AddPoint(g, ST_StartPoint(g))) FROM tmp;
```

```
 st_asewkt
------------------------------------------------
 SRID=4326;LINESTRING(0 0,10 0,10 10,5 5,0 5,0 0)
```

The following SQL adds a point to a specific position in a linestring. 

```
WITH tmp(g) AS (SELECT ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5)',4326))
SELECT ST_AsEWKT(ST_AddPoint(g, ST_SetSRID(ST_Point(5, 10), 4326), 3)) FROM tmp;
```

```
 st_asewkt
------------------------------------------------
 SRID=4326;LINESTRING(0 0,10 0,10 10,5 10,5 5,0 5)
```

# ST\$1Angle
<a name="ST_Angle-function"></a>

ST\$1Angle returns the angle in radians between points measured clockwise as follows:
+ If three points are input, then the returned angle P1-P2-P3 is measured as if the angle was obtained by rotating from P1 to P3 around P2 clockwise. 
+ If four points are input, then the returned clockwise angle formed by the directed lines P1-P2 and P3-P4 is returned. If the input is a degenerate case (that is, P1 equals P2, or P3 equals P4), then null is returned. 

The return value is in radians and in the range [0, 2π). 

ST\$1Angle operates on 2D projections of the input geometries.

## Syntax
<a name="ST_Angle-function-syntax"></a>

```
ST_Angle(geom1, geom2, geom3)
```

```
ST_Angle(geom1, geom2, geom3, geom4)
```

## Arguments
<a name="ST_Angle-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. 

 *geom3*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. 

 *geom4*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. 

## Return type
<a name="ST_Angle-function-return"></a>

`DOUBLE PRECISION`. 

If *geom1* equals *geom2*, or *geom2* equals *geom3*, then a null is returned. 

If *geom1*, *geom2*, *geom3*, or *geom4* is null, then a null is returned. 

If any of *geom1*, *geom2*, *geom3*, or *geom4* is the empty point, then an error is returned. 

If *geom1*, *geom2*, *geom3*, and *geom4* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

## Examples
<a name="ST_Angle-function-examples"></a>

The following SQL returns the angle converted to degrees of three input points. 

```
SELECT ST_Angle(ST_Point(1,1), ST_Point(0,0), ST_Point(1,0)) / Pi() * 180.0 AS angle;
```

```
 angle
---------------
    45
```

The following SQL returns the angle converted to degrees of four input points. 

```
SELECT ST_Angle(ST_Point(1,1), ST_Point(0,0), ST_Point(1,0), ST_Point(2,0)) / Pi() * 180.0 AS angle;
```

```
 angle
---------------
   225
```

# ST\$1Area
<a name="ST_Area-function"></a>

For an input geometry, ST\$1Area returns the Cartesian area of the 2D projection. The area units are the same as the units in which the coordinates of the input geometry are expressed. For points, linestrings, multipoints, and multilinestrings, the function returns 0. For geometry collections, it returns the sum of the areas of the geometries in the collection. 

For an input geography, ST\$1Area returns the geodesic area of the 2D projection of an input areal geography computed on the spheroid determined by the SRID. The unit of length is in square meters. The function returns zero (0) for points, multipoints, and linear geographies. When the input is a geometry collection, the function returns the sum of the areas of the areal geographies in the collection.

## Syntax
<a name="ST_Area-function-syntax"></a>

```
ST_Area(geo)
```

## Arguments
<a name="ST_Area-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_Area-function-return"></a>

`DOUBLE PRECISION`

If *geo* is null, then null is returned.

## Examples
<a name="ST_Area-function-examples"></a>

The following SQL returns the Cartesian area of a multipolygon. 

```
SELECT ST_Area(ST_GeomFromText('MULTIPOLYGON(((0 0,10 0,0 10,0 0)),((10 0,20 0,20 10,10 0)))'));
```

```
 st_area
---------
     100
```

The following SQL returns the area of a polygon in a geography. 

```
SELECT ST_Area(ST_GeogFromText('polygon((34 35, 28 30, 25 34, 34 35))'));
```

```
     st_area
------------------
 201824655743.383
```

The following SQL returns zero for a linear geography. 

```
SELECT ST_Area(ST_GeogFromText('multipoint(0 0, 1 1, -21.32 121.2)'));
```

```
 st_area
---------
       0
```

# ST\$1AsBinary
<a name="ST_AsBinary-function"></a>

ST\$1AsBinary returns the hexadecimal well-known binary (WKB) representation of an input geometry. For 3DZ, 3DM, and 4D geometries, ST\$1AsBinary uses the Open Geospatial Consortium (OGC) standard value for the geometry type. 

## Syntax
<a name="ST_AsBinary-function-syntax"></a>

```
ST_AsBinary(geom)
```

## Arguments
<a name="ST_AsBinary-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_AsBinary-function-return"></a>

`VARBYTE`

If *geom* is null, then null is returned.

## Examples
<a name="ST_AsBinary-function-examples"></a>

The following SQL returns the hexadecimal WKB representation of a polygon. 

```
SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
```

```
st_asbinary
--------------------------------
01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

# ST\$1AsEWKB
<a name="ST_AsEWKB-function"></a>

ST\$1AsEWKB returns the extended well-known binary (EWKB) representation of an input geometry. For 3DZ, 3DM, and 4D geometries, ST\$1AsEWKB uses the Open Geospatial Consortium (OGC) standard value for the geometry type.

## Syntax
<a name="ST_AsEWKB-function-syntax"></a>

```
ST_AsEWKB(geom)
```

## Arguments
<a name="ST_AsEWKB-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_AsEWKB-function-return"></a>

`VARBYTE`

If *geom* is null, then null is returned.

## Examples
<a name="ST_AsEWKB-function-examples"></a>

The following SQL returns the hexadecimal EWKB representation of a polygon. 

```
SELECT ST_AsEWKB(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
```

```
st_asewkb
--------------------------------
0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

# ST\$1AsEWKT
<a name="ST_AsEWKT-function"></a>

ST\$1AsEWKT returns the extended well-known text (EWKT) representation of an input geometry or geography. For 3DZ, 3DM, and 4D geometries, ST\$1AsEWKT appends Z, M, or ZM to the WKT value for the geometry type.

## Syntax
<a name="ST_AsEWKT-function-syntax"></a>

```
ST_AsEWKT(geo)
```

```
ST_AsEWKT(geo, precision)
```

## Arguments
<a name="ST_AsEWKT-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

 *precision*   
A value of data type `INTEGER`. For geometries, the coordinates of *geo* are displayed using the specified precision 1–20. If *precision* is not specified, the default is 15. For geographies, the coordinates of *geo* are displayed using the specified precision. If *precision* is not specified, the default is 15.

## Return type
<a name="ST_AsEWKT-function-return"></a>

`VARCHAR`

If *geo* is null, then null is returned. 

If *precision* is null, then null is returned. 

If the result is larger than a 64-KB `VARCHAR`, then an error is returned. 

## Examples
<a name="ST_AsEWKT-function-examples"></a>

The following SQL returns the EWKT representation of a linestring. 

```
SELECT ST_AsEWKT(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)', 4326));
```

```
st_asewkt
--------------------------------
 SRID=4326;LINESTRING(3.14159265358979 -6.28318530717959,2.71828182845905 -1.41421356237309)
```

The following SQL returns the EWKT representation of a linestring. The coordinates of the geometries are displayed with six digits of precision. 

```
SELECT ST_AsEWKT(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)', 4326), 6);
```

```
st_asewkt
--------------------------------
 SRID=4326;LINESTRING(3.14159 -6.28319,2.71828 -1.41421)
```

The following SQL returns the EWKT representation of a geography. 

```
SELECT ST_AsEWKT(ST_GeogFromText('LINESTRING(110 40, 2 3, -10 80, -7 9)'));
```

```
                  st_asewkt
----------------------------------------------
 SRID=4326;LINESTRING(110 40,2 3,-10 80,-7 9)
```

# ST\$1AsGeoJSON
<a name="ST_AsGeoJSON-function"></a>

ST\$1AsGeoJSON returns the GeoJSON representation of an input geometry or geography. For more information about GeoJSON, see [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) in Wikipedia.

For 3DZ and 4D geometries, the output geometry is a 3DZ projection of the input 3DZ or 4D geometry. That is, the `x`, `y`, and `z` coordinates are present in the output. For 3DM geometries, the output geometry is a 2D projection of the input 3DM geometry. That is, only `x` and `y` coordinates are present in the output.

For input geographies, ST\$1AsGeoJSON returns the GeoJSON representation of an input geography. The coordinates of the geography are displayed using the specified precision. 

## Syntax
<a name="ST_AsGeoJSON-function-syntax"></a>

```
ST_AsGeoJSON(geo)
```

```
ST_AsGeoJSON(geo, precision)
```

## Arguments
<a name="ST_AsGeoJSON-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

 *precision*   
A value of data type `INTEGER`. For geometries, the coordinates of *geo* are displayed using the specified precision 1–20. If *precision* is not specified, the default is 15. For geographies, the coordinates of *geo* are displayed using the specified precision. If *precision* is not specified, the default is 15.

## Return type
<a name="ST_AsGeoJSON-function-return"></a>

`VARCHAR`

If *geo* is null, then null is returned. 

If *precision* is null, then null is returned. 

If the result is larger than a 64-KB `VARCHAR`, then an error is returned. 

## Examples
<a name="ST_AsGeoJSON-function-examples"></a>

The following SQL returns the GeoJSON representation of a linestring. 

```
SELECT ST_AsGeoJSON(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)'));
```

```
st_asgeojson
----------------------------------------------------------------------------------------------------------------
 {"type":"LineString","coordinates":[[3.14159265358979,-6.28318530717959],[2.71828182845905,-1.41421356237309]]}
```

The following SQL returns the GeoJSON representation of a linestring. The coordinates of the geometries are displayed with six digits of precision. 

```
SELECT ST_AsGeoJSON(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)'), 6);
```

```
st_asgeojson
-----------------------------------------------------------------------------
  {"type":"LineString","coordinates":[[3.14159,-6.28319],[2.71828,-1.41421]]}
```

The following SQL returns the GeoJSON representation of a geography. 

```
SELECT ST_AsGeoJSON(ST_GeogFromText('LINESTRING(110 40, 2 3, -10 80, -7 9)'));
```

```
                             st_asgeojson
----------------------------------------------------------------------
 {"type":"LineString","coordinates":[[110,40],[2,3],[-10,80],[-7,9]]}
```

# ST\$1AsHexWKB
<a name="ST_AsHexWKB-function"></a>

ST\$1AsHexWKB returns the hexadecimal well-known binary (WKB) representation of an input geometry or geography using ASCII hexadecimal characters (0–9, A–F). For 3DZ, 3DM, and 4D geometries or geographies, ST\$1AsHexWKB uses the Open Geospatial Consortium (OGC) standard value for the geometry or geography type. 

## Syntax
<a name="ST_AsHexWKB-function-syntax"></a>

```
ST_AsHexWKB(geo)
```

## Arguments
<a name="ST_AsHexWKB-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_AsHexWKB-function-return"></a>

`VARCHAR`

If *geo* is null, then null is returned.

If the result is larger than a 64-KB `VARCHAR`, then an error is returned. 

## Examples
<a name="ST_AsHexWKB-function-examples"></a>

The following SQL returns the hexadecimal WKB representation of a polygon in a geometry. 

```
SELECT ST_AsHexWKB(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
```

```
st_ashexwkb
--------------------------------
01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

The following SQL returns the hexadecimal WKB representation of a polygon in a geography. 

```
SELECT ST_AsHexWKB(ST_GeogFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))'));
```

```
st_ashexwkb
--------------------------------
01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

# ST\$1AsHexEWKB
<a name="ST_AsHexEWKB-function"></a>

ST\$1AsHexEWKB returns the extended well-known binary (EWKB) representation of an input geometry or geography using ASCII hexadecimal characters (0–9, A–F). For 3DZ, 3DM, and 4D geometries or geographies, ST\$1AsHexEWKB uses the PostGIS extended WKB value for the geometry or geography type.

## Syntax
<a name="ST_AsHexEWKB-function-syntax"></a>

```
ST_AsHexEWKB(geo)
```

## Arguments
<a name="ST_AsHexEWKB-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_AsHexEWKB-function-return"></a>

`VARCHAR`

If *geo* is null, then null is returned. 

If the result is larger than a 64-KB `VARCHAR`, then an error is returned. 

## Examples
<a name="ST_AsHexEWKB-function-examples"></a>

The following SQL returns the hexadecimal EWKB representation of a polygon in a geometry. 

```
SELECT ST_AsHexEWKB(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
```

```
st_ashexewkb
--------------------------------
0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

The following SQL returns the hexadecimal EWKB representation of a polygon in a geography. 

```
SELECT ST_AsHexEWKB(ST_GeogFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))'));
```

```
st_ashexewkb
--------------------------------
0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

# ST\$1AsText
<a name="ST_AsText-function"></a>

ST\$1AsText returns the well-known text (WKT) representation of an input geometry or geography. For 3DZ, 3DM, and 4D geometries or geographies, ST\$1AsEWKT appends Z, M, or ZM to the WKT value for the geometry or geography type.

## Syntax
<a name="ST_AsText-function-syntax"></a>

```
ST_AsText(geo)
```

```
ST_AsText(geo, precision)
```

## Arguments
<a name="ST_AsText-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

 *precision*   
A value of data type `INTEGER`. For geometries, the coordinates of *geo* are displayed using the specified precision 1–20. If *precision* is not specified, the default is 15. For geogpraphies, the coordinates of *geo* are displayed using the specified precision. If *precision* is not specified, the default is 15.

## Return type
<a name="ST_AsText-function-return"></a>

`VARCHAR`

If *geo* is null, then null is returned.

If *precision* is null, then null is returned.

If the result is larger than a 64-KB `VARCHAR`, then an error is returned. 

## Examples
<a name="ST_AsText-function-examples"></a>

The following SQL returns the WKT representation of a linestring. 

```
SELECT ST_AsText(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)', 4326));
```

```
st_astext
--------------------------------
LINESTRING(3.14159265358979 -6.28318530717959,2.71828182845905 -1.41421356237309)
```

The following SQL returns the WKT representation of a linestring. The coordinates of the geometries are displayed with six digits of precision. 

```
SELECT ST_AsText(ST_GeomFromText('LINESTRING(3.141592653589793 -6.283185307179586,2.718281828459045 -1.414213562373095)', 4326), 6);
```

```
st_astext
----------------------------------------------
 LINESTRING(3.14159 -6.28319,2.71828 -1.41421)
```

The following SQL returns the WKT representation of a geography. 

```
SELECT ST_AsText(ST_GeogFromText('LINESTRING(110 40, 2 3, -10 80, -7 9)'));
```

```
             st_astext
------------------------------------
 LINESTRING(110 40,2 3,-10 80,-7 9)
```

# ST\$1Azimuth
<a name="ST_Azimuth-function"></a>

ST\$1Azimuth returns the north-based Cartesian azimuth using the 2D projections of the two input points. 

## Syntax
<a name="ST_Azimuth-function-syntax"></a>

```
ST_Azimuth(point1, point2)
```

## Arguments
<a name="ST_Azimuth-function-arguments"></a>

 *point1*   
A `POINT` value of data type `GEOMETRY`. The spatial reference system identifier (SRID) of *point1* must match the SRID of *point2*. 

 *point2*   
A `POINT` value of data type `GEOMETRY`. The SRID of *point2* must match the SRID of *point1*. 

## Return type
<a name="ST_Azimuth-function-return"></a>

A number that is an angle in radians of `DOUBLE PRECISION` data type. Values range from 0 (inclusive) to 2 pi (exclusive). 

If *point1* or *point2* is the empty point, then an error is returned. 

If either *point1* or *point2* is null, then null is returned. 

If *point1* and *point2* are equal, then null is returned. 

If *point1* or *point2* is not a point, then an error is returned. 

If *point1* and *point2* don't have the value for the spatial reference system identifier (SRID), then an error is returned. 

## Examples
<a name="ST_Azimuth-function-examples"></a>

The following SQL returns the azimuth of the input points. 

```
SELECT ST_Azimuth(ST_Point(1,2), ST_Point(5,6));
```

```
st_azimuth
-------------------
 0.7853981633974483
```

# ST\$1Boundary
<a name="ST_Boundary-function"></a>

ST\$1Boundary returns the boundary of an input geometry as follows: 
+ If the input geometry is empty (that is, it contains no points) it is returned as is. 
+ If the input geometry is a point or nonempty multipoint, an empty geometry collection is returned.
+ If the input is a linestring or a multilinestring, then a multipoint containing all the points on the boundary is returned. The multipoint might be empty).
+ If the input is a polygon that does not have any interior rings, then a closed linestring representing its boundary is returned.
+ If the input is a polygon that has interior rings, or is a multipolygon, then a multilinestring is returned. The multilinestring contains all the boundaries of all the rings in the areal geometry as closed linestrings.

To determine point equality, ST\$1Boundary operates on the 2D projection of the input geometry. If the input geometry is empty, a copy of it is returned in the same dimension as the input. For nonempty 3DM and 4D geometries, their `m` coordinates are dropped. In the special case of 3DZ and 4D multilinestrings, the `z` coordinates of the multilinestring's boundary points are computed as the averages of the distinct z-values of the linestring boundary points with the same 2D projection.

## Syntax
<a name="ST_Boundary-function-syntax"></a>

```
ST_Boundary(geom)
```

## Arguments
<a name="ST_Boundary-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_Boundary-function-return"></a>

`GEOMETRY`

If *geom* is null, then null is returned.

If *geom* is a `GEOMETRYCOLLECTION`, then an error is returned.

## Examples
<a name="ST_Boundary-function-examples"></a>

The following SQL returns the boundary of the input polygon as a multilinestring. 

```
SELECT ST_AsEWKT(ST_Boundary(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(1 1,1 2,2 1,1 1))')));
```

```
st_asewkt
--------------------
 MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(1 1,1 2,2 1,1 1))
```

# ST\$1Buffer
<a name="ST_Buffer-function"></a>

ST\$1Buffer returns 2D geometry that represents all points whose distance from the input geometry projected on the xy-Cartesian plane is less than or equal to the input distance. 

## Syntax
<a name="ST_Buffer-function-syntax"></a>

```
ST_Buffer(geom, distance)
```

```
ST_Buffer(geom, distance, number_of_segments_per_quarter_circle)
```

## Arguments
<a name="ST_Buffer-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

 *distance*   
A value of data type `DOUBLE PRECISION` that represents distance (or radius) of the buffer. 

 *number\$1of\$1segments\$1per\$1quarter\$1circle*   
A value of data type `INTEGER`. This value determines the number of points to approximate a quarter circle around each vertex of the input geometry. Negative values default to zero. The default is 8.

## Return type
<a name="ST_Buffer-function-return"></a>

`GEOMETRY`

The ST\$1Buffer function returns two-dimensional (2D) geometry in the xy-Cartesian plane.

If *geom* is a `GEOMETRYCOLLECTION`, then an error is returned.

## Examples
<a name="ST_Buffer-function-examples"></a>

The following SQL returns the buffer of the input linestring. 

```
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('LINESTRING(1 2,5 2,5 8)'), 2));
```

```
               st_asewkt  
POLYGON((-1 2,-0.96157056080646 2.39018064403226,-0.847759065022573 2.76536686473018,-0.662939224605089 3.11114046603921,-0.414213562373093 3.4142135623731,-0.111140466039201 3.66293922460509,0.234633135269824 3.84775906502257,0.609819355967748 3.96157056080646,1 4,3 4,3 8,3.03842943919354 8.39018064403226,3.15224093497743 8.76536686473018,3.33706077539491 9.11114046603921,3.58578643762691 9.4142135623731,3.8888595339608 9.66293922460509,4.23463313526982 9.84775906502257,4.60981935596775 9.96157056080646,5 10,5.39018064403226 9.96157056080646,5.76536686473018 9.84775906502257,6.11114046603921 9.66293922460509,6.4142135623731 9.41421356237309,6.66293922460509 9.1111404660392,6.84775906502258 8.76536686473017,6.96157056080646 8.39018064403225,7 8,7 2,6.96157056080646 1.60981935596774,6.84775906502257 1.23463313526982,6.66293922460509 0.888859533960796,6.41421356237309 0.585786437626905,6.1111404660392 0.33706077539491,5.76536686473018 0.152240934977427,5.39018064403226 0.0384294391935391,5 0,1 0,0.609819355967744 0.0384294391935391,0.234633135269821 0.152240934977427,-0.111140466039204 0.337060775394909,-0.414213562373095 0.585786437626905,-0.662939224605091 0.888859533960796,-0.847759065022574 1.23463313526982,-0.961570560806461 1.60981935596774,-1 2))
```

The following SQL returns the buffer of the input point geometry which approximates a circle. Because the command doesn't specify the number of segments per quarter circle, the function uses the default value of eight segments to approximate the quarter circle.

```
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('POINT(3 4)'), 2));
```

```
               st_asewkt
POLYGON((1 4,1.03842943919354 4.39018064403226,1.15224093497743 4.76536686473018,1.33706077539491 5.11114046603921,1.58578643762691 5.4142135623731,1.8888595339608 5.66293922460509,2.23463313526982 5.84775906502257,2.60981935596775 5.96157056080646,3 6,3.39018064403226 5.96157056080646,3.76536686473019 5.84775906502257,4.11114046603921 5.66293922460509,4.4142135623731 5.41421356237309,4.66293922460509 5.1111404660392,4.84775906502258 4.76536686473017,4.96157056080646 4.39018064403225,5 4,4.96157056080646 3.60981935596774,4.84775906502257 3.23463313526982,4.66293922460509 2.8888595339608,4.41421356237309 2.58578643762691,4.1111404660392 2.33706077539491,3.76536686473018 2.15224093497743,3.39018064403226 2.03842943919354,3 2,2.60981935596774 2.03842943919354,2.23463313526982 2.15224093497743,1.8888595339608 2.33706077539491,1.58578643762691 2.58578643762691,1.33706077539491 2.8888595339608,1.15224093497743 3.23463313526982,1.03842943919354 3.60981935596774,1 4))
```

The following SQL returns the buffer of the input point geometry which approximates a circle. Because the command specifies 3 as the number of segments per quarter circle, the function uses three segments to approximate the quarter circle.

```
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('POINT(3 4)'), 2, 3));
```

```
               st_asewkt
POLYGON((1 4,1.26794919243112 5,2 5.73205080756888,3 6,4 5.73205080756888,4.73205080756888 5,5 4,4.73205080756888 3,4 2.26794919243112,3 2,2 2.26794919243112,1.26794919243112 3,1 4))
```

# ST\$1Centroid
<a name="ST_Centroid-function"></a>

ST\$1Centroid returns a point that represents a centroid of a geometry as follows:
+ For `POINT` geometries, it returns the point whose coordinates are the average of the coordinates of the points in the geometry. 
+ For `LINESTRING` geometries, it returns the point whose coordinates are the weighted average of the midpoints of the segments of the geometry, where the weights are the lengths of the segments of the geometry.
+ For `POLYGON` geometries, it returns the point whose coordinates are the weighted average of the centroids of a triangulation of the areal geometry where the weights are the areas of the triangles in the triangulation.
+ For geometry collections, it returns the weighted average of the centroids of the geometries of maximum topological dimension in the geometry collection.

## Syntax
<a name="ST_Centroid-function-syntax"></a>

```
ST_Centroid(geom)
```

## Arguments
<a name="ST_Centroid-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Centroid-function-return"></a>

`GEOMETRY` 

If *geom* is null, then null is returned. 

If *geom* is empty, then null is returned. 

## Examples
<a name="ST_Centroid-function-examples"></a>

The following SQL returns central point of an input linestring. 

```
SELECT ST_AsEWKT(ST_Centroid(ST_GeomFromText('LINESTRING(110 40, 2 3, -10 80, -7 9, -22 -33)', 4326)))
```

```
                     st_asewkt
----------------------------------------------------
 SRID=4326;POINT(15.6965103455214 27.0206782881905)
```

# ST\$1Collect
<a name="ST_Collect-function"></a>

ST\$1Collect has two variants. One accepts two geometries, and one accepts an aggregate expression. 

The first variant of ST\$1Collect creates a geometry from the input geometries. The order of the input geometries is preserved. This variant works as follows: 
+ If both input geometries are points, then a `MULTIPOINT` with two points is returned. 
+ If both input geometries are linestrings, then a `MULTILINESTRING` with two linestrings is returned. 
+ If both input geometries are polygons, then a `MULTIPOLYGON` with two polygons is returned. 
+ Otherwise, a `GEOMETRYCOLLECTION` with two input geometries is returned. 

The second variant of ST\$1Collect creates a geometry from geometries in a geometry column. There isn't a determined return order of the geometries. Specify the WITHIN GROUP (ORDER BY ...) clause to specify the order of the returned geometries. This variant works as follows: 
+ If all non-NULL rows in the input aggregate expression are points, then a multipoint containing all the points in the aggregate expression is returned. 
+ If all non-NULL rows in the aggregate expression are linestrings, then a multilinestring containing all the linestrings in the aggregate expression is returned. 
+ If all non-NULL rows in the aggregate expression are polygons, the result is a multipolygon containing all the polygons in the aggregate expression is returned. 
+ Otherwise, a `GEOMETRYCOLLECTION` containing all the geometries in the aggregate expression is returned. 

The ST\$1Collect returns the geometry of the same dimension as the input geometries. All input geometries must be of the same dimension.

## Syntax
<a name="ST_Collect-function-syntax"></a>

```
ST_Collect(geom1, geom2)
```

```
ST_Collect(aggregate_expression)  [WITHIN GROUP (ORDER BY sort_expression1 [ASC | DESC] [, sort_expression2 [ASC | DESC] ...])]
```

## Arguments
<a name="ST_Collect-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *aggregate\$1expression*   
A column of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 [WITHIN GROUP (ORDER BY *sort\$1expression1* [ASC \$1 DESC] [, *sort\$1expression2* [ASC \$1 DESC] ...])]   
An optional clause that specifies the sort order of the aggregated values. The ORDER BY clause contains a list of sort expressions. Sort expressions are expressions similar to valid sort expressions in a query select list, such as a column name. You can specify ascending (`ASC`) or descending (`DESC`) order. The default is `ASC`. 

## Return type
<a name="ST_Collect-function-return"></a>

`GEOMETRY` of subtype `MULTIPOINT`, `MULTILINESTRING`, `MULTIPOLYGON`, or `GEOMETRYCOLLECTION`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometries. 

If both *geom1* or *geom2* are null, then null is returned. 

If all rows of *aggregate\$1expression* are null, then null is returned. 

If *geom1* is null, then a copy of *geom2* is returned. Likewise, if *geom2* is null, then a copy of *geom1* is returned.

If *geom1* and *geom2* have different SRID values, then an error is returned. 

If two geometries in *aggregate\$1expression* have different SRID values, then an error is returned. 

If the returned geometry is larger than the maximum size of a `GEOMETRY`, then an error is returned. 

If *geom1* and *geom2* are of different dimensions, then an error is returned. 

If two geometries in *aggregate\$1expression* are of different dimensions, then an error is returned. 

## Examples
<a name="ST_Collect-function-examples"></a>

The following SQL returns a geometry collection that contains the two input geometries. 

```
SELECT ST_AsText(ST_Collect(ST_GeomFromText('LINESTRING(0 0,1 1)'), ST_GeomFromText('POLYGON((10 10,20 10,10 20,10 10))')));
```

```
st_astext
-----------
 GEOMETRYCOLLECTION(LINESTRING(0 0,1 1),POLYGON((10 10,20 10,10 20,10 10)))
```

The following SQL collects all the geometries from a table into a geometry collection. 

```
WITH tbl(g) AS (SELECT ST_GeomFromText('POINT(1 2)', 4326) UNION ALL
SELECT ST_GeomFromText('LINESTRING(0 0,10 0)', 4326) UNION ALL
SELECT ST_GeomFromText('MULTIPOINT(13 4,8 5,4 4)', 4326) UNION ALL
SELECT NULL::geometry UNION ALL
SELECT ST_GeomFromText('POLYGON((0 0,10 0,0 10,0 0))', 4326))
SELECT ST_AsEWKT(ST_Collect(g)) FROM tbl;
```

```
st_astext
-----------
 SRID=4326;GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(0 0,10 0),MULTIPOINT((13 4),(8 5),(4 4)),POLYGON((0 0,10 0,0 10,0 0)))
```

The following SQL collects all geometries in the table grouped by the id column and ordered by this ID. In this example, resulting geometries are grouped by ID as follows: 
+ id 1 – points in a multipoint.
+ id 2 – linestrings in a multilinestring.
+ id 3 – mixed subtypes in a geometry collection.
+ id 4 – polygons in a multipolygon.
+ id 5 – null and the result is null.

```
WITH tbl(id, g) AS (SELECT 1, ST_GeomFromText('POINT(1 2)', 4326) UNION ALL
SELECT 1, ST_GeomFromText('POINT(4 5)', 4326) UNION ALL
SELECT 2, ST_GeomFromText('LINESTRING(0 0,10 0)', 4326) UNION ALL
SELECT 2, ST_GeomFromText('LINESTRING(10 0,20 -5)', 4326) UNION ALL
SELECT 3, ST_GeomFromText('MULTIPOINT(13 4,8 5,4 4)', 4326) UNION ALL
SELECT 3, ST_GeomFromText('MULTILINESTRING((-1 -1,-2 -2),(-3 -3,-5 -5))', 4326) UNION ALL
SELECT 4, ST_GeomFromText('POLYGON((0 0,10 0,0 10,0 0))', 4326) UNION ALL
SELECT 4, ST_GeomFromText('POLYGON((20 20,20 30,30 20,20 20))', 4326) UNION ALL
SELECT 1, NULL::geometry UNION ALL SELECT 2, NULL::geometry UNION ALL
SELECT 5, NULL::geometry UNION ALL SELECT 5, NULL::geometry)
SELECT id, ST_AsEWKT(ST_Collect(g)) FROM tbl GROUP BY id ORDER BY id;
```

```
 id |                                                 st_asewkt                                                 
----+-----------------------------------------------------------------------------------------------------------
  1 | SRID=4326;MULTIPOINT((1 2),(4 5))
  2 | SRID=4326;MULTILINESTRING((0 0,10 0),(10 0,20 -5))
  3 | SRID=4326;GEOMETRYCOLLECTION(MULTIPOINT((13 4),(8 5),(4 4)),MULTILINESTRING((-1 -1,-2 -2),(-3 -3,-5 -5)))
  4 | SRID=4326;MULTIPOLYGON(((0 0,10 0,0 10,0 0)),((20 20,20 30,30 20,20 20)))
  5 |
```

The following SQL collects all geometries from a table in a geometry collection. Results are ordered in descending order by `id`, and then lexicographically based on their minimum and maximum x-coordinates. 

```
WITH tbl(id, g) AS (
SELECT 1, ST_GeomFromText('POINT(4 5)', 4326) UNION ALL
SELECT 1, ST_GeomFromText('POINT(1 2)', 4326) UNION ALL
SELECT 2, ST_GeomFromText('LINESTRING(10 0,20 -5)', 4326) UNION ALL
SELECT 2, ST_GeomFromText('LINESTRING(0 0,10 0)', 4326) UNION ALL
SELECT 3, ST_GeomFromText('MULTIPOINT(13 4,8 5,4 4)', 4326) UNION ALL
SELECT 3, ST_GeomFromText('MULTILINESTRING((-1 -1,-2 -2),(-3 -3,-5 -5))', 4326) UNION ALL
SELECT 4, ST_GeomFromText('POLYGON((20 20,20 30,30 20,20 20))', 4326) UNION ALL
SELECT 4, ST_GeomFromText('POLYGON((0 0,10 0,0 10,0 0))', 4326) UNION ALL
SELECT 1, NULL::geometry UNION ALL SELECT 2, NULL::geometry UNION ALL
SELECT 5, NULL::geometry UNION ALL SELECT 5, NULL::geometry)
SELECT ST_AsEWKT(ST_Collect(g) WITHIN GROUP (ORDER BY id DESC, ST_XMin(g), ST_XMax(g))) FROM tbl;
```

```
                                                                                                                  st_asewkt                                                                                                                  
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 SRID=4326;GEOMETRYCOLLECTION(POLYGON((0 0,10 0,0 10,0 0)),POLYGON((20 20,20 30,30 20,20 20)),MULTILINESTRING((-1 -1,-2 -2),(-3 -3,-5 -5)),MULTIPOINT((13 4),(8 5),(4 4)),LINESTRING(0 0,10 0),LINESTRING(10 0,20 -5),POINT(1 2),POINT(4 5)
```

# ST\$1Contains
<a name="ST_Contains-function"></a>

ST\$1Contains returns true if the 2D projection of the first input geometry contains the 2D projection of the second input geometry. Geometry `A` contains geometry `B` if every point in `B` is a point in `A`, and their interiors have nonempty intersection. 

ST\$1Contains(`A`, `B`) is equivalent to ST\$1Within(`B`, `A`). 

## Syntax
<a name="ST_Contains-function-syntax"></a>

```
ST_Contains(geom1, geom2)
```

## Arguments
<a name="ST_Contains-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. This value is compared with *geom1* to determine if it is contained within *geom1*. 

## Return type
<a name="ST_Contains-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Contains-function-examples"></a>

The following SQL checks if the first polygon contains the second polygon. 

```
SELECT ST_Contains(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'));
```

```
st_contains
-----------
 false
```

# ST\$1ContainsProperly
<a name="ST_ContainsProperly-function"></a>

ST\$1ContainsProperly returns true if both input geometries are nonempty, and all points of the 2D projection of the second geometry are interior points of the 2D projection of the first geometry. 

## Syntax
<a name="ST_ContainsProperly-function-syntax"></a>

```
ST_ContainsProperly(geom1, geom2)
```

## Arguments
<a name="ST_ContainsProperly-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype can't be `GEOMETRYCOLLECTION`. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype can't be `GEOMETRYCOLLECTION`. This value is compared with *geom1* to determine if all its points are interior points of *geom1*. 

## Return type
<a name="ST_ContainsProperly-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_ContainsProperly-function-examples"></a>

The following SQL returns the values of ST\$1Contains and ST\$1ContainsProperly where the input linestring intersects the interior and the boundary of the input polygon (but not its exterior). The polygon contains the linestring but doesn't properly contain the linestring. 

```
WITH tmp(g1, g2) 
AS (SELECT ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0))'), ST_GeomFromText('LINESTRING(5 5,10 5,10 6,5 5)')) SELECT ST_Contains(g1, g2), ST_ContainsProperly(g1, g2) 
FROM tmp;
```

```
 st_contains | st_containsproperly 
-------------+---------------------
 t           | f
```

# ST\$1ConvexHull
<a name="ST_ConvexHull-function"></a>

ST\$1ConvexHull returns a geometry that represents the convex hull of the nonempty points contained in the input geometry. 

For empty input, the resulting geometry is the same as the input geometry. For all nonempty input, the function operates on the 2D projection of the input geometry. However, the dimension of the output geometry depends on the dimension of the input geometry. More specifically, when the input geometry is a nonempty 3DM or 3D geometry, `m` coordinates are dropped. That is, the dimension of the returned geometry is 2D or 3DZ, respectively. If the input is a nonempty 2D or 3DZ geometry, the resulting geometry has the same dimension.

## Syntax
<a name="ST_ConvexHull-function-syntax"></a>

```
ST_ConvexHull(geom)
```

## Arguments
<a name="ST_ConvexHull-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_ConvexHull-function-return"></a>

`GEOMETRY`

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

The values returned are as follows.


| Number of points on the convex hull | Geometry subtype | 
| --- | --- | 
| 0 | A copy of *geom* is returned.  | 
| 1 | A `POINT` subtype is returned.  | 
| 2 | A `LINESTRING` subtype is returned. The two points of the returned linestring are lexicographically ordered. | 
| 3 or greater | A `POLYGON` subtype with no interior rings is returned. The polygon is clockwise oriented, and the first point of the exterior ring is the lexicographically smallest point of the ring. | 

## Examples
<a name="ST_ConvexHull-function-examples"></a>

The following SQL returns the extended well-known text (EWKT) representation of a linestring. In this case, the convex hull returned is a polygon.

```
SELECT ST_AsEWKT(ST_ConvexHull(ST_GeomFromText('LINESTRING(0 0,1 0,0 1,1 1,0.5 0.5)'))) as output;
```

```
output
-------------
POLYGON((0 0,0 1,1 1,1 0,0 0))
```

The following SQL returns the EWKT representation of a linestring. In this case, the convex hull returned is a linestring.

```
SELECT ST_AsEWKT(ST_ConvexHull(ST_GeomFromText('LINESTRING(0 0,1 1,0.2 0.2,0.6 0.6,0.5 0.5)'))) as output;
```

```
output
-------------
LINESTRING(0 0,1 1)
```

The following SQL returns the EWKT representation of a multipoint. In this case, the convex hull returned is a point.

```
SELECT ST_AsEWKT(ST_ConvexHull(ST_GeomFromText('MULTIPOINT(0 0,0 0,0 0)'))) as output;
```

```
output
-------------
POINT(0 0)
```

# ST\$1CoveredBy
<a name="ST_CoveredBy-function"></a>

ST\$1CoveredBy returns true if the 2D projection of the first input geometry is covered by the 2D projection of the second input geometry. Geometry `A` is covered by geometry `B` if both are nonempty and every point in `A` is a point in `B`. 

ST\$1CoveredBy(`A`, `B`) is equivalent to ST\$1Covers(`B`, `A`). 

## Syntax
<a name="ST_CoveredBy-function-syntax"></a>

```
ST_CoveredBy(geom1, geom2)
```

## Arguments
<a name="ST_CoveredBy-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. This value is compared with *geom2* to determine if it's covered by *geom2*. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_CoveredBy-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_CoveredBy-function-examples"></a>

The following SQL checks if the first polygon is covered by the second polygon. 

```
SELECT ST_CoveredBy(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'));
```

```
st_coveredby
-----------
 true
```

# ST\$1Covers
<a name="ST_Covers-function"></a>

ST\$1Covers returns true if the 2D projection of the first input geometry covers the 2D projection of the second input geometry. Geometry `A` covers geometry `B` if both are nonempty and every point in `B` is a point in `A`. 

ST\$1Covers(`A`, `B`) is equivalent to ST\$1CoveredBy(`B`, `A`). 

## Syntax
<a name="ST_Covers-function-syntax"></a>

```
ST_Covers(geom1, geom2)
```

## Arguments
<a name="ST_Covers-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. This value is compared with *geom1* to determine if it covers *geom1*. 

## Return type
<a name="ST_Covers-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Covers-function-examples"></a>

The following SQL checks if the first polygon covers the second polygon. 

```
SELECT ST_Covers(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'));
```

```
st_covers
-----------
 false
```

# ST\$1Crosses
<a name="ST_Crosses-function"></a>

ST\$1Crosses returns true if the 2D projections of the two input geometries cross each other. 

## Syntax
<a name="ST_Crosses-function-syntax"></a>

```
ST_Crosses(geom1, geom2)
```

## Arguments
<a name="ST_Crosses-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Crosses-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

## Examples
<a name="ST_Crosses-function-examples"></a>

The following SQL checks if the first polygon crosses the second multipoint. In this example, the multipoint intersects both the interior and exterior of the polygon, which is why ST\$1Crosses returns true.

```
SELECT ST_Crosses (ST_GeomFromText('polygon((0 0,10 0,10 10,0 10,0 0))'), ST_GeomFromText('multipoint(5 5,0 0,-1 -1)'));
```

```
st_crosses              
-------------
 true
```

The following SQL checks if the first polygon crosses the second multipoint. In this example, the multipoint intersects the exterior of the polygon but not its interior, which is why ST\$1Crosses returns false.

```
SELECT ST_Crosses (ST_GeomFromText('polygon((0 0,10 0,10 10,0 10,0 0))'), ST_GeomFromText('multipoint(0 0,-1 -1)'));
```

```
st_crosses              
-------------
 false
```

# ST\$1Dimension
<a name="ST_Dimension-function"></a>

ST\$1Dimension returns the inherent dimension of an input geometry. The *inherent dimension* is the dimension value of the subtype that is defined in the geometry. 

For 3DM, 3DZ, and 4D geometry inputs, ST\$1Dimension returns the same result as for 2D geometry inputs.

## Syntax
<a name="ST_Dimension-function-syntax"></a>

```
ST_Dimension(geom)
```

## Arguments
<a name="ST_Dimension-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Dimension-function-return"></a>

`INTEGER` representing the inherent dimension of *geom*. 

If *geom* is null, then null is returned. 

The values returned are as follows.


| Returned value | Geometry subtype | 
| --- | --- | 
| 0 | Returned if *geom* is a `POINT` or `MULTIPOINT` subtype | 
| 1 | Returned if *geom* is a `LINESTRING` or `MULTILINESTRING` subtype. | 
| 2 | Returned if *geom* is a `POLYGON` or `MULTIPOLYGON` subtype | 
| 0 | Returned if *geom* is an empty `GEOMETRYCOLLECTION` subtype | 
| Largest dimension of the components of the collection | Returned if *geom* is a `GEOMETRYCOLLECTION` subtype | 

## Examples
<a name="ST_Dimension-function-examples"></a>

The following SQL converts a well-known text (WKT) representation of a four-point LINESTRING to a GEOMETRY object and returns the dimension of the linestring. 

```
SELECT ST_Dimension(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_dimension
-------------
1
```

# ST\$1Disjoint
<a name="ST_Disjoint-function"></a>

ST\$1Disjoint returns true if the 2D projections of the two input geometries have no points in common. 

## Syntax
<a name="ST_Disjoint-function-syntax"></a>

```
ST_Disjoint(geom1, geom2)
```

## Arguments
<a name="ST_Disjoint-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Disjoint-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Disjoint-function-examples"></a>

The following SQL checks if the first polygon is disjoint from the second polygon. 

```
SELECT ST_Disjoint(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))'), ST_Point(4, 4));
```

```
st_disjoint               
-----------
 true
```

# ST\$1Distance
<a name="ST_Distance-function"></a>

For input geometries, ST\$1Distance returns the minimum Euclidean distance between the 2D projections of the two input geometry values. 

For 3DM, 3DZ, 4D geometries, ST\$1Distance returns the Euclidean distance between the 2D projections of two input geometry values.

For input geographies, ST\$1Distance returns the geodesic distance of the two 2D points. The unit of distance is in meters. For geographies other than points and empty points an error is returned.

## Syntax
<a name="ST_Distance-function-syntax"></a>

```
ST_Distance(geo1, geo2)
```

## Arguments
<a name="ST_Distance-function-arguments"></a>

 *geo1*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type. The data type of *geo1* must be the same as *geo2*.

 *geo2*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type. The data type of *geo2* must be the same as *geo1*.

## Return type
<a name="ST_Distance-function-return"></a>

`DOUBLE PRECISION` in the same units as the input geometries or geographies.

If *geo1* or *geo2* is null or empty, then null is returned. 

If *geo1* and *geo2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geo1* or *geo2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Distance-function-examples"></a>

The following SQL returns the distance between two polygons. 

```
SELECT ST_Distance(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 -3,-2 -1,0 -3,-1 -3))'));
```

```
  st_distance
-----------
1.4142135623731
```

The following SQL returns the distance (in meters) between the Brandenburg Gate and the Reichstag building in Berlin using a GEOGRAPHY data type. 

```
SELECT ST_Distance(ST_GeogFromText('POINT(13.37761826722198 52.516411678282445)'), ST_GeogFromText('POINT(13.377950831464005 52.51705102546893)'));
```

```
   st_distance
------------------
 74.64129172609631
```

# ST\$1DistanceSphere
<a name="ST_DistanceSphere-function"></a>

ST\$1DistanceSphere returns the distance between two point geometries lying on a sphere. 

## Syntax
<a name="ST_DistanceSphere-function-syntax"></a>

```
ST_DistanceSphere(geom1, geom2)
```

```
ST_DistanceSphere(geom1, geom2, radius)
```

## Arguments
<a name="ST_DistanceSphere-function-arguments"></a>

 *geom1*   
A point value in degrees of data type `GEOMETRY` lying on a sphere. The first coordinate of the point is the longitude value. The second coordinate of the point is the latitude value. For 3DZ, 3DM, or 4D geometries, only the first two coordinates are used.

 *geom2*   
A point value in degrees of data type `GEOMETRY` lying on a sphere. The first coordinate of the point is the longitude value. The second coordinate of the point is the latitude value. For 3DZ, 3DM, or 4D geometries, only the first two coordinates are used.

 *radius*   
The radius of a sphere of data type `DOUBLE PRECISION`. If no *radius* is provided, the sphere defaults to Earth and the radius is computed from the World Geodetic System (WGS) 84 representation of the ellipsoid. 

## Return type
<a name="ST_DistanceSphere-function-return"></a>

`DOUBLE PRECISION` in the same units as the radius. If no radius is provided, the distance is in meters.

If *geom1* or *geom2* is null or empty, then null is returned. 

If no *radius* is provided, then the result is in meters along the Earth's surface. 

If *radius* is a negative number, then an error is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is not a point, then an error is returned. 

## Examples
<a name="ST_DistanceSphere-function-examples"></a>

The following example SQL computes the distance in kilometers between two points on Earth. 

```
SELECT ROUND(ST_DistanceSphere(ST_Point(-122, 47), ST_Point(-122.1, 47.1))/ 1000, 0);
```

```
  round
-----------
 13
```

The following example SQL computes the distances in kilometers between three airport locations in Germany: Berlin Tegel (TXL), Munich International (MUC), and Frankfurt International (FRA). 

```
WITH airports_raw(code,lon,lat) AS (
(SELECT 'MUC', 11.786111, 48.353889) UNION
(SELECT 'FRA', 8.570556, 50.033333) UNION
(SELECT 'TXL', 13.287778, 52.559722)),
airports1(code,location) AS (SELECT code, ST_Point(lon, lat) FROM airports_raw),
airports2(code,location) AS (SELECT * from airports1)
SELECT (airports1.code || ' <-> ' || airports2.code) AS airports,
round(ST_DistanceSphere(airports1.location, airports2.location) / 1000, 0) AS distance_in_km
FROM airports1, airports2 WHERE airports1.code < airports2.code ORDER BY 1;
```

```
  airports   | distance_in_km 
-------------+----------------
 FRA <-> MUC |            299
 FRA <-> TXL |            432
 MUC <-> TXL |            480
```

# ST\$1DWithin
<a name="ST_DWithin-function"></a>

ST\$1DWithin returns true if the Euclidean distance between the 2D projections of the two input geometry values is not larger than a threshold value. 

## Syntax
<a name="ST_DWithin-function-syntax"></a>

```
ST_DWithin(geom1, geom2, threshold)
```

## Arguments
<a name="ST_DWithin-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *threshold*   
A value of data type `DOUBLE PRECISION`. This value is in the units of the input arguments. 

## Return type
<a name="ST_DWithin-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *threshold* is negative, then an error is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_DWithin-function-examples"></a>

The following SQL checks if the distance between two polygons is within five units. 

```
SELECT ST_DWithin(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'),5);
```

```
st_dwithin
-----------
 true
```

# ST\$1EndPoint
<a name="ST_EndPoint-function"></a>

ST\$1EndPoint returns the last point of an input linestring. The spatial reference system identifier (SRID) value of the result is the same as that of the input geometry. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_EndPoint-function-syntax"></a>

```
ST_EndPoint(geom)
```

## Arguments
<a name="ST_EndPoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

## Return type
<a name="ST_EndPoint-function-return"></a>

`GEOMETRY` 

If *geom* is null, then null is returned. 

If *geom* is empty, then null is returned. 

If *geom* isn't a `LINESTRING`, then null is returned. 

## Examples
<a name="ST_EndPoint-function-examples"></a>

The following SQL returns an extended well-known text (EWKT) representation of a four-point `LINESTRING` to a `GEOMETRY` object and returns the end point of the linestring. 

```
SELECT ST_AsEWKT(ST_EndPoint(ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5)',4326)));
```

```
st_asewkt
-------------
 SRID=4326;POINT(0 5)
```

# ST\$1Envelope
<a name="ST_Envelope-function"></a>

ST\$1Envelope returns the minimum bounding box of the input geometry, as follows:
+ If the input geometry is empty, the returned geometry is a copy of the input geometry. 
+ If the minimum bounding box of the input geometry degenerates to a point, the returned geometry is a point. 
+ If the minimum bounding box of the input geometry is one-dimensional, a two-point linestring is returned.
+ If none of the preceding is true, the function returns a clockwise-oriented polygon whose vertices are the corners of the minimum bounding box.

The spatial reference system identifier (SRID) of the returned geometry is the same as that of the input geometry. 

For all nonempty input, the function operates on the 2D projection of the input geometry. 

## Syntax
<a name="ST_Envelope-function-syntax"></a>

```
ST_Envelope(geom)
```

## Arguments
<a name="ST_Envelope-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Envelope-function-return"></a>

`GEOMETRY` 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_Envelope-function-examples"></a>

The following SQL converts a well-known text (WKT) representation of a four-point `LINESTRING` to a `GEOMETRY` object and returns a polygon whose vertices whose corners are the minimum bounding box. 

```
SELECT ST_AsText(ST_Envelope(ST_GeomFromText('GEOMETRYCOLLECTION(POLYGON((0 0,10 0,0 10,0 0)),LINESTRING(20 10,20 0,10 0))')));
```

```
    st_astext
------------------------------------
  POLYGON((0 0,0 10,20 10,20 0,0 0))
```

# ST\$1Equals
<a name="ST_Equals-function"></a>

ST\$1Equals returns true if the 2D projections of the input geometries are geometrically equal. Geometries are considered geometrically equal if they have equal point sets and their interiors have a nonempty intersection. 

## Syntax
<a name="ST_Equals-function-syntax"></a>

```
ST_Equals(geom1, geom2)
```

## Arguments
<a name="ST_Equals-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. This value is compared with *geom1* to determine if it is equal to *geom1*. 

## Return type
<a name="ST_Equals-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then an error is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Equals-function-examples"></a>

The following SQL checks if the two polygons are geometrically equal. 

```
SELECT ST_Equals(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'));
```

```
st_equals
-----------
 false
```

The following SQL checks if the two linestrings are geometrically equal. 

```
SELECT ST_Equals(ST_GeomFromText('LINESTRING(1 0,10 0)'), ST_GeomFromText('LINESTRING(1 0,5 0,10 0)'));
```

```
st_equals
-----------
 true
```

# ST\$1ExteriorRing
<a name="ST_ExteriorRing-function"></a>

ST\$1ExteriorRing returns a closed linestring that represents the exterior ring of an input polygon. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_ExteriorRing-function-syntax"></a>

```
ST_ExteriorRing(geom)
```

## Arguments
<a name="ST_ExteriorRing-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_ExteriorRing-function-return"></a>

`GEOMETRY` of subtype `LINESTRING`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

If *geom* is not a polygon, then null is returned. 

If *geom* is empty, then an empty polygon is returned. 

## Examples
<a name="ST_ExteriorRing-function-examples"></a>

The following SQL returns the exterior ring of a polygon as a closed linestring. 

```
SELECT ST_AsEWKT(ST_ExteriorRing(ST_GeomFromText('POLYGON((7 9,8 7,11 6,15 8,16 6,17 7,17 10,18 12,17 14,15 15,11 15,10 13,9 12,7 9),(9 9,10 10,11 11,11 10,10 8,9 9),(12 14,15 14,13 11,12 14))')));
```

```
st_asewkt
-----------
 LINESTRING(7 9,8 7,11 6,15 8,16 6,17 7,17 10,18 12,17 14,15 15,11 15,10 13,9 12,7 9)
```

# ST\$1Force2D
<a name="ST_Force2D-function"></a>

ST\$1Force2D returns a 2D geometry of the input geometry. For 2D geometries, a copy of the input is returned. For 3DZ, 3DM, and 4D geometries, ST\$1Force2D projects the geometry to the xy-Cartesian plane. Empty points in the input geometry remain empty points in the output geometry.

## Syntax
<a name="ST_Force2D-function-syntax"></a>

```
ST_Force2D(geom)
```

## Arguments
<a name="ST_Force2D-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Force2D-function-return"></a>

`GEOMETRY`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

If *geom* is empty, then an empty geometry is returned. 

## Examples
<a name="ST_Force2D-function-examples"></a>

The following SQL returns a 2D geometry from a 3DZ geometry. 

```
SELECT ST_AsEWKT(ST_Force2D(ST_GeomFromText('MULTIPOINT Z(0 1 2, EMPTY, 2 3 4, 5 6 7)')));
```

```
st_asewkt
-----------
  MULTIPOINT((0 1),EMPTY,(2 3),(5 6))
```

# ST\$1Force3D
<a name="ST_Force3D-function"></a>

ST\$1Force3D is an alias for ST\$1Force3DZ. For more information, see [ST\$1Force3DZ](ST_Force3DZ-function.md). 

# ST\$1Force3DM
<a name="ST_Force3DM-function"></a>

ST\$1Force3DM returns a 3DM geometry of the input geometry. For 2D geometries, the `m` coordinates of the nonempty points in the output geometry are all set to `0`. For 3DM geometries, a copy of the input geometry is returned. For 3DZ geometries, the geometry is projected to the xy-Cartesian plane, and the `m` coordinates of the nonempty points in the output geometry are all set to `0`. For 4D geometries, the geometry is projected to the xym-Cartesian space. Empty points in the input geometry remain empty points in the output geometry.

## Syntax
<a name="ST_Force3DM-function-syntax"></a>

```
ST_Force3DM(geom)
```

## Arguments
<a name="ST_Force3DM-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Force3DM-function-return"></a>

`GEOMETRY`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

If *geom* is empty, then an empty geometry is returned. 

## Examples
<a name="ST_Force3DM-function-examples"></a>

The following SQL returns a 3DM geometry from a 3DZ geometry. 

```
SELECT ST_AsEWKT(ST_Force3DM(ST_GeomFromText('MULTIPOINT Z(0 1 2, EMPTY, 2 3 4, 5 6 7)')));
```

```
st_asewkt
-----------
  MULTIPOINT M ((0 1 0),EMPTY,(2 3 0),(5 6 0))
```

# ST\$1Force3DZ
<a name="ST_Force3DZ-function"></a>

ST\$1Force3DZ returns a 3DZ geometry from the input geometry. For 2D geometries, the `z` coordinates of the nonempty points in the output geometry are all set to `0`. For 3DM geometries, the geometry is projected on the xy-Cartesian plane, and the `z` coordinates of the nonempty points in the output geometry are all set to `0`. For 3DZ geometries, a copy of the input geometry is returned. For 4D geometries, the geometry is projected to the xyz-Cartesian space. Empty points in the input geometry remain empty points in the output geometry.

## Syntax
<a name="ST_Force3DZ-function-syntax"></a>

```
ST_Force3DZ(geom)
```

## Arguments
<a name="ST_Force3DZ-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Force3DZ-function-return"></a>

`GEOMETRY`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

If *geom* is empty, then an empty geometry is returned. 

## Examples
<a name="ST_Force3DZ-function-examples"></a>

The following SQL returns a 3DZ geometry from a 3DM geometry. 

```
SELECT ST_AsEWKT(ST_Force3DZ(ST_GeomFromText('MULTIPOINT M(0 1 2, EMPTY, 2 3 4, 5 6 7)')));
```

```
st_asewkt
-----------
  MULTIPOINT Z ((0 1 0),EMPTY,(2 3 0),(5 6 0))
```

# ST\$1Force4D
<a name="ST_Force4D-function"></a>

ST\$1Force4D returns a 4D geometry of the input geometry. For 2D geometries, the `z` and `m` coordinates of the nonempty points in the output geometry are all set to `0`. For 3DM geometries, the `z` coordinates of the nonempty points in the output geometry are all set to `0`. For 3DZ geometries, the `m` coordinates of the nonempty points in the output geometry are all set to `0`. For 4D geometries, a copy of the input geometry is returned. Empty points in the input geometry remain empty points in the output geometry.

## Syntax
<a name="ST_Force4D-function-syntax"></a>

```
ST_Force4D(geom)
```

## Arguments
<a name="ST_Force4D-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Force4D-function-return"></a>

`GEOMETRY`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* is null, then null is returned. 

If *geom* is empty, then an empty geometry is returned. 

## Examples
<a name="ST_Force4D-function-examples"></a>

The following SQL returns a 4D geometry from a 3DM geometry. 

```
SELECT ST_AsEWKT(ST_Force4D(ST_GeomFromText('MULTIPOINT M(0 1 2, EMPTY, 2 3 4, 5 6 7)')));
```

```
st_asewkt
-----------
  MULTIPOINT ZM ((0 1 0 2),EMPTY,(2 3 0 4),(5 6 0 7))
```

# ST\$1GeoHash
<a name="ST_GeoHash-function"></a>

ST\$1GeoHash returns the `geohash` representation of the input point with the specified precision. The default precision value is 20. For more information about the definition of geohash, see [Geohash](https://en.wikipedia.org/wiki/Geohash) in Wikipedia.

## Syntax
<a name="ST_GeoHash-function-syntax"></a>

```
ST_GeoHash(geom)
```

```
ST_GeoHash(geom, precision)
```

## Arguments
<a name="ST_GeoHash-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *precision*   
A value of data type `INTEGER`. The default is 20.

## Return type
<a name="ST_GeoHash-function-return"></a>

`GEOMETRY`

The function returns the `geohash` representation of the input point. 

If the input point is empty, the function returns null. 

If the input geometry is not a point, the function returns an error. 

## Examples
<a name="ST_GeoHash-function-examples"></a>

The following SQL returns the geohash representation of the input point. 

```
SELECT ST_GeoHash(ST_GeomFromText('POINT(45 -45)'), 25) AS geohash;
```

```
          geohash
---------------------------
 m000000000000000000000gzz
```

The following SQL returns null because the input point is empty. 

```
SELECT ST_GeoHash(ST_GeomFromText('POINT EMPTY'), 10) IS NULL AS result;
```

```
 result
---------
 true
```

# ST\$1GeogFromText
<a name="ST_GeogFromText-function"></a>

ST\$1GeogFromText constructs a geography object from a well-known text (WKT) or extended well-known text (EWKT) representation of an input geography. 

## Syntax
<a name="ST_GeogFromText-function-syntax"></a>

```
ST_GeogFromText(wkt_string)
```

## Arguments
<a name="ST_GeogFromText-function-arguments"></a>

 *wkt\$1string*   
A value of data type `VARCHAR` that is a WKT or EWKT representation of a geography.

## Return type
<a name="ST_GeogFromText-function-return"></a>

`GEOGRAPHY`

If the SRID value is set to the provided value in the input. If SRID is not provided, it is set to `4326`. 

If *wkt\$1string* is null, then null is returned. 

If *wkt\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeogFromText-function-examples"></a>

The following SQL constructs a polygon from a geography object with an SRID value. 

```
SELECT ST_AsEWKT(ST_GeogFromText('SRID=4324;POLYGON((0 0,0 1,1 1,10 10,1 0,0 0))'));
```

```
  st_asewkt
------------------------------------------------
 SRID=4324;POLYGON((0 0,0 1,1 1,10 10,1 0,0 0))
```

The following SQL constructs a polygon from a geography object. The SRID value is set to `4326`.

```
SELECT ST_AsEWKT(ST_GeogFromText('POLYGON((0 0,0 1,1 1,10 10,1 0,0 0))'));
```

```
 st_asewkt
------------------------------------------------
 SRID=4326;POLYGON((0 0,0 1,1 1,10 10,1 0,0 0))
```

# ST\$1GeogFromWKB
<a name="ST_GeogFromWKB-function"></a>

ST\$1GeogFromWKB constructs a geography object from a hexadecimal well-known binary (WKB) representation of an input geography. 

## Syntax
<a name="ST_GeogFromWKB-function-syntax"></a>

```
ST_GeogFromWKB(wkb_string)
```

## Arguments
<a name="ST_GeogFromWKB-function-arguments"></a>

 *wkb\$1string*   
A value of data type `VARCHAR` that is a hexadecimal WKB representation of a geography.

## Return type
<a name="ST_GeogFromWKB-function-return"></a>

`GEOGRAPHY`

If the SRID value is provided it is set to the provided value. If SRID is not provided, it is set to `4326`. 

If *wkb\$1string* is null, then null is returned. 

If *wkb\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeogFromWKB-function-examples"></a>

The following SQL constructs a geography from a hexadecimal WKB value. 

```
SELECT ST_AsEWKT(ST_GeogFromWKB('01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000'));
```

```
 st_asewkt
------------------------------------------
 SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0 0))
```

# ST\$1GeometryN
<a name="ST_GeometryN-function"></a>

ST\$1GeometryN returns a geometry pointed to by the input index of the input geometry, as follows: 
+ If the input is a point, linestring, or polygon, then a geometry is returned as is if the index is equal to one (1), and null if the index is other than one (1).
+ If the input is a multipoint, multilinestring, multipolygon, or geometry collection, then a point, linestring, polygon, or geometry collection is returned as pointed to by an input index. 

The index is one-based. The spatial reference system identifier (SRID) of the result is the same as that of the input geometry. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_GeometryN-function-syntax"></a>

```
ST_GeometryN(geom, index)
```

## Arguments
<a name="ST_GeometryN-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *index*   
A value of data type `INTEGER` that represents the position of a one-based index. 

## Return type
<a name="ST_GeometryN-function-return"></a>

`GEOMETRY` 

If *geom* or *index* is null, then null is returned. 

If *index* is out of range, then an error is returned. 

## Examples
<a name="ST_GeometryN-function-examples"></a>

The following SQL returns the geometries in a geometry collection. 

```
WITH tmp1(idx) AS (SELECT 1 UNION SELECT 2),
tmp2(g) AS (SELECT ST_GeomFromText('GEOMETRYCOLLECTION(POLYGON((0 0,10 0,0 10,0 0)),LINESTRING(20 10,20 0,10 0))'))
SELECT idx, ST_AsEWKT(ST_GeometryN(g, idx)) FROM tmp1, tmp2 ORDER BY idx;
```

```
 idx |          st_asewkt           
-----+------------------------------
   1 | POLYGON((0 0,10 0,0 10,0 0))
   2 | LINESTRING(20 10,20 0,10 0)
```

# ST\$1GeometryType
<a name="ST_GeometryType-function"></a>

ST\$1GeometryType returns the subtype of an input geometry as a string. 

For 3DM, 3DZ, and 4D geometry inputs, ST\$1GeometryType returns the same result as for 2D geometry inputs.

## Syntax
<a name="ST_GeometryType-function-syntax"></a>

```
ST_GeometryType(geom)
```

## Arguments
<a name="ST_GeometryType-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_GeometryType-function-return"></a>

`VARCHAR` representing the subtype of *geom*. 

If *geom* is null, then null is returned. 

The values returned are as follows.


| Returned string value | Geometry subtype | 
| --- | --- | 
| `ST_Point` | Returned if *geom* is a `POINT` subtype  | 
| `ST_LineString` | Returned if *geom* is a `LINESTRING` subtype  | 
| `ST_Polygon` | Returned if *geom* is a `POLYGON` subtype  | 
| `ST_MultiPoint` | Returned if *geom* is a `MULTIPOINT` subtype  | 
| `ST_MultiLineString` | Returned if *geom* is a `MULTILINESTRING` subtype  | 
| `ST_MultiPolygon` | Returned if *geom* is a `MULTIPOLYGON` subtype  | 
| `ST_GeometryCollection` | Returned if *geom* is a `GEOMETRYCOLLECTION` subtype  | 

## Examples
<a name="ST_GeometryType-function-examples"></a>

The following SQL returns the subtype of the input linestring geometry. 

```
SELECT ST_GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_geometrytype
-------------
 ST_LineString
```

# ST\$1GeomFromEWKB
<a name="ST_GeomFromEWKB-function"></a>

ST\$1GeomFromEWKB constructs a geometry object from the extended well-known binary (EWKB) representation of an input geometry. 

ST\$1GeomFromEWKB accepts 3DZ, 3DM, and 4D geometries written in WKB and EWKB hexadecimal format.

## Syntax
<a name="ST_GeomFromEWKB-function-syntax"></a>

```
ST_GeomFromEWKB(ewkb_string)
```

## Arguments
<a name="ST_GeomFromEWKB-function-arguments"></a>

 *ewkb\$1string*   
A value of data type `VARCHAR` that is a hexadecimal EWKB representation of a geometry.

## Return type
<a name="ST_GeomFromEWKB-function-return"></a>

`GEOMETRY`

If *ewkb\$1string* is null, then null is returned. 

If *ewkb\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromEWKB-function-examples"></a>

The following SQL constructs a polygon from an EWKB value and returns the EWKT representation of a polygon. 

```
SELECT ST_AsEWKT(ST_GeomFromEWKB('0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000'));
```

```
 st_asewkt
--------------------------------
 SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0 0))
```

# ST\$1GeomFromEWKT
<a name="ST_GeomFromEWKT-function"></a>

ST\$1GeomFromEWKT constructs a geometry object from the extended well-known text (EWKT) representation of an input geometry. 

ST\$1GeomFromEWKT accepts 3DZ, 3DM, and 4D where the geometry type is prefixed with Z, M, or ZM, respectively.

## Syntax
<a name="ST_GeomFromEWKT-function-syntax"></a>

```
ST_GeomFromEWKT(ewkt_string)
```

## Arguments
<a name="ST_GeomFromEWKT-function-arguments"></a>

 *ewkt\$1string*   
A value of data type `VARCHAR` or an expression that evaluates to a `VARCHAR` type, that is an EWKT representation of a geometry.  
You can use the WKT keyword `EMPTY` to designate an empty point, a multipoint with an empty point, or a geometry collection with an empty point. The following example creates an empty point.   

```
ST_GeomFromEWKT('SRID=4326;POINT EMPTY');
```

## Return type
<a name="ST_GeomFromEWKT-function-return"></a>

`GEOMETRY`

If *ewkt\$1string* is null, then null is returned. 

If *ewkt\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromEWKT-function-examples"></a>

The following SQL constructs a multilinestring from an EWKT value and returns a geometry. It also returns the ST\$1AsEWKT result of the geometry. 

```
SELECT ST_GeomFromEWKT('SRID=4326;MULTILINESTRING((1 0,1 0),(2 0,3 0),(4 0,5 0,6 0))') as geom, ST_AsEWKT(geom);
```

```
                                                                                                                                                       geom                                                                                                                                                       |                          st_asewkt                           
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------
 0105000020E610000003000000010200000002000000000000000000F03F0000000000000000000000000000F03F00000000000000000102000000020000000000000000000040000000000000000000000000000008400000000000000000010200000003000000000000000000104000000000000000000000000000001440000000000000000000000000000018400000000000000000 | SRID=4326;MULTILINESTRING((1 0,1 0),(2 0,3 0),(4 0,5 0,6 0))
```

# ST\$1GeomFromGeoHash
<a name="ST_GeomFromGeoHash-function"></a>

ST\$1GeomFromGeoHash constructs a geometry object from the geohash representation of an input geometry. ST\$1GeomFromGeoHash returns a two-dimensional (2D) geometry with the spatial reference identifier (SRID) of zero (0). For more information about the geohash format, see [Geohash](https://en.wikipedia.org/wiki/Geohash) in Wikipedia. 

## Syntax
<a name="ST_GeomFromGeoHash-function-syntax"></a>

```
ST_GeomFromGeoHash(geohash_string)
```

```
ST_GeomFromGeoHash(geohash_string, precision)
```

## Arguments
<a name="ST_GeomFromGeoHash-function-arguments"></a>

 *geohash\$1string*   
A value of data type `VARCHAR` or an expression that evaluates to a `VARCHAR` type, that is a geohash representation of a geometry.

 *precision*   
A value of data type `INTEGER` that represents the precision of the geohash. The value is the number of characters of the geohash to be used as precision. If the value is not specified, less than zero, or greater than the *geohash\$1string* length. then the *geohash\$1string* length is used.

## Return type
<a name="ST_GeomFromGeoHash-function-return"></a>

`GEOMETRY`

If *geohash\$1string* is null, then null is returned. 

If *geohash\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromGeoHash-function-examples"></a>

The following SQL returns a polygon with high precision. 

```
SELECT ST_AsText(ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz0'));
```

```
 st_asewkt       
-----------------------
 POLYGON((-115.172816 36.114646,-115.172816 36.114646,-115.172816 36.114646,-115.172816 36.114646,-115.172816 36.114646))
```

The following SQL returns a point with high precision. 

```
SELECT ST_AsText(ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz00'));
```

```
 st_asewkt       
-----------------------
 POINT(-115.172816 36.114646)
```

The following SQL returns a polygon with low precision. 

```
SELECT ST_AsText(ST_GeomFromGeoHash('9qq'));
```

```
 st_asewkt       
-----------------------
 POLYGON((-115.3125 35.15625,-115.3125 36.5625,-113.90625 36.5625,-113.90625 35.15625,-115.3125 35.15625))
```

The following SQL returns a polygon with precision 3. 

```
SELECT ST_AsText(ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 3));
```

```
 st_asewkt       
-----------------------
 POLYGON((-115.3125 35.15625,-115.3125 36.5625,-113.90625 36.5625,-113.90625 35.15625,-115.3125 35.15625))
```

# ST\$1GeomFromGeoJSON
<a name="ST_GeomFromGeoJSON-function"></a>

ST\$1GeomFromGeoJSON constructs a geometry object from the GeoJSON representation of an input geometry. For more information about the GeoJSON format, see [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) in Wikipedia. 

If there is at least one point with three or more coordinates, the resulting geometry is 3DZ, where the Z component is zero for the points that have only two coordinates. If all points in the input GeoJSON contain two coordinates or are empty, ST\$1GeomFromGeoJSON returns a 2D geometry. The returned geometry always has the spatial reference identifier (SRID) of 4326.

## Syntax
<a name="ST_GeomFromGeoJSON-function-syntax"></a>

```
ST_GeomFromGeoJSON(geojson_string)
```

## Arguments
<a name="ST_GeomFromGeoJSON-function-arguments"></a>

 *geojson\$1string*   
A value of data type `VARCHAR` or `SUPER`, or an expression that evaluates to a `VARCHAR` type, that is a GeoJSON representation of a geometry.

## Return type
<a name="ST_GeomFromGeoJSON-function-return"></a>

`GEOMETRY`

If *geojson\$1string* is null, then null is returned. 

If *geojson\$1string* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromGeoJSON-function-examples"></a>

The following SQL returns a 2D geometry represented in the input GeoJSON. 

```
SELECT ST_AsEWKT(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}'));
```

```
 st_asewkt       
-----------------------
 SRID=4326;POINT(1 2)
```

The following SQL returns a 3DZ geometry represented in the input GeoJSON. 

```
SELECT ST_AsEWKT(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[1,2,3],[4,5,6],[7,8,9]]}'));
```

```
 st_asewkt  
------------------------------------------
 SRID=4326;LINESTRING Z (1 2 3,4 5 6,7 8 9)
```

The following SQL returns 3DZ geometry when only one point has three coordinates while all other points have two coordinates in the input GeoJSON. 

```
SELECT ST_AsEWKT(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[0, 0],[0, 1, 8],[1, 0],[0, 0]]]}'));
```

```
 st_asewkt  
------------------------------------------------
 SRID=4326;POLYGON Z ((0 0 0,0 1 8,1 0 0,0 0 0))
```

# ST\$1GeomFromGeoSquare
<a name="ST_GeomFromGeoSquare-function"></a>

ST\$1GeomFromGeoSquare returns a geometry that covers the area that is represented by an input geosquare value. The returned geometry is always two-dimensional. To calculate a geosquare value, see [ST\$1GeoSquare](ST_GeoSquare-function.md).

## Syntax
<a name="ST_GeomFromGeoSquare-function-syntax"></a>

```
ST_GeomFromGeoSquare(geosquare)
```

```
ST_GeomFromGeoSquare(geosquare, max_depth)
```

## Arguments
<a name="ST_GeomFromGeoSquare-function-arguments"></a>

 *geosquare*   
A value of data type `BIGINT` or an expression that evaluates to a `BIGINT` type that is a geosquare value that describes the sequence of subdivisions made on the initial domain to reach the desired square. This value is calculated by [ST\$1GeoSquare](ST_GeoSquare-function.md).

 *max\$1depth*   
A value of data type `INTEGER` that represents the maximum number of domain subdivisions made on the initial domain. The value must be greater than or equal to `1`.

## Return type
<a name="ST_GeomFromGeoSquare-function-return"></a>

`GEOMETRY`

If *geosquare* is not valid, the function returns an error. 

If the input *max\$1depth* is not within range, the function returns an error. 

## Examples
<a name="ST_GeomFromGeoSquare-function-examples"></a>

The following SQL returns a geometry from a geosquare value.

```
SELECT ST_AsText(ST_GeomFromGeoSquare(797852));
```

```
 st_astext       
--------------------------------------------------------------------------------------------------------------------
 POLYGON((13.359375 52.3828125,13.359375 52.734375,13.7109375 52.734375,13.7109375 52.3828125,13.359375 52.3828125))
```

The following SQL returns a geometry from a geosquare value and a maximum depth of `3`. 

```
SELECT ST_AsText(ST_GeomFromGeoSquare(797852, 3));
```

```
 st_astext       
--------------------------------------
 POLYGON((0 45,0 90,45 90,45 45,0 45))
```

The following SQL first calculates the geosquare value for Seattle by specifying the x coordinate as longitude and the y coordinate as latitude (-122.3, 47.6). Then it returns the polygon for the geosquare. Although the output is a two-dimensional geometry, it can be used to calculate spatial data in terms of longitude and latitude.

```
SELECT ST_AsText(ST_GeomFromGeoSquare(ST_GeoSquare(ST_Point(-122.3, 47.6))));
```

```
 st_astext
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON((-122.335167014971 47.6080129947513,-122.335167014971 47.6080130785704,-122.335166931152 47.6080130785704,-122.335166931152 47.6080129947513,-122.335167014971 47.6080129947513))
```

# ST\$1GeomFromText
<a name="ST_GeomFromText-function"></a>

ST\$1GeomFromText constructs a geometry object from a well-known text (WKT) representation of an input geometry. 

ST\$1GeomFromText accepts 3DZ, 3DM, and 4D where the geometry type is prefixed with Z, M, or ZM, respectively.

## Syntax
<a name="ST_GeomFromText-function-syntax"></a>

```
ST_GeomFromText(wkt_string)
```

```
ST_GeomFromText(wkt_string, srid)
```

## Arguments
<a name="ST_GeomFromText-function-arguments"></a>

 *wkt\$1string*   
A value of data type `VARCHAR` that is a WKT representation of a geometry.  
You can use the WKT keyword `EMPTY` to designate an empty point, a multipoint with an empty point, or a geometry collection with an empty point. The following example creates a multipoint with one empty and one nonempty point.   

```
ST_GeomFromEWKT('MULTIPOINT(1 0,EMPTY)');
```

 *srid*   
A value of data type `INTEGER` that is a spatial reference identifier (SRID). If an SRID value is provided, the returned geometry has this SRID value. Otherwise, the SRID value of the returned geometry is set to zero (0).

## Return type
<a name="ST_GeomFromText-function-return"></a>

`GEOMETRY`

If *wkt\$1string* or *srid* is null, then null is returned. 

If *srid* is negative, then null is returned. 

If *wkt\$1string* is not valid, then an error is returned. 

If *srid* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromText-function-examples"></a>

The following SQL constructs a geometry object from the WKT representation and SRID value. 

```
SELECT ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326);
```

```
st_geomfromtext
--------------------------------
0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
```

# ST\$1GeomFromWKB
<a name="ST_GeomFromWKB-function"></a>

ST\$1GeomFromWKB constructs a geometry object from a hexadecimal well-known binary (WKB) representation of an input geometry. 

ST\$1GeomFromWKB accepts 3DZ, 3DM, and 4D geometries written in WKB hexadecimal format.

## Syntax
<a name="ST_GeomFromWKB-function-syntax"></a>

```
ST_GeomFromWKB(wkb_string)
```

```
ST_GeomFromWKB(wkb_string, srid)
```

## Arguments
<a name="ST_GeomFromWKB-function-arguments"></a>

 *wkb\$1string*   
A value of data type `VARCHAR` that is a hexadecimal WKB representation of a geometry.

 *srid*   
A value of data type `INTEGER` that is a spatial reference identifier (SRID). If an SRID value is provided, the returned geometry has this SRID value. Otherwise, the SRID value of the returned geometry is set to 0.

## Return type
<a name="ST_GeomFromWKB-function-return"></a>

`GEOMETRY`

If *wkb\$1string* or *srid* is null, then null is returned. 

If *srid* is negative, then null is returned. 

If *wkb\$1string* is not valid, then an error is returned. 

If *srid* is not valid, then an error is returned. 

## Examples
<a name="ST_GeomFromWKB-function-examples"></a>

The following SQL constructs a polygon from a WKB value and returns the WKT representation of a polygon. 

```
SELECT ST_AsText(ST_GeomFromWKB('01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000'));            
```

```
 st_astext
--------------------------------
 POLYGON((0 0,0 1,1 1,1 0,0 0))
```

# ST\$1GeoSquare
<a name="ST_GeoSquare-function"></a>

ST\$1GeoSquare recursively subdivides the domain ([-180, 180], [-90, 90]) into equal square regions called *geosquares* to a specified depth. The subdivision is based on the location of a provided point. One of the geosquares containing the point is subdivided at each step until reaching the maximum depth. The selection of this geosquare is stable, that is, the function result depends on the input arguments only. The function returns a unique value that identifies the final geosquare in which the point is located.

The ST\$1GeoSquare accepts a POINT where the x coordinate is representing the longitude, and the y coordinate is representing the latitude. The longitude and latitude are limited to [-180, 180] and [-90, 90], respectively. The output of ST\$1GeoSquare can be used as input to the [ST\$1GeomFromGeoSquare](ST_GeomFromGeoSquare-function.md) function.

There are 360° around the arc of the equatorial circumference of the Earth that are divided into two hemispheres (Eastern and Western), each with 180° of longitudinal lines (Meridians) from the 0° Meridian. By convention, the eastern longitudes are "\$1" (positive) coordinates when projected to an x-axis on a Cartesian plane and the western longitudes are "-" (negative) coordinates when projected to an x-axis on a Cartesian plane. There are 90° of latitudinal lines north and south of the 0° equatorial circumference of the Earth, each parallel to the 0° equatorial circumference of the Earth. By convention, the northern latitudinal lines intersect the "\$1" (positive) y-axis when projected to a Cartesian plane, and the southern latitudinal lines intersect the "-" (negative) y-axis when projected to a Cartesian plane. The spherical grid formed by the intersection of longitudinal lines and latitudinal lines is converted to a grid projected onto a Cartesian plane with standard positive and negative x-coordinates and positive and negative y-coordinates on the Cartesian plane.

The purpose of ST\$1GeoSquare is to tag or mark close points with equal code values. Points that are located in the same geosquare receive the same code value. A geosquare is used to encode geographic coordinates (latitude and longitude) into an integer. A larger region is divided into grids to delineate an area on a map with varying resolutions. A geosquare can be used for spatial indexing, spatial binning, proximity searches, location searching, and creating unique place identifiers. The [ST\$1GeoHash](ST_GeoHash-function.md) function follows a similar process of dividing a region into grids, but has a different encoding.

## Syntax
<a name="ST_GeoSquare-function-syntax"></a>

```
ST_GeoSquare(geom)
```

```
ST_GeoSquare(geom, max_depth)
```

## Arguments
<a name="ST_ST_GeoSquare-function-arguments"></a>

 *geom*   
A POINT value of data type `GEOMETRY` or an expression that evaluates to a POINT subtype. The x coordinate (longitude) of the point must be within the range: `-180` – `180`. The y coordinate (latitude) of the point must be within the range: `-90` – `90`. 

 *max\$1depth*   
A value of data type `INTEGER`. The maximum number of times the domain containing the point is subdivided recursively. The value must be an integer from 1 – 32. The default is 32. The actual final number of the subdivisions is less than or equal to the specified *max\$1depth*. 

## Return type
<a name="ST_GeoSquare-function-return"></a>

`BIGINT`

The function returns a unique value that identifies the final geosquare in which the input point is located. 

If the input *geom* is not a point, the function returns an error. 

If the input point is empty, the return value is not a valid input to the [ST\$1GeomFromGeoSquare](ST_GeomFromGeoSquare-function.md) function. Use the [ST\$1IsEmpty](ST_IsEmpty-function.md) function to prevent calls to ST\$1GeoSquare with an empty point. 

If the input point is not within range, the function returns an error. 

If the input *max\$1depth* is out of range, the function returns an error. 

## Examples
<a name="ST_ST_GeoSquare-function-examples"></a>

The following SQL returns a geosquare from an input point. 

```
SELECT ST_GeoSquare(ST_Point(13.5, 52.5));
```

```
  st_geosquare
-----------------------
 -4410772491521635895
```

The following SQL returns a geosquare from an input point with a maximum depth of `10`. 

```
SELECT ST_GeoSquare(ST_Point(13.5, 52.5), 10);
```

```
 st_geosquare
--------------
 797852
```

# ST\$1InteriorRingN
<a name="ST_InteriorRingN-function"></a>

ST\$1InteriorRingN returns a closed linestring corresponding to the interior ring of an input polygon at the index position. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_InteriorRingN-function-syntax"></a>

```
ST_InteriorRingN(geom, index)
```

## Arguments
<a name="ST_InteriorRingN-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *index*   
A value of data type `INTEGER` that represents the position of a ring of a one-based index. 

## Return type
<a name="ST_InteriorRingN-function-return"></a>

`GEOMETRY` of subtype `LINESTRING`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *geom* or *index* is null, then null is returned. 

If *index* is out of range, then null is returned. 

If *geom* is not a polygon, then null is returned. 

If *geom* is an empty polygon, then null is returned. 

## Examples
<a name="ST_InteriorRingN-function-examples"></a>

The following SQL returns the second ring of the polygon as a closed linestring. 

```
SELECT ST_AsEWKT(ST_InteriorRingN(ST_GeomFromText('POLYGON((7 9,8 7,11 6,15 8,16 6,17 7,17 10,18 12,17 14,15 15,11 15,10 13,9 12,7 9),(9 9,10 10,11 11,11 10,10 8,9 9),(12 14,15 14,13 11,12 14))'),2));
```

```
st_asewkt
-----------
 LINESTRING(12 14,15 14,13 11,12 14)
```

# ST\$1Intersects
<a name="ST_Intersects-function"></a>

ST\$1Intersects returns true if the 2D projections of the two input geometries have at least one point in common. 

## Syntax
<a name="ST_Intersects-function-syntax"></a>

```
ST_Intersects(geom1, geom2)
```

## Arguments
<a name="ST_Intersects-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Intersects-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Intersects-function-examples"></a>

The following SQL checks if the first polygon intersects the second polygon. 

```
SELECT ST_Intersects(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))'), ST_GeomFromText('MULTIPOINT((4 4),(6 6))'));
```

```
st_intersects              
-------------
 true
```

# ST\$1Intersection
<a name="ST_Intersection-function"></a>

ST\$1Intersection returns a geometry representing the point-set intersection of two geometries. That is, it returns the portion of the two input geometries that is shared between them. 

## Syntax
<a name="ST_Intersection-function-syntax"></a>

```
ST_Intersection(geom1, geom2)
```

## Arguments
<a name="ST_Intersection-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Intersection-function-return"></a>

`GEOMETRY`

If *geom1* and *geom2* don't share any space (they are disjoint), then an empty geometry is returned. 

If *geom1* or *geom2* are empty, then an empty geometry is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

If *geom1* or *geom2* is not a two-dimensional (2D) geometry, then an error is returned. 

## Examples
<a name="ST_Intersection-function-examples"></a>

The following SQL returns the non-empty geometry representing the intersection of two input geometries. 

```
SELECT ST_AsEWKT(ST_Intersection(ST_GeomFromText('polygon((0 0,100 100,0 200,0 0))'), ST_GeomFromText('polygon((0 0,10 0,0 10,0 0))')));
```

```
        st_asewkt        
-------------------------
 POLYGON((0 0,0 10,5 5,0 0))
```

The following SQL returns an empty geometry when passed disjoint (non-intersecting) input geometries. 

```
SELECT ST_AsEWKT(ST_Intersection(ST_GeomFromText('linestring(0 100,0 0)'), ST_GeomFromText('polygon((1 0,10 0,1 10,1 0))')));
```

```
    st_asewkt     
------------------
 LINESTRING EMPTY
```

# ST\$1IsPolygonCCW
<a name="ST_IsPolygonCCW-function"></a>

ST\$1IsPolygonCCW returns true if the 2D projection of the input polygon or multipolygon is counterclockwise. If the input geometry is a point, linestring, multipoint, or multilinestring, then true is returned. For geometry collections, ST\$1IsPolygonCCW returns true if all the geometries in the collection are counterclockwise. 

## Syntax
<a name="ST_IsPolygonCCW-function-syntax"></a>

```
ST_IsPolygonCCW(geom)
```

## Arguments
<a name="ST_IsPolygonCCW-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsPolygonCCW-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsPolygonCCW-function-examples"></a>

The following SQL checks if the polygon is counterclockwise. 

```
SELECT ST_IsPolygonCCW(ST_GeomFromText('POLYGON((7 9,8 7,11 6,15 8,16 6,17 7,17 10,18 12,17 14,15 15,11 15,10 13,9 12,7 9),(9 9,10 10,11 11,11 10,10 8,9 9),(12 14,15 14,13 11,12 14))'));
```

```
 st_ispolygonccw
----------
 true
```

# ST\$1IsPolygonCW
<a name="ST_IsPolygonCW-function"></a>

ST\$1IsPolygonCW returns true if the 2D projection of the input polygon or multipolygon is clockwise. If the input geometry is a point, linestring, multipoint, or multilinestring, then true is returned. For geometry collections, ST\$1IsPolygonCW returns true if all the geometries in the collection are clockwise. 

## Syntax
<a name="ST_IsPolygonCW-function-syntax"></a>

```
ST_IsPolygonCW(geom)
```

## Arguments
<a name="ST_IsPolygonCW-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsPolygonCW-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsPolygonCW-function-examples"></a>

The following SQL checks if the polygon is clockwise. 

```
SELECT ST_IsPolygonCW(ST_GeomFromText('POLYGON((7 9,8 7,11 6,15 8,16 6,17 7,17 10,18 12,17 14,15 15,11 15,10 13,9 12,7 9),(9 9,10 10,11 11,11 10,10 8,9 9),(12 14,15 14,13 11,12 14))'));
```

```
 st_ispolygonccw
----------
 true
```

# ST\$1IsClosed
<a name="ST_IsClosed-function"></a>

ST\$1IsClosed returns true if the 2D projection of the input geometry is closed. The following rules define a closed geometry: 
+ The input geometry is a point or a multipoint. 
+ The input geometry is a linestring, and the start and end points of the linestring coincide. 
+ The input geometry is a nonempty multilinestring and all its linestrings are closed. 
+ The input geometry is a nonempty polygon, all polygon's rings are nonempty, and the start and end points of all its rings coincide. 
+ The input geometry is a nonempty multipolygon and all its polygons are closed.
+ The input geometry is a nonempty geometry collection and all its components are closed. 

## Syntax
<a name="ST_IsClosed-function-syntax"></a>

```
ST_IsClosed(geom)
```

## Arguments
<a name="ST_IsClosed-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsClosed-function-return"></a>

`BOOLEAN`

If *geom* is an empty point, then false is returned. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsClosed-function-examples"></a>

The following SQL checks if the polygon is closed. 

```
SELECT ST_IsClosed(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'));
```

```
st_isclosed
-----------
 true
```

# ST\$1IsCollection
<a name="ST_IsCollection-function"></a>

ST\$1IsCollection returns true if the input geometry is one of the following subtypes: `GEOMETRYCOLLECTION`, `MULTIPOINT`, `MULTILINESTRING`, or `MULTIPOLYGON`. 

## Syntax
<a name="ST_IsCollection-function-syntax"></a>

```
ST_IsCollection(geom)
```

## Arguments
<a name="ST_IsCollection-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsCollection-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsCollection-function-examples"></a>

The following SQL checks if the polygon is a collection. 

```
SELECT ST_IsCollection(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'));
```

```
st_iscollection
-----------
 false
```

# ST\$1IsEmpty
<a name="ST_IsEmpty-function"></a>

ST\$1IsEmpty returns true if the input geometry is empty. A geometry is not empty if it contains at least one nonempty point. 

ST\$1IsEmpty returns true if the input geometry has at least one nonempty point. 

## Syntax
<a name="ST_IsEmpty-function-syntax"></a>

```
ST_IsEmpty(geom)
```

## Arguments
<a name="ST_IsEmpty-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsEmpty-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsEmpty-function-examples"></a>

The following SQL checks if the specified polygon is empty. 

```
SELECT ST_IsEmpty(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'));
```

```
st_isempty
-----------
 false
```

# ST\$1IsRing
<a name="ST_IsRing-function"></a>

ST\$1IsRing returns true if the input linestring is a ring. A linestring is a ring if it is closed and simple. 

## Syntax
<a name="ST_IsRing-function-syntax"></a>

```
ST_IsRing(geom)
```

## Arguments
<a name="ST_IsRing-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The geometry must be a `LINESTRING`.

## Return type
<a name="ST_IsRing-function-return"></a>

`BOOLEAN`

If *geom* is not a `LINESTRING`, then an error is returned. 

## Examples
<a name="ST_IsRing-function-examples"></a>

The following SQL checks if the specified linestring is a ring. 

```
SELECT ST_IsRing(ST_GeomFromText('linestring(0 0, 1 1, 1 2, 0 0)'));
```

```
st_isring
-----------
 true
```

# ST\$1IsSimple
<a name="ST_IsSimple-function"></a>

ST\$1IsSimple returns true if the 2D projection of the input geometry is simple. For more information about the definition of a simple geometry, see [Geometric simplicity](spatial-terminology.md#spatial-terminology-simplicity). 

## Syntax
<a name="ST_IsSimple-function-syntax"></a>

```
ST_IsSimple(geom)
```

## Arguments
<a name="ST_IsSimple-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsSimple-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsSimple-function-examples"></a>

The following SQL checks if the specified linestring is simple. In this example, it isn't simple because it has self-intersection. 

```
SELECT ST_IsSimple(ST_GeomFromText('LINESTRING(0 0,10 0,5 5,5 -5)'));
```

```
 st_issimple
-----------
 false
```

# ST\$1IsValid
<a name="ST_IsValid-function"></a>

ST\$1IsValid returns true if the 2D projection of the input geometry is valid. For more information about the definition of a valid geometry, see [Geometric validity](spatial-terminology.md#spatial-terminology-validity). 

## Syntax
<a name="ST_IsValid-function-syntax"></a>

```
ST_IsValid(geom)
```

## Arguments
<a name="ST_IsValid-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_IsValid-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned. 

## Examples
<a name="ST_IsValid-function-examples"></a>

The following SQL checks if the specified polygon is valid. In this example, the polygon is invalid because the interior of the polygon isn't simply connected. 

```
SELECT ST_IsValid(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 0,10 5,5 10,0 5,5 0))'));
```

```
 st_isvalid
-----------
 false
```

# ST\$1Length
<a name="ST_Length-function"></a>

For a linear geometry, ST\$1Length returns the Cartesian length of a 2D projection. The length units are the same as the units in which the coordinates of the input geometry are expressed. The function returns zero (0) for points, multipoints, and areal geometries. When the input is a geometry collection, the function returns the sum of the lengths of the geometries in the collection. 

For a geography, ST\$1Length returns the geodesic length of the 2D projection of an input linear geography computed on the spheroid determined by the SRID. The unit of length is in meters. The function returns zero (0) for points, multipoints, and areal geographies. When the input is a geometry collection, the function returns the sum of the lengths of the geographies in the collection.

## Syntax
<a name="ST_Length-function-syntax"></a>

```
ST_Length(geo)
```

## Arguments
<a name="ST_Length-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_Length-function-return"></a>

`DOUBLE PRECISION`

If *geo* is null, then null is returned.

If the SRID value is not found, then an error is returned.

## Examples
<a name="ST_Length-function-examples"></a>

The following SQL returns the Cartesian length of a multilinestring. 

```
SELECT ST_Length(ST_GeomFromText('MULTILINESTRING((0 0,10 0,0 10),(10 0,20 0,20 10))'));
```

```
st_length
--------------------------------
  44.142135623731
```

The following SQL returns the length of a linestring in a geography. 

```
SELECT ST_Length(ST_GeogFromText('SRID=4326;LINESTRING(5 0,6 0,4 0)'));
```

```
 st_length 
------------------
 333958.472379804
```

The following SQL returns the length of a point in a geography. 

```
SELECT ST_Length(ST_GeogFromText('SRID=4326;POINT(4 5)'));
```

```
 st_length 
-----------
 0
```

# ST\$1LengthSphere
<a name="ST_LengthSphere-function"></a>

ST\$1LengthSphere returns the length of a linear geometry in meters. For point, multipoint, and areal geometries, ST\$1LengthSphere returns 0. For geometry collections, ST\$1LengthSphere returns the total length of the linear geometries in the collection in meters. 

ST\$1LengthSphere interprets the coordinates of each point of the input geometry as longitude and latitude in degrees. For 3DZ, 3DM, or 4D geometries, only the first two coordinates are used.

## Syntax
<a name="ST_LengthSphere-function-syntax"></a>

```
ST_LengthSphere(geom)
```

## Arguments
<a name="ST_LengthSphere-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_LengthSphere-function-return"></a>

`DOUBLE PRECISION` length in meters. The length computation is based on the spherical model of the Earth whose radius is Earth's mean radius of the World Geodetic System (WGS) 84 ellipsoidal model of the Earth. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_LengthSphere-function-examples"></a>

The following example SQL computes the length of a linestring in meters. 

```
SELECT ST_LengthSphere(ST_GeomFromText('LINESTRING(10 10,45 45)'));
```

```
 st_lengthsphere  
------------------
 5127736.08292556
```

# ST\$1Length2D
<a name="ST_Length2D-function"></a>

ST\$1Length2D is an alias for ST\$1Length. For more information, see [ST\$1Length](ST_Length-function.md). 

# ST\$1LineFromMultiPoint
<a name="ST_LineFromMultiPoint-function"></a>

ST\$1LineFromMultiPoint returns a linestring from an input multipoint geometry. The order of the points is preserved. The spatial reference system identifier (SRID) of the returned geometry is the same as that of the input geometry. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_LineFromMultiPoint-function-syntax"></a>

```
ST_LineFromMultiPoint(geom)
```

## Arguments
<a name="ST_LineFromMultiPoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `MULTIPOINT`. 

## Return type
<a name="ST_LineFromMultiPoint-function-return"></a>

`GEOMETRY`

If *geom* is null, then null is returned. 

If *geom* is empty, then an empty `LINESTRING` is returned. 

If *geom* contains empty points, then these empty points are ignored. 

If *geom* isn't a `MULTIPOINT`, then error is returned. 

## Examples
<a name="ST_LineFromMultiPoint-function-examples"></a>

The following SQL creates a linestring from a multipoint. 

```
SELECT ST_AsEWKT(ST_LineFromMultiPoint(ST_GeomFromText('MULTIPOINT(0 0,10 0,10 10,5 5,0 5)',4326)));
```

```
 st_asewkt
---------------------------------------------
 SRID=4326;LINESTRING(0 0,10 0,10 10,5 5,0 5)
```

# ST\$1LineInterpolatePoint
<a name="ST_LineInterpolatePoint-function"></a>

ST\$1LineInterpolatePoint returns a point along a line at a fractional distance from the start of the line. 

To determine point equality, ST\$1LineInterpolatePoint operates on the 2D projection of the input geometry. If the input geometry is empty, a copy of it is returned in the same dimension as the input. For 3DZ, 3DM, and 4D geometries, the `z` or `m` coordinate is the average of the `z` or `m` coordinates of the segment where the point lies.

## Syntax
<a name="ST_LineInterpolatePoint-function-syntax"></a>

```
ST_LineInterpolatePoint(geom, fraction)
```

## Arguments
<a name="ST_LineInterpolatePoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype is `LINESTRING`. 

 *fraction*   
A value of data type `DOUBLE PRECISION` that represents the position of a point along the linestring for the line. The value is a fraction in the range 0–1, inclusive. 

## Return type
<a name="ST_LineInterpolatePoint-function-return"></a>

`GEOMETRY` of subtype `POINT`. 

If *geom* or *fraction* is null, then null is returned. 

If *geom* is empty, then the empty point is returned. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

If *fraction* is out of range, then an error is returned. 

If *geom* is not a linestring, then an error is returned. 

## Examples
<a name="ST_LineInterpolatePoint-function-examples"></a>

The following SQL returns a point halfway along a linestring.

```
SELECT ST_AsEWKT(ST_LineInterpolatePoint(ST_GeomFromText('LINESTRING(0 0, 5 5, 7 7, 10 10)'), 0.50));
```

```
st_asewkt
-----------
 POINT(5 5)
```

The following SQL returns a point 90 percent of the way along a linestring.

```
SELECT ST_AsEWKT(ST_LineInterpolatePoint(ST_GeomFromText('LINESTRING(0 0, 5 5, 7 7, 10 10)'), 0.90));
```

```
st_asewkt
-----------
 POINT(9 9)
```

# ST\$1M
<a name="ST_M-function"></a>

ST\$1M returns the `m` coordinate of an input point. 

## Syntax
<a name="ST_M-function-syntax"></a>

```
ST_M(point)
```

## Arguments
<a name="ST_M-function-arguments"></a>

 *point*   
A `POINT` value of data type `GEOMETRY`. 

## Return type
<a name="ST_M-function-return"></a>

`DOUBLE PRECISION` value of the `m` coordinate.

If *point* is null, then null is returned. 

If *point* is a 2D or 3DZ point, then null is returned. 

If *point* is the empty point, then null is returned. 

If *point* is not a `POINT`, then an error is returned. 

## Examples
<a name="ST_M-function-examples"></a>

The following SQL returns the `m` coordinate of a point in a 3DM geometry. 

```
SELECT ST_M(ST_GeomFromEWKT('POINT M (1 2 3)'));
```

```
st_m
-----------
 3
```

The following SQL returns the `m` coordinate of a point in a 4D geometry. 

```
SELECT ST_M(ST_GeomFromEWKT('POINT ZM (1 2 3 4)'));
```

```
st_m
-----------
 4
```

# ST\$1MakeEnvelope
<a name="ST_MakeEnvelope-function"></a>

ST\$1MakeEnvelope returns a geometry as follows:
+ If the input coordinates specify a point, then the returned geometry is a point. 
+ If the input coordinates specify a line, then the returned geometry is a linestring. 
+ Otherwise, the returned geometry is a polygon, where the input coordinates specify the lower-left and upper-right corners of a box. 

If provided, the spatial reference system identifier (SRID) value of the returned geometry is set to the input SRID value. 

## Syntax
<a name="ST_MakeEnvelope-function-syntax"></a>

```
ST_MakeEnvelope(xmin, ymin, xmax, ymax)
```

```
ST_MakeEnvelope(xmin, ymin, xmax, ymax, srid)
```

## Arguments
<a name="ST_MakeEnvelope-function-arguments"></a>

 *xmin*   
A value of data type `DOUBLE PRECISION`. This value is the first coordinate of the lower-left corner of a box. 

 *ymin*   
A value of data type `DOUBLE PRECISION`. This value is the second coordinate of the lower-left corner of a box. 

 *xmax*   
A value of data type `DOUBLE PRECISION`. This value is the first coordinate of the upper-right corner of a box. 

 *ymax*   
A value of data type `DOUBLE PRECISION`. This value is the second coordinate of the upper-right corner of a box. 

 *srid*   
A value of data type `INTEGER` that represents a spatial reference system identifier (SRID). If the SRID value is not provided, then it is set to zero. 

## Return type
<a name="ST_MakeEnvelope-function-return"></a>

`GEOMETRY` of subtype `POINT`, `LINESTRING`, or `POLYGON`. 

The SRID of the returned geometry is set to `srid` or zero if `srid` isn't set. 

If *xmin*, *ymin*, *xmax*, *ymax*, or *srid* is null, then null is returned.

If *srid* is negative, then an error is returned. 

## Examples
<a name="ST_MakeEnvelope-function-examples"></a>

The following SQL returns a polygon representing an envelope defined by the four input coordinate values. 

```
SELECT ST_AsEWKT(ST_MakeEnvelope(2,4,5,7));
```

```
 st_astext
---------------
 POLYGON((2 4,2 7,5 7,5 4,2 4))
```

The following SQL returns a polygon representing an envelope defined by the four input coordinate values and an SRID value. 

```
SELECT ST_AsEWKT(ST_MakeEnvelope(2,4,5,7,4326));
```

```
 st_astext
----------------------------------
 SRID=4326;POLYGON((2 4,2 7,5 7,5 4,2 4))
```

# ST\$1MakeLine
<a name="ST_MakeLine-function"></a>

ST\$1MakeLine creates a linestring from the input geometries. 

The dimension of the returned geometry is the same as that of the input geometries. Both input geometries must of the same dimension.

## Syntax
<a name="ST_MakeLine-function-syntax"></a>

```
ST_MakeLine(geom1, geom2)
```

## Arguments
<a name="ST_MakeLine-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`, `LINESTRING`, or `MULTIPOINT`. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`, `LINESTRING`, or `MULTIPOINT`. 

## Return type
<a name="ST_MakeLine-function-return"></a>

`GEOMETRY` of subtype `LINESTRING`. 

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* is the empty point or contains empty points, then these empty points are ignored. 

If *geom1* and *geom2* are empty, then the empty `LINESTRING` is returned. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometries. 

If *geom1* and *geom2* have different SRID values, then an error is returned. 

If *geom1* or *geom2* is not a `POINT`, `LINESTRING`, or `MULTIPOINT`, then an error is returned. 

If *geom1* and *geom2* have different dimensions, then an error is returned. 

## Examples
<a name="ST_MakeLine-function-examples"></a>

The following SQL constructs a linestring from two input linestrings. 

```
SELECT ST_MakeLine(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'), ST_GeomFromText('LINESTRING(88.29 39.07,88.42 39.26,88.27 39.31,88.29 39.07)'));
```

```
st_makeline
-----------
 010200000008000000C3F5285C8F52534052B81E85EB113D407B14AE47E15A5340C3F5285C8F423D40E17A14AE475153408FC2F5285C4F3D40C3F5285C8F52534052B81E85EB113D40C3F5285C8F125640295C8FC2F58843407B14AE47E11A5640E17A14AE47A14340E17A14AE4711564048E17A14AEA74340C3F5285C8F125640295C8FC2F5884340
```

# ST\$1MakePoint
<a name="ST_MakePoint-function"></a>

ST\$1MakePoint returns a point geometry whose coordinate values are the input values. 

## Syntax
<a name="ST_MakePoint-function-syntax"></a>

```
ST_MakePoint(x, y)
```

```
ST_MakePoint(x, y, z)
```

```
ST_MakePoint(x, y, z, m)
```

## Arguments
<a name="ST_MakePoint-function-arguments"></a>

 *x*   
A value of data type `DOUBLE PRECISION` representing the first coordinate. 

 *y*   
A value of data type `DOUBLE PRECISION` representing the second coordinate. 

 *z*   
A value of data type `DOUBLE PRECISION` representing the third coordinate. 

 *m*   
A value of data type `DOUBLE PRECISION` representing the fourth coordinate. 

## Return type
<a name="ST_MakePoint-function-return"></a>

`GEOMETRY` of subtype `POINT`. 

The spatial reference system identifier (SRID) value of the returned geometry is set to 0. 

If *x*, *y*, *z*, or *m* is null, then null is returned. 

## Examples
<a name="ST_MakePoint-function-examples"></a>

The following SQL returns a `GEOMETRY` type of subtype `POINT` with the provided coordinates. 

```
SELECT ST_AsText(ST_MakePoint(1,3));
```

```
st_astext
-----------
 POINT(1 3)
```

The following SQL returns a `GEOMETRY` type of subtype `POINT` with the provided coordinates. 

```
SELECT ST_AsEWKT(ST_MakePoint(1, 2, 3));
```

```
st_asewkt
----------------
 POINT Z (1 2 3)
```

The following SQL returns a `GEOMETRY` type of subtype `POINT` with the provided coordinates. 

```
SELECT ST_AsEWKT(ST_MakePoint(1, 2, 3, 4));
```

```
st_asewkt
-------------------
 POINT ZM (1 2 3 4)
```

# ST\$1MakePolygon
<a name="ST_MakePolygon-function"></a>

ST\$1MakePolygon has two variants that return a polygon. One takes a single geometry, and another takes two geometries. 
+ The input of the first variant is a linestring that defines the outer ring of the output polygon.
+ The input of the second variant is a linestring and a multilinestring. Both of these are empty or closed. 

  The boundary of the exterior ring of the output polygon is the input linestring, and the boundaries of the interior rings of the polygon are the linestrings in the input multilinestring. If the input linestring is empty, an empty polygon is returned. Empty linestrings in the multilinestring are disregarded. The spatial reference system identifier (SRID) of the resulting geometry is the common SRID of the two input geometries.

The dimension of the returned geometry is the same as that of the input geometries. The exterior ring and interior rings must of the same dimension.

## Syntax
<a name="ST_MakePolygon-function-syntax"></a>

```
ST_MakePolygon(geom1)
```

```
ST_MakePolygon(geom1, geom2)
```

## Arguments
<a name="ST_MakePolygon-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. The *linestring* value must be closed or empty.

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `MULTILINESTRING`. 

## Return type
<a name="ST_MakePolygon-function-return"></a>

`GEOMETRY` of subtype `POLYGON`. 

The spatial reference system identifier (SRID) of the returned geometry is equal to the SRID of the inputs. 

If *geom1*, or *geom2* is null, then null is returned. 

If *geom1* is not a linestring, then an error is returned. 

If *geom2* is not a multilinestring, then an error is returned. 

If *geom1* is not closed, then an error is returned. 

If *geom1* is a single point or is not closed, then an error is returned. 

If *geom2* contains at least one linestring that has a single point or is not closed, then an error is returned. 

If *geom1* and *geom2* have different SRID values, then an error is returned. 

If *geom1* and *geom2* have different dimensions, then an error is returned. 

## Examples
<a name="ST_MakePolygon-function-examples"></a>

The following SQL returns a polygon from an input linestring. 

```
SELECT ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')));
```

```
 st_astext
---------------
POLYGON((77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07))
```

The following SQL creates a polygon from a closed linestring and a closed multilinestring. The linestring is used for the exterior ring of the polygon. The linestrings in the multilinestrings are used for the interior rings of the polygon. 

```
SELECT ST_AsEWKT(ST_MakePolygon(ST_GeomFromText('LINESTRING(0 0,10 0,10 10,0 10,0 0)'), ST_GeomFromText('MULTILINESTRING((1 1,1 2,2 1,1 1),(3 3,3 4,4 3,3 3))')));
```

```
 st_astext
----------------------------------
POLYGON((0 0,10 0,10 10,0 10,0 0),(1 1,1 2,2 1,1 1),(3 3,3 4,4 3,3 3))
```

# ST\$1MemSize
<a name="ST_MemSize-function"></a>

ST\$1MemSize returns the amount of memory space (in bytes) used by the input geometry. This size depends on the Amazon Redshift internal representation of the geometry and thus can change if the internal representation changes. You can use this size as an indication of the relative size of geometry objects in Amazon Redshift. 

## Syntax
<a name="ST_MemSize-function-syntax"></a>

```
ST_MemSize(geom)
```

## Arguments
<a name="ST_MemSize-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_MemSize-function-return"></a>

`INTEGER` representing the inherent dimension of *geom*. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_MemSize-function-examples"></a>

The following SQL returns the memory size of a geometry collection. 

```
SELECT ST_MemSize(ST_GeomFromText('GEOMETRYCOLLECTION(POLYGON((0 0,10 0,0 10,0 0)),LINESTRING(20 10,20 0,10 0))'))::varchar + ' bytes';
```

```
 ?column?  
-----------
 172 bytes
```

# ST\$1MMax
<a name="ST_MMax-function"></a>

ST\$1MMax returns the maximum `m` coordinate of an input geometry. 

## Syntax
<a name="ST_MMax-function-syntax"></a>

```
ST_MMax(geom)
```

## Arguments
<a name="ST_MMax-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_MMax-function-return"></a>

`DOUBLE PRECISION` value of the maximum `m` coordinate.

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

If *geom* is a 2D or 3DZ geometry, then null is returned. 

## Examples
<a name="ST_MMax-function-examples"></a>

The following SQL returns the largest `m` coordinate of a linestring in a 3DM geometry. 

```
SELECT ST_MMax(ST_GeomFromEWKT('LINESTRING M (0 1 2, 3 4 5, 6 7 8)'));
```

```
st_mmax
-----------
  8
```

The following SQL returns the largest `m` coordinate of a linestring in a 4D geometry. 

```
SELECT ST_MMax(ST_GeomFromEWKT('LINESTRING ZM (0 1 2 3, 4 5 6 7, 8 9 10 11)'));
```

```
st_mmax
-----------
  11
```

# ST\$1MMin
<a name="ST_MMin-function"></a>

ST\$1MMin returns the minimum `m` coordinate of an input geometry. 

## Syntax
<a name="ST_MMin-function-syntax"></a>

```
ST_MMin(geom)
```

## Arguments
<a name="ST_MMin-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_MMin-function-return"></a>

`DOUBLE PRECISION` value of the minimum `m` coordinate. 

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

If *geom* is a 2D or 3DZ geometry, then null is returned. 

## Examples
<a name="ST_MMin-function-examples"></a>

The following SQL returns the smallest `m` coordinate of a linestring in a 3DM geometry. 

```
SELECT ST_MMin(ST_GeomFromEWKT('LINESTRING M (0 1 2, 3 4 5, 6 7 8)'));
```

```
st_mmin
-----------
  2
```

The following SQL returns the smallest `m` coordinate of a linestring in a 4D geometry. 

```
SELECT ST_MMin(ST_GeomFromEWKT('LINESTRING ZM (0 1 2 3, 4 5 6 7, 8 9 10 11)'));
```

```
st_mmin
-----------
  3
```

# ST\$1Multi
<a name="ST_Multi-function"></a>

ST\$1Multi converts a geometry to the corresponding multitype. If the input geometry is already a multitype or a geometry collection, a copy of it is returned. If the input geometry is a point, linestring, or polygon, then a multipoint, multilinestring, or multipolygon, respectively, that contains the input geometry is returned. 

## Syntax
<a name="ST_Multi-function-syntax"></a>

```
ST_Multi(geom)
```

## Arguments
<a name="ST_Multi-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Multi-function-return"></a>

`GEOMETRY` with subtype `MULTIPOINT`, `MULTILINESTRING`, `MULTIPOLYGON`, or `GEOMETRYCOLLECTION`. 

The spatial reference system identifier (SRID) of the returned geometry is the same as that of the input geometry. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_Multi-function-examples"></a>

The following SQL returns a multipoint from an input multipoint. 

```
SELECT ST_AsEWKT(ST_Multi(ST_GeomFromText('MULTIPOINT((1 2),(3 4))', 4326)));
```

```
    st_asewkt
------------------------------------
  SRID=4326;MULTIPOINT((1 2),(3 4))
```

The following SQL returns a multipoint from an input point. 

```
SELECT ST_AsEWKT(ST_Multi(ST_GeomFromText('POINT(1 2)', 4326)));
```

```
    st_asewkt
------------------------------------
  SRID=4326;MULTIPOINT((1 2))
```

The following SQL returns a geometry collection from an input geometry collection. 

```
SELECT ST_AsEWKT(ST_Multi(ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 2),MULTIPOINT((1 2),(3 4)))', 4326)));
```

```
    st_asewkt
------------------------------------
  SRID=4326;GEOMETRYCOLLECTION(POINT(1 2),MULTIPOINT((1 2),(3 4)))
```

# ST\$1NDims
<a name="ST_NDims-function"></a>

ST\$1NDims returns the coordinate dimension of a geometry. ST\$1NDims doesn't consider the topological dimension of a geometry. Instead, it returns a constant value depending on the dimension of the geometry. 

## Syntax
<a name="ST_NDims-function-syntax"></a>

```
ST_NDims(geom)
```

## Arguments
<a name="ST_NDims-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_NDims-function-return"></a>

`INTEGER` representing the inherent dimension of *geom*. 

If *geom* is null, then null is returned. 

The values returned are as follows.


| Returned value | Dimension of input geometry | 
| --- | --- | 
| 2 | 2D | 
| 3 | 3DZ or 3DM | 
| 4 | 4D | 

## Examples
<a name="ST_NDims-function-examples"></a>

The following SQL returns the number of dimensions of a 2D linestring. 

```
SELECT ST_NDims(ST_GeomFromText('LINESTRING(0 0,1 1,2 2,0 0)'));
```

```
st_ndims
-------------
 2
```

The following SQL returns the number of dimensions of a 3DZ linestring. 

```
SELECT ST_NDims(ST_GeomFromText('LINESTRING Z(0 0 3,1 1 3,2 2 3,0 0 3)'));
```

```
st_ndims
-------------
 3
```

The following SQL returns the number of dimensions of a 3DM linestring. 

```
SELECT ST_NDims(ST_GeomFromText('LINESTRING M(0 0 4,1 1 4,2 2 4,0 0 4)'));
```

```
st_ndims
-------------
 3
```

The following SQL returns the number of dimensions of a 4D linestring. 

```
SELECT ST_NDims(ST_GeomFromText('LINESTRING ZM(0 0 3 4,1 1 3 4,2 2 3 4,0 0 3 4)'));
```

```
st_ndims
-------------
 4
```

# ST\$1NPoints
<a name="ST_NPoints-function"></a>

ST\$1NPoints returns the number of nonempty points in an input geometry or geography. 

## Syntax
<a name="ST_NPoints-function-syntax"></a>

```
ST_NPoints(geo)
```

## Arguments
<a name="ST_NPoints-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_NPoints-function-return"></a>

`INTEGER`

If *geo* is an empty point, then `0` is returned. 

If *geo* is null, then null is returned. 

## Examples
<a name="ST_NPoints-function-examples"></a>

The following SQL returns the number of points in a linestring. 

```
SELECT ST_NPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_npoints
-------------
 4
```

The following SQL returns the number of points in a linestring in a geography. 

```
SELECT ST_NPoints(ST_GeogFromText('LINESTRING(110 40, 2 3, -10 80, -7 9)'));
```

```
st_npoints
-------------
 4
```

# ST\$1NRings
<a name="ST_NRings-function"></a>

ST\$1NRings returns the number of rings in an input geometry. 

## Syntax
<a name="ST_NRings-function-syntax"></a>

```
ST_NRings(geom)
```

## Arguments
<a name="ST_NRings-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_NRings-function-return"></a>

`INTEGER`

If *geom* is null, then null is returned. 

The values returned are as follows.


| Returned value | Geometry subtype | 
| --- | --- | 
| 0 | Returned if *geom* is a `POINT`, `LINESTRING`, `MULTIPOINT`, or `MULTILINESTRING` subtype  | 
| The number of rings. | Returned if *geom* is a `POLYGON` or `MULTIPOLYGON` subtype | 
| The number of rings in all components | Returned if *geom* is a `GEOMETRYCOLLECTION` subtype | 

## Examples
<a name="ST_NRings-function-examples"></a>

The following SQL returns the number of rings in a multipolygon. 

```
SELECT ST_NRings(ST_GeomFromText('MULTIPOLYGON(((0 0,10 0,0 10,0 0)),((0 0,-10 0,0 -10,0 0)))'));
```

```
 st_nrings
-------------
 2
```

# ST\$1NumGeometries
<a name="ST_NumGeometries-function"></a>

ST\$1NumGeometries returns the number of geometries in an input geometry. 

## Syntax
<a name="ST_NumGeometries-function-syntax"></a>

```
ST_NumGeometries(geom)
```

## Arguments
<a name="ST_NumGeometries-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_NumGeometries-function-return"></a>

`INTEGER` representing the number of geometries in *geom*. 

If *geom* is null, then null is returned. 

If *geom* is a single empty geometry, then `0` is returned. 

If *geom* is a single nonempty geometry, then `1` is returned. 

If *geom* is a `GEOMETRYCOLLECTION` or a `MULTI` subtype, then the number of geometries is returned. 

## Examples
<a name="ST_NumGeometries-function-examples"></a>

The following SQL returns the number of geometries in the input multilinestring. 

```
SELECT ST_NumGeometries(ST_GeomFromText('MULTILINESTRING((0 0,1 0,0 5),(3 4,13 26))'));
```

```
st_numgeometries
-------------
 2
```

# ST\$1NumInteriorRings
<a name="ST_NumInteriorRings-function"></a>

ST\$1NumInteriorRings returns the number of rings in an input polygon geometry. 

## Syntax
<a name="ST_NumInteriorRings-function-syntax"></a>

```
ST_NumInteriorRings(geom)
```

## Arguments
<a name="ST_NumInteriorRings-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_NumInteriorRings-function-return"></a>

`INTEGER`

If *geom* is null, then null is returned. 

If *geom* is not a polygon, then null is returned. 

## Examples
<a name="ST_NumInteriorRings-function-examples"></a>

The following SQL returns the number of interior rings in the input polygon. 

```
SELECT ST_NumInteriorRings(ST_GeomFromText('POLYGON((0 0,100 0,100 100,0 100,0 0),(1 1,1 5,5 1,1 1),(7 7,7 8,8 7,7 7))'));
```

```
 st_numinteriorrings
-------------
 2
```

# ST\$1NumPoints
<a name="ST_NumPoints-function"></a>

ST\$1NumPoints returns the number of points in an input geometry. 

## Syntax
<a name="ST_NumPoints-function-syntax"></a>

```
ST_NumPoints(geom)
```

## Arguments
<a name="ST_NumPoints-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="ST_NumPoints-function-return"></a>

`INTEGER`

If *geom* is null, then null is returned. 

If *geom* is not of subtype `LINESTRING`, then null is returned. 

## Examples
<a name="ST_NumPoints-function-examples"></a>

The following SQL returns the number of points in the input linestring. 

```
SELECT ST_NumPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_numpoints
-------------
4
```

The following SQL returns null because the input *geom* is not of subtype `LINESTRING`. 

```
SELECT ST_NumPoints(ST_GeomFromText('MULTIPOINT(1 2,3 4)'));
```

```
st_numpoints
-------------
```

# ST\$1Perimeter
<a name="ST_Perimeter-function"></a>

For an input areal geometry, ST\$1Perimeter returns the Cartesian perimeter (length of the boundary) of the 2D projection. The perimeter units are the same as the units in which the coordinates of the input geometry are expressed. The function returns zero (0) for points, multipoints, and linear geometries. When the input is a geometry collection, the function returns the sum of the perimeters of the geometries in the collection. 

For an input geography, ST\$1Perimeter returns the geodesic perimeter (length of the boundary) of the 2D projection of an input areal geography computed on the spheroid determined by the SRID. The unit of perimeter is in meters. The function returns zero (0) for points, multipoints, and linear geographies. When the input is a geometry collection, the function returns the sum of the perimeters of the geographies in the collection.

## Syntax
<a name="ST_Perimeter-function-syntax"></a>

```
ST_Perimeter(geo)
```

## Arguments
<a name="ST_Perimeter-function-arguments"></a>

 *geo*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type.

## Return type
<a name="ST_Perimeter-function-return"></a>

`DOUBLE PRECISION`

If *geo* is null, then null is returned.

If the SRID value is not found, then an error is returned.

## Examples
<a name="ST_Perimeter-function-examples"></a>

The following SQL returns the Cartesian perimeter of a multipolygon. 

```
SELECT ST_Perimeter(ST_GeomFromText('MULTIPOLYGON(((0 0,10 0,0 10,0 0)),((10 0,20 0,20 10,10 0)))'));
```

```
 st_perimeter
--------------------------------
    68.2842712474619
```

The following SQL returns the Cartesian perimeter of a multipolygon. 

```
SELECT ST_Perimeter(ST_GeomFromText('MULTIPOLYGON(((0 0,10 0,0 10,0 0)),((10 0,20 0,20 10,10 0)))'));
```

```
 st_perimeter
--------------------------------
    68.2842712474619
```

The following SQL returns the perimeter of a polygon in a geography. 

```
SELECT ST_Perimeter(ST_GeogFromText('SRID=4326;POLYGON((0 0,1 0,0 1,0 0))'));
```

```
 st_perimeter 
------------------
 378790.428393693
```

The following SQL returns the perimeter of a linestring in a geography. 

```
SELECT ST_Perimeter(ST_GeogFromText('SRID=4326;LINESTRING(5 0,10 0)'));
```

```
 st_perimeter 
--------------
 0
```

# ST\$1Perimeter2D
<a name="ST_Perimeter2D-function"></a>

ST\$1Perimeter2D is an alias for ST\$1Perimeter. For more information, see [ST\$1Perimeter](ST_Perimeter-function.md). 

# ST\$1Point
<a name="ST_Point-function"></a>

ST\$1Point returns a point geometry from the input coordinate values. 

## Syntax
<a name="ST_Point-function-syntax"></a>

```
ST_Point(x, y)
```

## Arguments
<a name="ST_Point-function-arguments"></a>

 *x*   
A value of data type `DOUBLE PRECISION` that represents a first coordinate. 

 *y*   
A value of data type `DOUBLE PRECISION` that represents a second coordinate. 

## Return type
<a name="ST_Point-function-return"></a>

`GEOMETRY` of subtype `POINT`. 

The spatial reference system identifier (SRID) value of the returned geometry is set to 0. 

If *x* or *y* is null, then null is returned. 

## Examples
<a name="ST_Point-function-examples"></a>

The following SQL constructs a point geometry from the input coordinates. 

```
SELECT ST_AsText(ST_Point(5.0, 7.0));
```

```
st_astext
-------------
POINT(5 7)
```

# ST\$1PointN
<a name="ST_PointN-function"></a>

ST\$1PointN returns a point in a linestring as specified by an index value. Negative index values are counted backward from the end of the linestring, so that -1 is the last point. 

The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_PointN-function-syntax"></a>

```
ST_PointN(geom, index)
```

## Arguments
<a name="ST_PointN-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

 *index*   
A value of data type `INTEGER` that represents the index of a point in a linestring. 

## Return type
<a name="ST_PointN-function-return"></a>

`GEOMETRY` of subtype `POINT`. 

The spatial reference system identifier (SRID) value of the returned geometry is set to 0. 

If *geom* or *index* is null, then null is returned. 

If *index* is out of range, then null is returned. 

If *geom* is empty, then null is returned. 

If *geom* is not a `LINESTRING`, then null is returned. 

## Examples
<a name="ST_PointN-function-examples"></a>

The following SQL returns an extended well-known text (EWKT) representation of a six-point `LINESTRING` to a `GEOMETRY` object and returns the point at index 5 of the linestring. 

```
SELECT ST_AsEWKT(ST_PointN(ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5,0 0)',4326), 5));
```

```
st_asewkt
-------------
 SRID=4326;POINT(0 5)
```

# ST\$1Points
<a name="ST_Points-function"></a>

ST\$1Points returns a multipoint geometry containing all nonempty points in the input geometry. ST\$1Points doesn't remove points that are duplicated in the input, including the start and end points of ring geometries.

## Syntax
<a name="ST_Points-function-syntax"></a>

```
ST_Points(geom)
```

## Arguments
<a name="ST_Points-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Points-function-return"></a>

`GEOMETRY` of subtype `MULTIPOINT`. 

The spatial reference system identifier (SRID) value of the returned geometry is the same as *geom*. 

If *geom* is null, then null is returned. 

If *geom* is empty, then the empty multipoint is returned. 

## Examples
<a name="ST_Points-function-examples"></a>

The following SQL examples construct a multipoint geometry from the input geometry. The result is a multipoint geometry containing the nonempty points in the input geometry.

```
SELECT ST_AsEWKT(ST_Points(ST_SetSRID(ST_GeomFromText('LINESTRING(1 0,2 0,3 0)'), 4326)));
```

```
st_asewkt
-------------
SRID=4326;MULTIPOINT((1 0),(2 0),(3 0))
```

```
SELECT ST_AsEWKT(ST_Points(ST_SetSRID(ST_GeomFromText('MULTIPOLYGON(((0 0,1 0,0 1,0 0)))'), 4326)));
```

```
st_asewkt
-------------
SRID=4326;MULTIPOINT((0 0),(1 0),(0 1),(0 0))
```

# ST\$1Polygon
<a name="ST_Polygon-function"></a>

ST\$1Polygon returns a polygon geometry whose outer ring is the input linestring with the value that was input for the spatial reference system identifier (SRID). 

The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_Polygon-function-syntax"></a>

```
ST_Polygon(linestring, srid)
```

## Arguments
<a name="ST_Polygon-function-arguments"></a>

 *linestring*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING` that represents a linestring. The *linestring* value must be closed. 

 *srid*   
A value of data type `INTEGER` that represents a SRID. 

## Return type
<a name="ST_Polygon-function-return"></a>

`GEOMETRY` of subtype `POLYGON`.

The SRID value of the returned geometry is set to *srid*. 

If *linestring* or *srid* is null, then null is returned.

If *linestring* is not a linestring, then an error is returned.

If *linestring* is not closed, then an error is returned.

If *srid* is negative, then an error is returned.

## Examples
<a name="ST_Polygon-function-examples"></a>

The following SQL constructs a polygon with an SRID value. 

```
SELECT ST_AsEWKT(ST_Polygon(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'),4356));
```

```
st_asewkt
-------------
 SRID=4356;POLYGON((77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07))
```

# ST\$1RemovePoint
<a name="ST_RemovePoint-function"></a>

ST\$1RemovePoint returns a linestring geometry that has the point of the input geometry at an index position removed. 

The index is zero-based. The spatial reference system identifier (SRID) of the result is the same as the input geometry. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_RemovePoint-function-syntax"></a>

```
ST_RemovePoint(geom, index)
```

## Arguments
<a name="ST_RemovePoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

 *index*   
A value of data type `INTEGER` that represents the position of a zero-based index. 

## Return type
<a name="ST_RemovePoint-function-return"></a>

`GEOMETRY` 

If *geom* or *index* is null, then null is returned. 

If *geom* is not subtype `LINESTRING`, then an error is returned. 

If *index* is out of range, then an error is returned. Valid values for the index position are between 0 and `ST_NumPoints(geom)` minus 1. 

## Examples
<a name="ST_RemovePoint-function-examples"></a>

The following SQL removes the last point in a linestring. 

```
WITH tmp(g) AS (SELECT ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5)',4326))
SELECT ST_AsEWKT(ST_RemovePoint(g, ST_NumPoints(g) - 1)) FROM tmp;
```

```
   st_asewkt
-----------------------------------------
 SRID=4326;LINESTRING(0 0,10 0,10 10,5 5)
```

# ST\$1Reverse
<a name="ST_Reverse-function"></a>

ST\$1Reverse reverses the order of the vertices for linear and areal geometries. For point or multipoint geometries, a copy of the original geometry is returned. For geometry collections, ST\$1Reverse reverses the order of the vertices for each of the geometries in the collection.

The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_Reverse-function-syntax"></a>

```
ST_Reverse(geom)
```

## Arguments
<a name="ST_Reverse-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Reverse-function-return"></a>

`GEOMETRY` 

The spatial reference system identifier (SRID) of the returned geometry is the same as that of the input geometry. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_Reverse-function-examples"></a>

The following SQL reverses the order of the points in a linestring. 

```
SELECT ST_AsEWKT(ST_Reverse(ST_GeomFromText('LINESTRING(1 0,2 0,3 0,4 0)', 4326)));
```

```
    st_asewkt
------------------------------------
  SRID=4326;LINESTRING(4 0,3 0,2 0,1 0)
```

# ST\$1SetPoint
<a name="ST_SetPoint-function"></a>

ST\$1SetPoint returns a linestring with updated coordinates with respect to the input linestring's position as specified by the index. The new coordinates are the coordinates of the input point. 

The dimension of the returned geometry is the same as that of the *geom1* value. If *geom1* and *geom2* have different dimensions, *geom2* is projected to the dimension of *geom1*.

## Syntax
<a name="ST_SetPoint-function-syntax"></a>

```
ST_SetPoint(geom1, index, geom2)
```

## Arguments
<a name="ST_SetPoint-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

 *index*   
A value of data type `INTEGER` that represents the position of an index. A `0` refers to the first point of the linestring from the left, `1` refers to the second point, and so on. The index can be a negative value. A `-1` refers to the first point of the linestring from the right, `-2` refers to the second point of the linestring from the right, and so on. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `POINT`. 

## Return type
<a name="ST_SetPoint-function-return"></a>

`GEOMETRY`

If *geom2* is the empty point, then *geom1* is returned. 

If *geom1*, *geom2*, or *index* is null, then null is returned. 

If *geom1* is not a linestring, then an error is returned. 

If *index* is not within a valid index range, then an error is returned. 

If *geom2* is not a point, then an error is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

## Examples
<a name="ST_SetPoint-function-examples"></a>

The following SQL returns a new linestring where we set the second point of the input linestring with the specified point. 

```
SELECT ST_AsText(ST_SetPoint(ST_GeomFromText('LINESTRING(1 2, 3 2, 5 2, 1 2)'), 2, ST_GeomFromText('POINT(7 9)')));
```

```
st_astext              
-------------
 LINESTRING(1 2,3 2,7 9,1 2)
```

The following SQL example returns a new linestring where we set the third point from the right (the index is negative) of the linestring with the specified point. 

```
SELECT ST_AsText(ST_SetPoint(ST_GeomFromText('LINESTRING(1 2, 3 2, 5 2, 1 2)'), -3, ST_GeomFromText('POINT(7 9)')));
```

```
st_astext              
-------------
 LINESTRING(1 2,7 9,5 2,1 2)
```

# ST\$1SetSRID
<a name="ST_SetSRID-function"></a>

ST\$1SetSRID returns a geometry that is the same as input geometry, except updated with the value input for the spatial reference system identifier (SRID). 

## Syntax
<a name="ST_SetSRID-function-syntax"></a>

```
ST_SetSRID(geom, srid)
```

## Arguments
<a name="ST_SetSRID-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *srid*   
A value of data type `INTEGER` that represents a SRID. 

## Return type
<a name="ST_SetSRID-function-return"></a>

`GEOMETRY`

The SRID value of the returned geometry is set to *srid*. 

If *geom* or *srid* is null, then null is returned.

If *srid* is negative, then an error is returned.

## Examples
<a name="ST_SetSRID-function-examples"></a>

The following SQL sets the SRID value of a linestring.

```
SELECT ST_AsEWKT(ST_SetSRID(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'),50));
```

```
st_asewkt
-------------
 SRID=50;LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)
```

# ST\$1Simplify
<a name="ST_Simplify-function"></a>

ST\$1Simplify returns a simplified copy of the input geometry using the Ramer-Douglas-Peucker algorithm with the given tolerance. The topology of the input geometry might not be preserved. For more information about the algorithm, see [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm) in Wikipedia. 

When ST\$1Simplify calculates distances to simplify a geometry, ST\$1Simplify operates on the 2D projection of the input geometry. 

## Syntax
<a name="ST_Simplify-function-syntax"></a>

```
ST_Simplify(geom, tolerance)
```

## Arguments
<a name="ST_Simplify-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *tolerance*   
A value of data type `DOUBLE PRECISION` that represents the tolerance level of the Ramer-Douglas-Peucker algorithm. If *tolerance* is a negative number, then zero is used. 

## Return type
<a name="ST_Simplify-function-return"></a>

`GEOMETRY`. 

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometry. 

The dimension of the returned geometry is the same as that of the input geometry. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_Simplify-function-examples"></a>

The following SQL simplifies the input linestring using a Euclidean distance tolerance of 1 with the Ramer-Douglas-Peucker algorithm. The units of the distance are the same as those of the coordinates of the geometry.

```
SELECT ST_AsEWKT(ST_Simplify(ST_GeomFromText('LINESTRING(0 0,1 2,1 1,2 2,2 1)'), 1));
```

```
 st_asewkt
-----------
LINESTRING(0 0,1 2,2 1)
```

# ST\$1SRID
<a name="ST_SRID-function"></a>

ST\$1SRID returns the spatial reference system identifier (SRID) of an input geometry. For more information about an SRID, see [Querying spatial data in Amazon Redshift](geospatial-overview.md).

## Syntax
<a name="ST_SRID-function-syntax"></a>

```
ST_SRID(geom)
```

## Arguments
<a name="ST_SRID-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_SRID-function-return"></a>

`INTEGER` representing the SRID value of *geom*. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_SRID-function-examples"></a>

The following SQL returns an SRID value of a linestring that is set to SRID `4326`.

```
SELECT ST_SRID(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)',4326));
```

```
st_srid
-------------
 4326
```

The following SQL returns an SRID value of a linestring that is not set when constructed. This results in `0` for the SRID value.

```
SELECT ST_SRID(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_srid
-------------
 0
```

# ST\$1StartPoint
<a name="ST_StartPoint-function"></a>

ST\$1StartPoint returns the first point of an input linestring. The spatial reference system identifier (SRID) value of the result is the same as that of the input geometry. The dimension of the returned geometry is the same as that of the input geometry.

## Syntax
<a name="ST_StartPoint-function-syntax"></a>

```
ST_StartPoint(geom)
```

## Arguments
<a name="ST_StartPoint-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. The subtype must be `LINESTRING`. 

## Return type
<a name="ST_StartPoint-function-return"></a>

`GEOMETRY` 

If *geom* is null, then null is returned. 

If *geom* is empty, then null is returned. 

If *geom* isn't a `LINESTRING`, then null is returned. 

## Examples
<a name="ST_StartPoint-function-examples"></a>

The following SQL returns an extended well-known text (EWKT) representation of a four-point `LINESTRING` to a `GEOMETRY` object and returns the start point of the linestring. 

```
SELECT ST_AsEWKT(ST_StartPoint(ST_GeomFromText('LINESTRING(0 0,10 0,10 10,5 5,0 5)',4326)));
```

```
st_asewkt
-------------
 SRID=4326;POINT(0 0)
```

# ST\$1Touches
<a name="ST_Touches-function"></a>

ST\$1Touches returns true if the 2D projections of the two input geometries touch. The two geometries touch if they are nonempty, intersect, and have no interior points in common. 

## Syntax
<a name="ST_Touches-function-syntax"></a>

```
ST_Touches(geom1, geom2)
```

## Arguments
<a name="ST_Touches-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Touches-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Touches-function-examples"></a>

The following SQL checks if a polygon touches a linestring. 

```
SELECT ST_Touches(ST_GeomFromText('POLYGON((0 0,10 0,0 10,0 0))'), ST_GeomFromText('LINESTRING(20 10,20 0,10 0)'));
```

```
 st_touches              
-------------
 t
```

# ST\$1Transform
<a name="ST_Transform-function"></a>

ST\$1Transform returns a new geometry with coordinates that are transformed in a spatial reference system defined by the input spatial reference system identifier (SRID). 

## Syntax
<a name="ST_Transform-function-syntax"></a>

```
ST_Transform(geom, srid)
```

## Arguments
<a name="ST_Transform-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *srid*   
A value of data type `INTEGER` that represents an SRID. 

## Return type
<a name="ST_Transform-function-return"></a>

`GEOMETRY`.

The SRID value of the returned geometry is set to *srid*. 

If *geom* or *srid* is null, then null is returned.

If the SRID value associated with the input *geom* does not exist, then an error is returned.

If *srid* does not exist, then an error is returned.

## Examples
<a name="ST_Transform-function-examples"></a>

The following SQL transforms the SRID of an empty geometry collection. 

```
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('GEOMETRYCOLLECTION EMPTY', 3857), 4326));
```

```
             st_asewkt
------------------------------------
 SRID=4326;GEOMETRYCOLLECTION EMPTY
```

The following SQL transforms the SRID of a linestring. 

```
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('LINESTRING(110 40, 2 3, -10 80, -7 9, -22 -33)', 4326), 26918));
```

```
                                                                                            st_asewkt
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 SRID=26918;LINESTRING(73106.6977300955 15556182.9688576,14347201.5059964 1545178.32934967,1515090.41262989 9522193.25115316,10491250.83295 2575457.28410878,5672303.72135968 -5233682.61176205)
```

The following SQL transforms the SRID of a polygon. 

```
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('POLYGON Z ((-10 10 -7, -65 10 -6, -10 64 -5, -10 10 -7), (-11 11 5, -11 12 6, -12 11 7, -11 11 5))', 6989), 6317));
```

```
                                                                                                                                                                                                                      st_asewkt
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 SRID=6317;POLYGON Z ((6186430.2771091 -1090834.57212608 1100247.33216237,2654831.67853801 -5693304.90741276 1100247.50581055,2760987.41750022 -486836.575101877 5709710.44137268,6186430.2771091 -1090834.57212608 1100247.33216237),(6146675.25029258 -1194792.63532103 1209007.1115113,6125027.87562215 -1190584.81194058 1317403.77865723,6124888.99555252 -1301885.3455052 1209007.49312929,6146675.25029258 -1194792.63532103 1209007.1115113))
```

# ST\$1Union
<a name="ST_Union-function"></a>

ST\$1Union returns a geometry representing the union of two geometries. That is, it merges the input geometries to produce a resulting geometry with no overlaps. 

## Syntax
<a name="ST_Union-function-syntax"></a>

```
ST_Union(geom1, geom2)
```

## Arguments
<a name="ST_Union-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Union-function-return"></a>

`GEOMETRY`

The spatial reference system identifier (SRID) value of the returned geometry is the SRID value of the input geometries.

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* or *geom2* are empty, then an empty geometry is returned. 

If *geom1* and *geom2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geom1* or *geom2* is a geometry collection, linestring, or multilinestring, then an error is returned. 

If *geom1* or *geom2* is not a two-dimensional (2D) geometry, then an error is returned. 

## Examples
<a name="ST_Union-function-examples"></a>

The following SQL returns the non-empty geometry representing the union of two input geometries. 

```
SELECT ST_AsEWKT(ST_Union(ST_GeomFromText('POLYGON((0 0,100 100,0 200,0 0))'), ST_GeomFromText('POLYGON((0 0,10 0,0 10,0 0))')));
```

```
        st_asewkt        
-------------------------
 POLYGON((0 0,0 200,100 100,5 5,10 0,0 0))
```

# ST\$1Within
<a name="ST_Within-function"></a>

ST\$1Within returns true if the 2D projection of the first input geometry is within the 2D projection of the second input geometry. 

For example, geometry `A` is within geometry `B` if every point in `A` is a point in `B` and their interiors have nonempty intersection. 

ST\$1Within(`A`, `B`) is equivalent to ST\$1Contains(`B`, `A`). 

## Syntax
<a name="ST_Within-function-syntax"></a>

```
ST_Within(geom1, geom2)
```

## Arguments
<a name="ST_Within-function-arguments"></a>

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. This value is compared with *geom2* to determine if it is within *geom2*. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_Within-function-return"></a>

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *geom1* and *geom2* don't have the same spatial reference system identifier (SRID) value, then an error is returned. 

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Within-function-examples"></a>

The following SQL checks if the first polygon is within the second polygon. 

```
SELECT ST_Within(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 3,2 1,0 -3,-1 3))'));
```

```
st_within
-----------
 true
```

# ST\$1X
<a name="ST_X-function"></a>

ST\$1X returns the first coordinate of an input point. 

## Syntax
<a name="ST_X-function-syntax"></a>

```
ST_X(point)
```

## Arguments
<a name="ST_X-function-arguments"></a>

 *point*   
A `POINT` value of data type `GEOMETRY`. 

## Return type
<a name="ST_X-function-return"></a>

`DOUBLE PRECISION` value of the first coordinate.

If *point* is null, then null is returned. 

If *point* is the empty point, then null is returned. 

If *point* is not a `POINT`, then an error is returned. 

## Examples
<a name="ST_X-function-examples"></a>

The following SQL returns the first coordinate of a point. 

```
SELECT ST_X(ST_Point(1,2));
```

```
st_x
-----------
 1.0
```

# ST\$1XMax
<a name="ST_XMax-function"></a>

ST\$1XMax returns the maximum first coordinate of an input geometry. 

## Syntax
<a name="ST_XMax-function-syntax"></a>

```
ST_XMax(geom)
```

## Arguments
<a name="ST_XMax-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_XMax-function-return"></a>

`DOUBLE PRECISION` value of the maximum first coordinate. 

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_XMax-function-examples"></a>

The following SQL returns the largest first coordinate of a linestring. 

```
SELECT ST_XMax(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_xmax
-----------
 77.42
```

# ST\$1XMin
<a name="ST_XMin-function"></a>

ST\$1XMin returns the minimum first coordinate of an input geometry. 

## Syntax
<a name="ST_XMin-function-syntax"></a>

```
ST_XMin(geom)
```

## Arguments
<a name="ST_XMin-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_XMin-function-return"></a>

`DOUBLE PRECISION` value of the minimum first coordinate. 

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_XMin-function-examples"></a>

The following SQL returns the smallest first coordinate of a linestring. 

```
SELECT ST_XMin(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_xmin
-----------
 77.27
```

# ST\$1Y
<a name="ST_Y-function"></a>

ST\$1Y returns the second coordinate of an input point. 

## Syntax
<a name="ST_Y-function-syntax"></a>

```
ST_Y(point)
```

## Arguments
<a name="ST_Y-function-arguments"></a>

 *point*   
A `POINT` value of data type `GEOMETRY`. 

## Return type
<a name="ST_Y-function-return"></a>

`DOUBLE PRECISION` value of the second coordinate.

If *point* is null, then null is returned. 

If *point* is the empty point, then null is returned. 

If *point* is not a `POINT`, then an error is returned. 

## Examples
<a name="ST_Y-function-examples"></a>

The following SQL returns the second coordinate of a point. 

```
SELECT ST_Y(ST_Point(1,2));
```

```
st_y
-----------
 2.0
```

# ST\$1YMax
<a name="ST_YMax-function"></a>

ST\$1YMax returns the maximum second coordinate of an input geometry. 

## Syntax
<a name="ST_YMax-function-syntax"></a>

```
ST_YMax(geom)
```

## Arguments
<a name="ST_YMax-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_YMax-function-return"></a>

`DOUBLE PRECISION` value of the maximum second coordinate.

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_YMax-function-examples"></a>

The following SQL returns the largest second coordinate of a linestring. 

```
SELECT ST_YMax(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_ymax
-----------
 29.31
```

# ST\$1YMin
<a name="ST_YMin-function"></a>

ST\$1YMin returns the minimum second coordinate of an input geometry. 

## Syntax
<a name="ST_YMin-function-syntax"></a>

```
ST_YMin(geom)
```

## Arguments
<a name="ST_YMin-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_YMin-function-return"></a>

`DOUBLE PRECISION` value of the minimum second coordinate. 

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

## Examples
<a name="ST_YMin-function-examples"></a>

The following SQL returns the smallest second coordinate of a linestring. 

```
SELECT ST_YMin(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
```

```
st_ymin
-----------
 29.07
```

# ST\$1Z
<a name="ST_Z-function"></a>

ST\$1Z returns the `z` coordinate of an input point. 

## Syntax
<a name="ST_Z-function-syntax"></a>

```
ST_Z(point)
```

## Arguments
<a name="ST_Z-function-arguments"></a>

 *point*   
A `POINT` value of data type `GEOMETRY`. 

## Return type
<a name="ST_Z-function-return"></a>

`DOUBLE PRECISION` value of the `m` coordinate.

If *point* is null, then null is returned. 

If *point* is a 2D or 3DM point, then null is returned. 

If *point* is the empty point, then null is returned. 

If *point* is not a `POINT`, then an error is returned. 

## Examples
<a name="ST_Z-function-examples"></a>

The following SQL returns the `z` coordinate of a point in a 3DZ geometry. 

```
SELECT ST_Z(ST_GeomFromEWKT('POINT Z (1 2 3)'));
```

```
st_z
-----------
 3
```

The following SQL returns the `z` coordinate of a point in a 4D geometry. 

```
SELECT ST_Z(ST_GeomFromEWKT('POINT ZM (1 2 3 4)'));
```

```
st_z
-----------
 3
```

# ST\$1ZMax
<a name="ST_ZMax-function"></a>

ST\$1ZMax returns the maximum `z` coordinate of an input geometry. 

## Syntax
<a name="ST_ZMax-function-syntax"></a>

```
ST_ZMax(geom)
```

## Arguments
<a name="ST_ZMax-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_ZMax-function-return"></a>

`DOUBLE PRECISION` value of the maximum `z` coordinate.

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

If *geom* is a 2D or 3DM geometry, then null is returned. 

## Examples
<a name="ST_ZMax-function-examples"></a>

The following SQL returns the largest `z` coordinate of a linestring in a 3DZ geometry. 

```
SELECT ST_ZMax(ST_GeomFromEWKT('LINESTRING Z (0 1 2, 3 4 5, 6 7 8)'));
```

```
st_zmax
-----------
  8
```

The following SQL returns the largest `z` coordinate of a linestring in a 4D geometry. 

```
SELECT ST_ZMax(ST_GeomFromEWKT('LINESTRING ZM (0 1 2 3, 4 5 6 7, 8 9 10 11)'));
```

```
st_zmax
-----------
  10
```

# ST\$1ZMin
<a name="ST_ZMin-function"></a>

ST\$1ZMin returns the minimum `z` coordinate of an input geometry. 

## Syntax
<a name="ST_ZMin-function-syntax"></a>

```
ST_ZMin(geom)
```

## Arguments
<a name="ST_ZMin-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

## Return type
<a name="ST_ZMin-function-return"></a>

`DOUBLE PRECISION` value of the minimum `z` coordinate. 

If *geom* is empty, then null is returned. 

If *geom* is null, then null is returned. 

If *geom* is a 2D or 3DM geometry, then null is returned. 

## Examples
<a name="ST_ZMin-function-examples"></a>

The following SQL returns the smallest `z` coordinate of a linestring in a 3DZ geometry. 

```
SELECT ST_ZMin(ST_GeomFromEWKT('LINESTRING Z (0 1 2, 3 4 5, 6 7 8)'));
```

```
st_zmin
-----------
  2
```

The following SQL returns the smallest `z` coordinate of a linestring in a 4D geometry. 

```
SELECT ST_ZMin(ST_GeomFromEWKT('LINESTRING ZM (0 1 2 3, 4 5 6 7, 8 9 10 11)'));
```

```
st_zmin
-----------
  2
```

# SupportsBBox
<a name="SupportsBBox-function"></a>

SupportsBBox returns true if the input geometry supports encoding with a precomputed bounding box. For more information about support for bounding boxes, see [Bounding box](spatial-terminology.md#spatial-terminology-bounding-box).

## Syntax
<a name="SupportsBBox-function-syntax"></a>

```
SupportsBBox(geom)
```

## Arguments
<a name="SupportsBBox-function-arguments"></a>

 *geom*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type.

## Return type
<a name="SupportsBBox-function-return"></a>

`BOOLEAN`

If *geom* is null, then null is returned.

## Examples
<a name="SupportsBBox-function-examples"></a>

The following SQL returns true because the input point geometry supports being encoded with a bounding box. 

```
SELECT SupportsBBox(AddBBox(ST_GeomFromText('POLYGON((0 0,1 0,0 1,0 0))')));
```

```
supportsbbox
--------------
t
```

The following SQL returns false because the input point geometry doesn't support being encoded with a bounding box. 

```
SELECT SupportsBBox(DropBBox(ST_GeomFromText('POLYGON((0 0,1 0,0 1,0 0))')));
```

```
supportsbbox
--------------
f
```