# Geo Polygon (/docs/reference/sql/functions/geo-polygon)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

MVTEncodeGeom [#mvtencodegeom]

Projects a geometry given in geographic coordinates (longitude/latitude) into the tile-local pixel space of the
slippy-map tile identified by `zoom`, `tile_x` and `tile_y`, snaps it to the integer pixel grid, optionally clips it
to the tile, and returns the tile-space geometry as a `Geometry`.

The projection is Web Mercator over the full `UInt32` coordinate range; the origin is the tile's top-left corner with the
y axis pointing downwards (the Mapbox Vector Tile convention). When `clip` is enabled (the default) the geometry is
clipped to the tile expanded by `buffer` pixels, and geometries that fall entirely outside become `NULL`. The result is
intended to be passed to the aggregate function `MVTEncode`. This function is the analogue of PostGIS `ST_AsMVTGeom`.

Supported input geometry types are `Point`, `MultiPoint`, `LineString`, `MultiLineString`, `Ring`, `Polygon`, `MultiPolygon` and the
`Geometry` variant.

**Syntax**

```sql
MVTEncodeGeom(geometry, zoom, tile_x, tile_y[, extent[, buffer[, clip]]])
```

**Arguments**

* `geometry` — Geometry in longitude/latitude degrees. [`Point`](/reference/data-types/geo#point) or [`MultiPoint`](/reference/data-types/geo#multipoint) or [`LineString`](/reference/data-types/geo#linestring) or [`MultiLineString`](/reference/data-types/geo#multilinestring) or [`Ring`](/reference/data-types/geo#ring) or [`Polygon`](/reference/data-types/geo#polygon) or [`MultiPolygon`](/reference/data-types/geo#multipolygon) or [`Geometry`](/reference/data-types/geo)
* `zoom` — Slippy-map zoom level, in the range `[0, 32]`. [`UInt8`](/reference/data-types/int-uint)
* `tile_x` — Tile column index, in the range `[0, 2^zoom - 1]`. [`UInt32`](/reference/data-types/int-uint)
* `tile_y` — Tile row index, in the range `[0, 2^zoom - 1]`. [`UInt32`](/reference/data-types/int-uint)
* `extent` — Optional tile extent in pixels per side. Defaults to `4096`. [`UInt32`](/reference/data-types/int-uint)
* `buffer` — Optional clip buffer in pixels. Defaults to `1`. [`UInt32`](/reference/data-types/int-uint)
* `clip` — Optional flag; when nonzero (default) the geometry is clipped to the tile plus buffer. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the tile-space geometry, or `NULL` if it is fully clipped out. [`Geometry`](/reference/data-types/geo)

**Examples**

**Project a point into a tile**

```sql title=Query
SELECT MVTEncodeGeom((13.37, 52.52)::Point, 10, 550, 335)
```

*Introduced in version 26.7.0.*

polygonAreaCartesian [#polygonareacartesian]

Calculates the area of a polygon.

**Syntax**

```sql
polygonAreaCartesian(polygon)
```

**Arguments**

* `polygon` — A polygon value [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the area of the polygon [`Float64`](/reference/data-types/float)

**Examples**

**Usage example**

```sql title=Query
SELECT polygonAreaCartesian([[[(0., 0.), (0., 5.), (5., 5.), (5., 0.)]]])
```

```text title=Response
25
```

*Introduced in version 21.4.0.*

polygonAreaSpherical [#polygonareaspherical]

Calculates the surface area of a polygon.

**Syntax**

```sql
polygonAreaSpherical(polygon)
```

**Arguments**

* `polygon` — A polygon value. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the surface area of the polygon [`Float64`](/reference/data-types/float)

**Examples**

**Spherical example**

```sql title=Query
SELECT round(polygonAreaSpherical([[[(4.346693, 50.858306), (4.367945, 50.852455), (4.366227, 50.840809), (4.344961, 50.833264), (4.338074, 50.848677), (4.346693, 50.858306)]]]), 14)
```

```text title=Response
9.387704e-8
```

*Introduced in version 21.4.0.*

polygonConvexHullCartesian [#polygonconvexhullcartesian]

Calculates a convex hull. [Reference](https://www.boost.org/doc/libs/1_61_0/libs/geometry/doc/html/geometry/reference/algorithms/convex_hull.html)

Coordinates are in Cartesian coordinate system.

**Syntax**

```sql
polygonConvexHullCartesian(multipolygon)
```

**Arguments**

* `multipolygon` — A MultiPolygon value. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Returned value**

Returns the convex hull as a Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Examples**

**Conve hull example**

```sql title=Query
SELECT wkt(polygonConvexHullCartesian([[[(0., 0.), (0., 5.), (5., 5.), (5., 0.), (2., 3.)]]]))
```

```text title=Response
POLYGON((0 0,0 5,5 5,5 0,0 0))
```

*Introduced in version 21.4.0.*

polygonPerimeterCartesian [#polygonperimetercartesian]

Calculates the perimeter of a polygon.

**Syntax**

```sql
polygonPerimeterCartesian(polygon)
```

**Arguments**

* `polygon` — A Polygon value. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the perimeter of the polygon. [`Float64`](/reference/data-types/float)

**Examples**

**Usage example**

```sql title=Query
SELECT polygonPerimeterCartesian([[[(0., 0.), (0., 5.), (5., 5.), (5., 0.)]]])
```

```text title=Response
15
```

*Introduced in version 21.4.0.*

polygonPerimeterSpherical [#polygonperimeterspherical]

Calculates the perimeter of the polygon.

**Syntax**

```sql
polygonPerimeterSpherical(polygon)
```

**Arguments**

* `polygon` — A value of type [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

The perimeter of the polygon on a sphere [`Float64`](/reference/data-types/float)

**Examples**

**spherical\_example**

```sql title=Query
SELECT round(polygonPerimeterSpherical([[[(4.346693, 50.858306), (4.367945, 50.852455), (4.366227, 50.840809), (4.344961, 50.833264), (4.338074, 50.848677), (4.346693, 50.858306)]]]), 6)
```

```text title=Response
0.045539
```

*Introduced in version 21.4.0.*

polygonsDistanceCartesian [#polygonsdistancecartesian]

Calculates distance between two polygons.

**Syntax**

```sql
polygonsDistanceCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — A Polygon value [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — A Polygon value [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the minimal distance between the two polygons [`Float64`](/reference/data-types/float)

**Examples**

**Distance example**

```sql title=Query
SELECT polygonsDistanceCartesian([[[(0, 0), (0, 0.1), (0.1, 0.1), (0.1, 0)]]], [[[(10., 10.), (10., 40.), (40., 40.), (40., 10.), (10., 10.)]]])
```

```text title=Response
14.000714267493642
```

*Introduced in version 21.4.0.*

polygonsDistanceSpherical [#polygonsdistancespherical]

Calculates the minimal distance between two points where one point belongs to the first polygon and the second to another polygon.
Spherical means that coordinates are interpreted as coordinates on a pure and ideal sphere, which is not true for the Earth.
Using this type of coordinate system speeds up execution, but of course is not precise.

**Syntax**

```sql
polygonsDistanceSpherical(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon value. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon value. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the minimal distance between the two polygons on a sphere [`Float64`](/reference/data-types/float)

**Examples**

**Spherical distance**

```sql title=Query
SELECT polygonsDistanceSpherical([[[(0, 0), (0, 0.1), (0.1, 0.1), (0.1, 0)]]], [[[(10., 10.), (10., 40.), (40., 40.), (40., 10.), (10., 10.)]]])
```

```text title=Response
0.24372872211133834
```

*Introduced in version 21.4.0.*

polygonsEqualsCartesian [#polygonsequalscartesian]

Returns true if two polygons are equal.

**Syntax**

```sql
polygonsEqualsCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns `1` if equal, otherwise `0`. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Equality check example**

```sql title=Query
SELECT polygonsEqualsCartesian([[[(1., 1.), (1., 4.), (4., 4.), (4., 1.)]]], [[[(1., 1.), (1., 4.), (4., 4.), (4., 1.), (1., 1.)]]])
```

```text title=Response
1
```

*Introduced in version 21.4.0.*

polygonsIntersectionCartesian [#polygonsintersectioncartesian]

Calculates the intersection of polygons.

**Syntax**

```sql
polygonsIntersectionCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the intersection of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Intersection example**

```sql title=Query
SELECT wkt(polygonsIntersectionCartesian([[[(0., 0.), (0., 3.), (1., 2.9), (2., 2.6), (2.6, 2.), (2.9, 1.), (3., 0.), (0., 0.)]]], [[[(1., 1.), (1., 4.), (4., 4.), (4., 1.), (1., 1.)]]]))
```

```text title=Response
MULTIPOLYGON(((1 2.9,2 2.6,2.6 2,2.9 1,1 1,1 2.9)))
```

*Introduced in version 21.4.0.*

polygonsIntersectionSpherical [#polygonsintersectionspherical]

Calculates the intersection (AND) between polygons, coordinates are spherical.

**Syntax**

```sql
polygonsIntersectionSpherical(polygon1, polygon2)
```

**Arguments**

* `polygon1` — First Polygon with spherical coordinates. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — Second Polygon with spherical coordinates. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the intersection of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Spherical intersection example**

```sql title=Query
SELECT wkt(arrayMap(a -> arrayMap(b -> arrayMap(c -> (round(c.1, 6), round(c.2, 6)), b), a), polygonsIntersectionSpherical([[[(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)]]]])))
```

```text title=Response
MULTIPOLYGON(((4.3666 50.8434,4.36024 50.8436,4.34956 50.8536,4.35268 50.8567,4.36794 50.8525,4.3666 50.8434)))
```

*Introduced in version 21.4.0.*

polygonsSymDifferenceCartesian [#polygonssymdifferencecartesian]

The same as [`polygonsSymDifferenceSpherical`](#polygonsSymDifferenceSpherical), but the coordinates are in the Cartesian coordinate system; which is more close to the model of the real Earth.

**Syntax**

```sql
polygonsSymDifferenceCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the symmetric difference of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Usage example**

```sql title=Query
SELECT wkt(polygonsSymDifferenceCartesian([[[(0, 0), (0, 3), (1, 2.9), (2, 2.6), (2.6, 2), (2.9, 1), (3, 0), (0, 0)]]], [[[(1., 1.), (1., 4.), (4., 4.), (4., 1.), (1., 1.)]]]))
```

```text title=Response
MULTIPOLYGON(((1 2.9,1 1,2.9 1,3 0,0 0,0 3,1 2.9)),((1 2.9,1 4,4 4,4 1,2.9 1,2.6 2,2 2.6,1 2.9)))
```

*Introduced in version 21.4.0.*

polygonsSymDifferenceSpherical [#polygonssymdifferencespherical]

Calculates the spatial set theoretic symmetric difference (XOR) between two polygons

**Syntax**

```sql
polygonsSymDifferenceSpherical(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the symmetric difference of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Usage example**

```sql title=Query
SELECT wkt(arraySort(polygonsSymDifferenceSpherical([[(50., 50.), (50., -50.), (-50., -50.), (-50., 50.), (50., 50.)], [(10., 10.), (10., 40.), (40., 40.), (40., 10.), (10., 10.)], [(-10., -10.), (-10., -40.), (-40., -40.), (-40., -10.), (-10., -10.)]], [[(-20., -20.), (-20., 20.), (20., 20.), (20., -20.), (-20., -20.)]])));
```

```text title=Response
MULTIPOLYGON(((-20 -10.3067,-10 -10,-10 -20.8791,-20 -20,-20 -10.3067)),((10 20.8791,20 20,20 10.3067,10 10,10 20.8791)),((50 50,50 -50,-50 -50,-50 50,50 50),(20 10.3067,40 10,40 40,10 40,10 20.8791,-20 20,-20 -10.3067,-40 -10,-40 -40,-10 -40,-10 -20.8791,20 -20,20 10.3067)))
```

*Introduced in version 21.4.0.*

polygonsUnionCartesian [#polygonsunioncartesian]

Calculates the union of polygons.

**Syntax**

```sql
polygonsUnionCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the union of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Usage example**

```sql title=Query
SELECT wkt(polygonsUnionCartesian([[[(0., 0.), (0., 3.), (1., 2.9), (2., 2.6), (2.6, 2.), (2.9, 1), (3., 0.), (0., 0.)]]], [[[(1., 1.), (1., 4.), (4., 4.), (4., 1.), (1., 1.)]]]))
```

```text title=Response
MULTIPOLYGON(((1 2.9,1 4,4 4,4 1,2.9 1,3 0,0 0,0 3,1 2.9)))
```

*Introduced in version 21.4.0.*

polygonsUnionSpherical [#polygonsunionspherical]

Calculates a union (OR) of polygons.

**Syntax**

```sql
polygonsUnionSpherical(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns the union of the polygons as a MultiPolygon. [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Usage example**

```sql title=Query
SELECT wkt(polygonsUnionSpherical([[[(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)]]]))
```

```text title=Response
MULTIPOLYGON(((4.36661 50.8434,4.36623 50.8408,4.34496 50.8333,4.33807 50.8487,4.34669 50.8583,4.35268 50.8567,4.36136 50.8652,4.36131 50.8651,4.39045 50.8565,4.38303 50.8429,4.36661 50.8434)))
```

*Introduced in version 21.4.0.*

polygonsWithinCartesian [#polygonswithincartesian]

Checks if a polygon is within another polygon.

**Syntax**

```sql
polygonsWithinCartesian(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns `1` if `polygon1` is contained in `polygon2`, otherwise `0`. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT polygonsWithinCartesian([[[(2., 2.), (2., 3.), (3., 3.), (3., 2.)]]], [[[(1., 1.), (1., 4.), (4., 4.), (4., 1.), (1., 1.)]]])
```

```text title=Response
1
```

*Introduced in version 21.4.0.*

polygonsWithinSpherical [#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)

**Syntax**

```sql
polygonsWithinSpherical(polygon1, polygon2)
```

**Arguments**

* `polygon1` — The first Polygon. [`Polygon`](/reference/data-types/geo#polygon)
* `polygon2` — The second Polygon. [`Polygon`](/reference/data-types/geo#polygon)

**Returned value**

Returns `1` if `polygon1` lies completely within `polygon2`, otherwise `0`. [`UInt8`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
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)]]]);
```

```text title=Response
0
```

*Introduced in version 21.4.0.*

readWKBLineString [#readwkblinestring]

Parses a Well-Known Binary (WKB) representation of a LineString geometry and returns it in the internal RawTree format.

**Syntax**

```sql
readWKBLineString(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a LineString geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns returns a RawTree internal representation of the linestring geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKBLineString(unhex('010200000004000000000000000000f03f000000000000f03f0000000000000040000000000000004000000000000008400000000000000840000000000000f03f000000000000f03f'));
```

```text title=Response
[(1,1),(2,2),(3,3),(1,1)]
```

*Introduced in version 25.6.0.*

readWKBMultiLineString [#readwkbmultilinestring]

Parses a Well-Known Binary (WKB) representation of a MultiLineString geometry and returns it in the internal RawTree format.

**Syntax**

```sql
readWKBMultiLineString(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a MultiLineString geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the multilinestring geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKBMultiLineString(unhex('010500000002000000010200000003000000000000000000f03f000000000000f03f0000000000000040000000000000004000000000000008400000000000000840010200000003000000000000000000104000000000000010400000000000001440000000000000144000000000000018400000000000001840'));
```

```text title=Response
[[(1,1),(2,2),(3,3)],[(4,4),(5,5),(6,6)]]
```

*Introduced in version 25.6.0.*

readWKBMultiPoint [#readwkbmultipoint]

Parses a Well-Known Binary (WKB) representation of a MultiPoint geometry and returns it in the internal ClickHouse format.

**Syntax**

```sql
readWKBMultiPoint(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a MultiPoint geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a ClickHouse internal representation of the multipoint geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKBMultiPoint(unhex('0104000000020000000101000000000000000000f03f000000000000f03f010100000000000000000000400000000000000040'));
```

```text title=Response
[(1,1),(2,2)]
```

*Introduced in version 26.7.0.*

readWKBMultiPolygon [#readwkbmultipolygon]

Parses a Well-Known Binary (WKB) representation of a MultiPolygon geometry and returns it in the internal RawTree format.

**Syntax**

```sql
readWKBMultiPolygon(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a MultiPolygon geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the MultiPolygon geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT
    toTypeName(readWKBMultiPolygon(unhex('0106000000020000000103000000020000000500000000000000000000400000000000000000000000000000244000000000000000000000000000002440000000000000244000000000000000000000000000002440000000000000004000000000000000000500000000000000000010400000000000001040000000000000144000000000000010400000000000001440000000000000144000000000000010400000000000001440000000000000104000000000000010400103000000010000000400000000000000000024c000000000000024c000000000000024c000000000000022c000000000000022c0000000000000244000000000000024c000000000000024c0'))) AS type,
    readWKBMultiPolygon(unhex('0106000000020000000103000000020000000500000000000000000000400000000000000000000000000000244000000000000000000000000000002440000000000000244000000000000000000000000000002440000000000000004000000000000000000500000000000000000010400000000000001040000000000000144000000000000010400000000000001440000000000000144000000000000010400000000000001440000000000000104000000000000010400103000000010000000400000000000000000024c000000000000024c000000000000024c000000000000022c000000000000022c0000000000000244000000000000024c000000000000024c0')) FORMAT Vertical;
```

```text title=Response
type:                     MultiPolygon
readWKBMulti~000024c0')): [[[(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)]]]
```

*Introduced in version 25.6.0.*

readWKBPoint [#readwkbpoint]

Parses a Well-Known Binary (WKB) representation of a Point geometry and returns it in the internal RawTree format.

**Syntax**

```sql
readWKBPoint(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a Point geometry. [`String`](/reference/data-types/string)

**Returned value**

The function returns a RawTree internal representation of the point geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT toTypeName(readWKBPoint(unhex('0101000000333333333333f33f3333333333330b40')));
```

```text title=Response
(1.2,3.4)
```

*Introduced in version 25.6.0.*

readWKBPolygon [#readwkbpolygon]

Parses a Well-Known Binary (WKB) representation of a Polygon geometry and returns it in the internal RawTree format.

**Syntax**

```sql
readWKBPolygon(wkb_string)
```

**Arguments**

* `wkb_string` — The input WKB string representing a Polygon geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the Polygon geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT
    toTypeName(readWKBPolygon(unhex('010300000001000000050000000000000000000040000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000400000000000000000'))) AS type,
    readWKBPolygon(unhex('010300000001000000050000000000000000000040000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000400000000000000000'));
```

```text title=Response
Polygon [[(2,0),(10,0),(10,10),(0,10),(2,0)]]
```

*Introduced in version 25.6.0.*

readWKTLineString [#readwktlinestring]

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

**Syntax**

```sql
readWKTLineString(wkt_string)
```

**Arguments**

* `wkt_string` — The input WKT string representing a LineString geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the linestring geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKTLineString('LINESTRING (1 1, 2 2, 3 3, 1 1)');
```

```text title=Response
┌─readWKTLineString('LINESTRING (1 1, 2 2, 3 3, 1 1)')─┐
│ [(1,1),(2,2),(3,3),(1,1)]                            │
└──────────────────────────────────────────────────────┘
```

**LineString example**

```sql title=Query
SELECT toTypeName(readWKTLineString('LINESTRING (1 1, 2 2, 3 3, 1 1)'));
```

```text title=Response
┌─toTypeName(readWKTLineString('LINESTRING (1 1, 2 2, 3 3, 1 1)'))─┐
│ LineString                                                       │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.4.0.*

readWKTMultiLineString [#readwktmultilinestring]

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

**Syntax**

```sql
readWKTMultiLineString(wkt_string)
```

**Arguments**

* `wkt_string` — The input WKT string representing a MultiLineString geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns the function returns a RawTree internal representation of the multilinestring geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKTMultiLineString('MULTILINESTRING ((1 1, 2 2, 3 3), (4 4, 5 5, 6 6))');
```

```text title=Response
┌─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)]]                                    │
└──────────────────────────────────────────────────────────────────────────────┘
```

**MultiLineString example**

```sql title=Query
SELECT toTypeName(readWKTMultiLineString('MULTILINESTRING ((1 1, 2 2, 3 3, 1 1))'));
```

```text title=Response
┌─toTypeName(readWKTMultiLineString('MULTILINESTRING ((1 1, 2 2, 3 3, 1 1))'))─┐
│ MultiLineString                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.4.0.*

readWKTMultiPoint [#readwktmultipoint]

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

**Syntax**

```sql
readWKTMultiPoint(wkt_string)
```

**Arguments**

* `wkt_string` — The input WKT string representing a MultiPoint geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a ClickHouse internal representation of the multipoint geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKTMultiPoint('MULTIPOINT (1 1, 2 2, 3 3)');
```

```text title=Response
┌─readWKTMultiPoint('MULTIPOINT (1 1, 2 2, 3 3)')─┐
│ [(1,1),(2,2),(3,3)]                             │
└─────────────────────────────────────────────────┘
```

**MultiPoint example**

```sql title=Query
SELECT toTypeName(readWKTMultiPoint('MULTIPOINT (1 1, 2 2)'));
```

```text title=Response
┌─toTypeName(readWKTMultiPoint('MULTIPOINT (1 1, 2 2)'))─┐
│ MultiPoint                                             │
└────────────────────────────────────────────────────────┘
```

*Introduced in version 26.7.0.*

readWKTMultiPolygon [#readwktmultipolygon]

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

**Syntax**

```sql
readWKTMultiPolygon(wkt_string)
```

**Arguments**

* `wkt_string` — String starting with `MULTIPOLYGON` [`String`](/reference/data-types/string)

**Returned value**

Returns a MultiPolygon [`MultiPolygon`](/reference/data-types/geo#multipolygon)

**Examples**

**Usage example**

```sql title=Query
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
```

```text title=Response
[[[(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)]]]
```

*Introduced in version 21.4.0.*

readWKTPoint [#readwktpoint]

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

**Syntax**

```sql
readWKTPoint(wkt_string)
```

**Arguments**

* `wkt_string` — The input WKT string representing a Point geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the Point geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKTPoint('POINT (1.2 3.4)');
```

```text title=Response
(1.2,3.4)
```

*Introduced in version 21.4.0.*

readWKTPolygon [#readwktpolygon]

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

**Syntax**

```sql
readWKTPolygon(wkt_string)
```

**Arguments**

* `wkt_string` — String starting with `POLYGON` [`String`](/reference/data-types/string)

**Returned value**

Returns a Polygon [`Polygon`](/reference/data-types/geo#polygon)

**Examples**

**Usage example**

```sql title=Query
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
```

```text title=Response
[[(2,0),(10,0),(10,10),(0,10),(2,0)]]
```

*Introduced in version 21.4.0.*

readWKTRing [#readwktring]

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

**Syntax**

```sql
readWKTRing(wkt_string)
```

**Arguments**

* `wkt_string` — The input WKT string representing a Polygon geometry. [`String`](/reference/data-types/string)

**Returned value**

Returns a RawTree internal representation of the ring (closed linestring) geometry. [`Geo`](/reference/data-types/geo)

**Examples**

**Usage example**

```sql title=Query
SELECT readWKTRing('POLYGON ((1 1, 2 2, 3 3, 1 1))');
```

```text title=Response
[(1,1),(2,2),(3,3),(1,1)]
```

*Introduced in version 21.4.0.*
