Geo Functions

This functionality is in beta and is subject to change. The design and code is less mature than official GA features and is being provided as-is with no warranties. Beta features are not subject to the support SLA of official GA features.

The geo functions work with geometries stored in geo_point, geo_shape and shape fields, or returned by other geo functions.

Limitations

geo_point, geo_shape and shape and types are represented in SQL as geometry and can be used interchangeably with the following exceptions:

  • geo_shape and shape fields don’t have doc values, therefore these fields cannot be used for filtering, grouping or sorting.
  • geo_points fields are indexed and have doc values by default, however only latitude and longitude are stored and indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and 8.381903171539307E-8 for longitude). The altitude component is accepted but not stored in doc values nor indexed. Therefore calling ST_Z function in the filtering, grouping or sorting will return null.

Geometry Conversion

ST_AsWKT

Synopsis:

  1. ST_AsWKT(
  2. geometry
  3. )

Input:

geometry

Output: string

Description: Returns the WKT representation of the geometry.

  1. SELECT city, ST_AsWKT(location) location FROM "geo" WHERE city = 'Amsterdam';
  2. city:s | location:s
  3. Amsterdam |POINT (4.850311987102032 52.347556999884546)

ST_WKTToSQL

Synopsis:

  1. ST_WKTToSQL(
  2. string
  3. )

Input:

string WKT representation of geometry

Output: geometry

Description: Returns the geometry from WKT representation.

  1. SELECT CAST(ST_WKTToSQL('POINT (10 20)') AS STRING) location;
  2. location:s
  3. POINT (10.0 20.0)

Geometry Properties

ST_GeometryType

Synopsis:

  1. ST_GeometryType(
  2. geometry
  3. )

Input:

geometry

Output: string

Description: Returns the type of the geometry such as POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION, ENVELOPE or CIRCLE.

  1. SELECT ST_GeometryType(ST_WKTToSQL('POINT (10 20)')) type;
  2. type:s
  3. POINT

ST_X

Synopsis:

  1. ST_X(
  2. geometry
  3. )

Input:

geometry

Output: double

Description: Returns the longitude of the first point in the geometry.

  1. SELECT ST_X(ST_WKTToSQL('POINT (10 20)')) x;
  2. x:d
  3. 10.0

ST_Y

Synopsis:

  1. ST_Y(
  2. geometry
  3. )

Input:

geometry

Output: double

Description: Returns the latitude of the first point in the geometry.

  1. SELECT ST_Y(ST_WKTToSQL('POINT (10 20)')) y;
  2. y:d
  3. 20.0

ST_Z

Synopsis:

  1. ST_Z(
  2. geometry
  3. )

Input:

geometry

Output: double

Description: Returns the altitude of the first point in the geometry.

  1. SELECT ST_Z(ST_WKTToSQL('POINT (10 20 30)')) z;
  2. z:d
  3. 30.0

ST_Distance

Synopsis:

  1. ST_Distance(
  2. geometry,
  3. geometry
  4. )

Input:

source geometry

target geometry

Output: Double

Description: Returns the distance between geometries in meters. Both geometries have to be points.

  1. SELECT ST_Distance(ST_WKTToSQL('POINT (10 20)'), ST_WKTToSQL('POINT (20 30)')) distance;
  2. distance:d
  3. 1499101.2889383635