Geospatial functions

At the core of Geospatial Analytics are the scalar functions and table functions provided as part of Db2® for i.

The implementation of these geospatial functions follows the OGC Simple Features for SQL specification and parts of the ISO SQL/MM Part 3: Spatial standard.

The geospatial functions fall into the following categories:
  • Construction of geometries from data exchange formats or coordinate data
  • Conversion of a geometry into a data exchange format
  • Comparison of geometries and discovery of relations between geometries
  • Construction of new geometries from existing geometries
  • Information about geometries
  • Creation of geohashes

Construction of geometries from data exchange formats or coordinate data

The following scalar functions create a geometry of the ST_GEOMETRY type or one of its subtypes from coordinate data, or from a well-known text (WKT), or a well-known binary (WKB) data exchange format:

Table 1. Geospatial scalar functions that construct geometries from data exchange formats or coordinate data
Function Use Function Name
Construct any geometry from a WKT, WKB ST_GEOMETRY scalar function
Construct any geometry from a WKT object ST_WKTTOSQL scalar function
Construct any geometry from a WKB object ST_WKBTOSQL scalar function
Construct a specific geometry from a WKT or WKB

ST_GEOMCOLLECTION scalar function

ST_LINESTRING scalar function

ST_MULTILINESTRING scalar function

ST_MULTIPOINT scalar function

ST_MULTIPOLYGON scalar function

ST_POINT scalar function

ST_POLYGON scalar function

Construct a specific geometry from coordinates ST_POINT scalar function

Conversion of a geometry to a different geometry type

The following scalar functions convert one geometry type to a different geometry type:

Table 2. Geospatial scalar functions that convert one geometry type to a different geometry type
Function Use Function Name
Convert a geometry into a linestring geometry ST_TOLINESTRING scalar function
Convert a geometry into a multiline geometry ST_TOMULTILINE scalar function
Convert a geometry into a multipoint geometry ST_TOMULTIPOINT scalar function
Convert a geometry into a multipolygon geometry ST_TOMULTIPOLYGON scalar function
Convert a geometry into a point geometry ST_TOPOINT scalar function
Convert a geometry into a polygon geometry ST_TOPOLYGON scalar function

Conversion of a geometry into a data exchange format

The following scalar functions convert a geometry of the ST_GEOMETRY type or one of its subtypes into a data exchange format:

Table 3. Geospatial scalar functions that convert a geometry of the ST_GEOMETRY type or one of its subtypes into a data exchange format
Function Use Function Name
Convert a geometry into a WKT object ST_ASTEXT scalar function
Convert a geometry into a WKB object ST_ASBINARY scalar function

Comparison of geometries and discovery of relations between geometries

These geospatial scalar functions return information that is the result of a comparison between geometries. They return information about ways in which geographic features relate to one another or compare with one another.

Table 4. Geospatial scalar functions that compare geometries and find relations between geometries
Function Use Function Name
Check whether two items geometries are identical ST_EQUALS scalar function
Determine the distance between geometries ST_DISTANCE scalar function
Determine whether geometries intersect

ST_CROSSES scalar function

ST_DISJOINT scalar function

ST_INTERSECTS scalar function

ST_OVERLAPS scalar function

ST_TOUCHES scalar function

Determine whether a geometry contains another one

ST_CONTAINS scalar function

ST_COVERS scalar function

ST_WITHIN scalar function

Construction of new geometries from existing geometries

The following scalar functions modify properties of a geometry of type ST_GEOMETRY or one of its subtypes to construct a new geometry:

Table 5. Geospatial scalar functions that construct new geometries from existing geometries
Function Use Function Name
Create new geometries with different space configurations

ST_BUFFER scalar function

ST_DIFFERENCE scalar function

ST_INTERSECTION scalar function

ST_SYMDIFFERENCE scalar function

Create a new geometry by combining multiple geometries ST_UNION scalar function

Information about geometries

The following scalar functions return information about geometric properties such as coordinates, measures, and boundaries:

Table 6. Geospatial scalar functions that return information about properties of geometries
Function Use Function Name
Return information about geometry types ST_GEOMETRYTYPE scalar function
Return information to indicate whether a geometry is simple ST_ISSIMPLE scalar function
Return information about geometry dimensions ST_AREA scalar function
Return information about geometry definitions ST_NUMPOINTS scalar function
Return information about coordinates and measures

ST_ISVALID scalar function

ST_MAXX scalar function

ST_MAXY scalar function

ST_MINX scalar function

ST_MINY scalar function

Return information about spatial reference systems

ST_SRSID scalar function

ST_SRSNAME scalar function

Creation of geohashes

The following table functions create geohashes

Table 7. Geospatial table functions that create geohash data
Function Use Function Name
Create the geohash value for a specific point

ST_GEOHASHVALUE scalar function

ST_GEOHASH table function

Create the set of geohash cells that are needed to completely cover a particular geometry

ST_GEOHASHCOVER table function

ST_GEOHASHCOVEREXTEND table function

Create the set of geohash cells that are needed to create a boundary box around a particular geometry

ST_FUZZYGEOHASHCOVER table function

ST_FUZZYGEOHASHCOVEREXTEND table function