Skip to main content
Skip to main content

Functions for Working with Polygons

WKT​

Returns a WKT (Well Known Text) geometric object from various Geo Data Types. Supported WKT objects are:

  • POINT
  • POLYGON
  • MULTIPOLYGON
  • LINESTRING
  • MULTILINESTRING

Syntax

Parameters

geo_data can be one of the following Geo Data Types or their underlying primitive types:

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:

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

MULTIPOLYGON from an array of multi-dimensional tuple arrays:

readWKTMultiPolygon​

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

Example​

typeoutput
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​

String starting with MULTIPOLYGON

Returned value​

MultiPolygon

readWKTPolygon​

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

Example​

typeoutput
Polygon[[(2,0),(10,0),(10,10),(0,10),(2,0)]]

Input parameters​

String starting with POLYGON

Returned value​

Polygon

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​

Arguments​

  • wkt_string: The input WKT string representing a Point geometry.

Returned value​

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

Example​

readWKTLineString​

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

Syntax​

Arguments​

  • wkt_string: The input WKT string representing a LineString geometry.

Returned value​

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

Example​

readWKTMultiLineString​

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

Syntax​

Arguments​

  • wkt_string: The input WKT string representing a MultiLineString geometry.

Returned value​

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

Example​

readWKTRing​

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

Syntax​

Arguments​

  • wkt_string: The input WKT string representing a Polygon geometry.

Returned value​

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

Example​

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​

Input parameters​

Returned value​

UInt8, 0 for false, 1 for true

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.

Example​

Input parameters​

Two polygons

Returned value​

Float64

polygonsDistanceCartesian​

Calculates distance between two polygons

Example​

Input parameters​

Two polygons

Returned value​

Float64

polygonsEqualsCartesian​

Returns true if two polygons are equal

Example​

Input parameters​

Two polygons

Returned value​

UInt8, 0 for false, 1 for true

polygonsSymDifferenceSpherical​

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

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

polygonsSymDifferenceCartesian​

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

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

polygonsIntersectionSpherical​

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

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

polygonsWithinCartesian​

Returns true if the second polygon is within the first polygon.

Example​

Input parameters​

Two polygons

Returned value​

UInt8, 0 for false, 1 for true

polygonConvexHullCartesian​

Calculates a convex hull. Reference

Coordinates are in Cartesian coordinate system.

Example​

Input parameters​

MultiPolygon

Returned value​

Polygon

polygonAreaSpherical​

Calculates the surface area of a polygon.

Example​

Input parameters​

Polygon

Returned value​

Float

polygonsUnionSpherical​

Calculates a union (OR).

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

polygonPerimeterSpherical​

Calculates the perimeter of the polygon.

Example​

This is the polygon representing Zimbabwe:

Input parameters​

Returned value​

polygonsIntersectionCartesian​

Calculates the intersection of polygons.

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

polygonAreaCartesian​

Calculates the area of a polygon

Example​

Input parameters​

Polygon

Returned value​

Float64

polygonPerimeterCartesian​

Calculates the perimeter of a polygon.

Example​

Input parameters​

Polygon

Returned value​

Float64

polygonsUnionCartesian​

Calculates the union of polygons.

Example​

Input parameters​

Polygons

Returned value​

MultiPolygon

For more information on geometry systems, see this presentation about the Boost library, which is what ClickHouse uses.