title_wip

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/sql-reference/functions/geo/polygon.md)

## WKT[​](#wkt "Direct link to WKT")

Returns a WKT (Well Known Text) geometric object from various [Geo Data Types](/docs/sql-reference/data-types/geo). Supported WKT objects are:

- POINT
- POLYGON
- MULTIPOLYGON
- LINESTRING
- MULTILINESTRING

**Syntax**

```
WKT(geo_data)
```

**Parameters**

`geo_data` can be one of the following [Geo Data Types](/docs/sql-reference/data-types/geo) or their underlying primitive types:

- [Point](/docs/sql-reference/data-types/geo#point)
- [Ring](/docs/sql-reference/data-types/geo#ring)
- [Polygon](/docs/sql-reference/data-types/geo#polygon)
- [MultiPolygon](/docs/sql-reference/data-types/geo#multipolygon)
- [LineString](/docs/sql-reference/data-types/geo#linestring)
- [MultiLineString](/docs/sql-reference/data-types/geo#multilinestring)

**Returned value**

- WKT geometric object `POINT` is returned for a Point.
- WKT geometric object `POLYGON` is returned for a Polygon
- WKT geometric object `MULTIPOLYGON` is returned for a MultiPolygon.
- WKT geometric object `LINESTRING` is returned for a LineString.
- WKT geometric object `MULTILINESTRING` is returned for a MultiLineString.

**Examples**

POINT from tuple:

```
SELECT wkt((0., 0.));
```

```
POINT(0 0)
```

POLYGON from an array of tuples or an array of tuple arrays:

```
SELECT wkt([(0., 0.), (10., 0.), (10., 10.), (0., 10.)]);
```

```
POLYGON((0 0,10 0,10 10,0 10))
```

MULTIPOLYGON from an array of multi-dimensional tuple arrays:

```
SELECT wkt([[[(0., 0.), (10., 0.), (10., 10.), (0., 10.)], [(4., 4.), (5., 4.), (5., 5.), (4., 5.)]], [[(-10., -10.), (-10., -9.), (-9., 10.)]]]);
```

```
MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,5 4,5 5,4 5,4 4)),((-10 -10,-10 -9,-9 10,-10 -10)))
```

## readWKTMultiPolygon[​](#readwktmultipolygon "Direct link to readWKTMultiPolygon")

Converts a WKT (Well Known Text) MultiPolygon into a MultiPolygon type.

### Example[​](#example "Direct link to Example")

```
SELECT
    toTypeName(readWKTMultiPolygon('MULTIPOLYGON(((2 0,10 0,10 10,0 10,2 0),(4 4,5 4,5 5,4 5,4 4)),((-10 -10,-10 -9,-9 10,-10 -10)))')) AS type,
    readWKTMultiPolygon('MULTIPOLYGON(((2 0,10 0,10 10,0 10,2 0),(4 4,5 4,5 5,4 5,4 4)),((-10 -10,-10 -9,-9 10,-10 -10)))') AS output FORMAT Markdown
```

|  |  |  |  |
| --- | --- | --- | --- |
| type output|  |  | | --- | --- | | MultiPolygon [[[(2,0),(10,0),(10,10),(0,10),(2,0)],[(4,4),(5,4),(5,5),(4,5),(4,4)]],[[(-10,-10),(-10,-9),(-9,10),(-10,-10)]]] | | | |

### Input parameters[​](#input-parameters "Direct link to Input parameters")

String starting with `MULTIPOLYGON`

### Returned value[​](#returned-value "Direct link to Returned value")

MultiPolygon

## readWKTPolygon[​](#readwktpolygon "Direct link to readWKTPolygon")

Converts a WKT (Well Known Text) MultiPolygon into a Polygon type.

### Example[​](#example-1 "Direct link to Example")

```
SELECT
    toTypeName(readWKTPolygon('POLYGON((2 0,10 0,10 10,0 10,2 0))')) AS type,
    readWKTPolygon('POLYGON((2 0,10 0,10 10,0 10,2 0))') AS output
FORMAT Markdown
```

|  |  |  |  |
| --- | --- | --- | --- |
| type output|  |  | | --- | --- | | Polygon [[(2,0),(10,0),(10,10),(0,10),(2,0)]] | | | |

### Input parameters[​](#input-parameters-1 "Direct link to Input parameters")

String starting with `POLYGON`

### Returned value[​](#returned-value-1 "Direct link to Returned value")

Polygon

## readWKTPoint[​](#readwktpoint "Direct link to readWKTPoint")

The `readWKTPoint` function in ClickHouse parses a Well-Known Text (WKT) representation of a Point geometry and returns a point in the internal ClickHouse format.

### Syntax[​](#syntax "Direct link to Syntax")

```
readWKTPoint(wkt_string)
```

### Arguments[​](#arguments "Direct link to Arguments")

- `wkt_string`: The input WKT string representing a Point geometry.

### Returned value[​](#returned-value-2 "Direct link to Returned value")

The function returns a ClickHouse internal representation of the Point geometry.

### Example[​](#example-2 "Direct link to Example")

```
SELECT readWKTPoint('POINT (1.2 3.4)');
```

```
(1.2,3.4)
```

## readWKTLineString[​](#readwktlinestring "Direct link to readWKTLineString")

Parses a Well-Known Text (WKT) representation of a LineString geometry and returns it in the internal ClickHouse format.

### Syntax[​](#syntax-1 "Direct link to Syntax")

```
readWKTLineString(wkt_string)
```

### Arguments[​](#arguments-1 "Direct link to Arguments")

- `wkt_string`: The input WKT string representing a LineString geometry.

### Returned value[​](#returned-value-3 "Direct link to Returned value")

The function returns a ClickHouse internal representation of the linestring geometry.

### Example[​](#example-3 "Direct link to Example")

```
SELECT readWKTLineString('LINESTRING (1 1, 2 2, 3 3, 1 1)');
```

```
[(1,1),(2,2),(3,3),(1,1)]
```

## readWKTMultiLineString[​](#readwktmultilinestring "Direct link to readWKTMultiLineString")

Parses a Well-Known Text (WKT) representation of a MultiLineString geometry and returns it in the internal ClickHouse format.

### Syntax[​](#syntax-2 "Direct link to Syntax")

```
readWKTMultiLineString(wkt_string)
```

### Arguments[​](#arguments-2 "Direct link to Arguments")

- `wkt_string`: The input WKT string representing a MultiLineString geometry.

### Returned value[​](#returned-value-4 "Direct link to Returned value")

The function returns a ClickHouse internal representation of the multilinestring geometry.

### Example[​](#example-4 "Direct link to Example")

```
SELECT readWKTMultiLineString('MULTILINESTRING ((1 1, 2 2, 3 3), (4 4, 5 5, 6 6))');
```

```
[[(1,1),(2,2),(3,3)],[(4,4),(5,5),(6,6)]]
```

## readWKTRing[​](#readwktring "Direct link to readWKTRing")

Parses a Well-Known Text (WKT) representation of a Polygon geometry and returns a ring (closed linestring) in the internal ClickHouse format.

### Syntax[​](#syntax-3 "Direct link to Syntax")

```
readWKTRing(wkt_string)
```

### Arguments[​](#arguments-3 "Direct link to Arguments")

- `wkt_string`: The input WKT string representing a Polygon geometry.

### Returned value[​](#returned-value-5 "Direct link to Returned value")

The function returns a ClickHouse internal representation of the ring (closed linestring) geometry.

### Example[​](#example-5 "Direct link to Example")

```
SELECT readWKTRing('POLYGON ((1 1, 2 2, 3 3, 1 1))');
```

```
[(1,1),(2,2),(3,3),(1,1)]
```

## polygonsWithinSpherical[​](#polygonswithinspherical "Direct link to polygonsWithinSpherical")

Returns true or false depending on whether or not one polygon lies completely inside another polygon. Reference <https://www.boost.org/doc/libs/1_62_0/libs/geometry/doc/html/geometry/reference/algorithms/within/within_2.html>

### Example[​](#example-6 "Direct link to Example")

```
SELECT polygonsWithinSpherical([[[(4.3613577, 50.8651821), (4.349556, 50.8535879), (4.3602419, 50.8435626), (4.3830299, 50.8428851), (4.3904543, 50.8564867), (4.3613148, 50.8651279)]]], [[[(4.346693, 50.858306), (4.367945, 50.852455), (4.366227, 50.840809), (4.344961, 50.833264), (4.338074, 50.848677), (4.346693, 50.858306)]]]);
```

```
0
```

## readWKBMultiPolygon[​](#readwkbmultipolygon "Direct link to readWKBMultiPolygon")

Converts a WKB (Well Known Binary) MultiPolygon into a MultiPolygon type.

### Example[​](#example-7 "Direct link to Example")