Geo functions
These functions can be used when working with and analysing geospatial data.
| Function | Description |
|---|---|
geo::area() | Calculates the area of a geometry |
geo::bearing() | Calculates the bearing between two geolocation points |
geo::centroid() | Calculates the centroid of a geometry |
geo::distance() | Calculates the distance between two geolocation points |
geo::​hash::decode() | Decodes a geohash into a geometry point |
geo::​hash::encode() | Encodes a geometry point into a geohash |
geo::is_valid() | Determines if a geometry type is a geography type |
Point and geometry
A
pointis composed of two floats that represent the longitude (east/west) and latitude (north/south) of a location.A
geometryis a type of object defined in the GeoJSON spec, of which Polygon is the most common. They can be passed in to the geo functions as objects that contain a "type" (such as "Polygon") and "coordinates" (an array of points).
geo::area
The geo::area function calculates the area of a geometry in square metres.
The following example shows this function, and its output, when used in a RETURN statement for four approximate points found on a map for the US state of Wyoming which has an area of 253,340 km2 and a mostly rectangular shape. Note: the doubled square brackets are because the function takes an array of an array to allow for more complex types such as MultiPolygon.

If the argument is not a geometry type, then an error will be returned.
geo::bearing
The geo::bearing function calculates the bearing between two geolocation points. Bearing begins at 0 degrees to indicate north, increasing clockwise into positive values and decreasing counterclockwise into negative values that converge at 180 degrees.

The following example shows this function, and its output, when used in a RETURN statement:

geo::centroid
The geo::centroid function calculates the centroid between multiple geolocation points.
The following example shows this function, and its output, when used in a RETURN statement. Note: the doubled square brackets are because the function takes an array of an array to allow for more complex types such as MultiPolygon.
The return value is a mountainous region somewhere in Austria:

geo::distance
The geo::distance function calculates the haversine distance, in metres, between two geolocation points.
The following example shows this function, and its output, when used in a RETURN statement:

geo::hash::decode
The geo::hash::decode function converts a geohash into a geolocation point.
The following example shows this function, and its output, when used in a RETURN statement:
geo::hash::encode
The geo::hash::encode function converts a geolocation point into a geohash.
The function accepts a second argument, which determines the accuracy and granularity of the geohash.
The following example shows this function, and its output, when used in a RETURN statement:
The following example shows this function with two arguments, and its output, when used in a select statement:
geo::is_valid
The geo::is_valid function determines if a geometry type is a geography type.
Geography types are used to store geolocation data in a Geographic Coordinate System (GCS),
whereas geometry types can store geolocation data in any coordinate system, including GCS, mathematical planes, board game layouts, etc...
A geography type add the following constraint:
each Point coordinates are in the range of -180° to 180° for longitude and -90° to 90° for latitude.
The following examples show this function, and its output, when used in a RETURN statement: