DB2 Version 9.7 for Linux, UNIX, and Windows

Well-known text (WKT) representation

The OpenGIS Consortium "Simple Features for SQL" specification defines the well-known text representation to exchange geometry data in ASCII format. This representation is also referenced by the ISO "SQL/MM Part: 3 Spatial" standard. See "Spatial functions that convert geometries to and from data exchange formats" for information on functions which accept and produce WKT data.

The well-known text representation of a geometry is defined as follows:

Read syntax diagramSkip visual syntax diagram
>>-+-POINT-----------+--+-| point-tagged-text |-----------+----><
   +-LINESTRING------+  +-| linestring-tagged text |------+   
   +-POLYGON---------+  +-| polygon-tagged-text |---------+   
   +-MULTIPOINT------+  +-| multipoint-tagged-text |------+   
   +-MULTILINESTRING-+  +-| multilinestring-tagged-text |-+   
   '-MULTIPOLYGON----'  '-| multipolygon-tagged-text |----'   

point-tagged-text

|--+--+-EMPTY-----------------------+------+--------------------|
   |  '-(--| point-coordinates |--)-'      |   
   +-Z-+-EMPTY-------------------------+---+   
   |   '-(--| point-z-coordinates |--)-'   |   
   +-M-+-EMPTY-------------------------+---+   
   |   '-(--| point-m-coordinates |--)-'   |   
   '-ZM-+-EMPTY--------------------------+-'   
        '-(--| point-zm-coordinates |--)-'     

linestring-tagged-text

|--+--+-EMPTY-----------------------+------+--------------------|
   |  '-(--| linestring-points |--)-'      |   
   +-Z-+-EMPTY-------------------------+---+   
   |   '-(--| linestring-z-points |--)-'   |   
   +-M-+-EMPTY-------------------------+---+   
   |   '-(--| linestring-m-points |--)-'   |   
   '-ZM-+-EMPTY--------------------------+-'   
        '-(--| linestring-zm-points |--)-'     

polygon-tagged-text

|--+--+-EMPTY-------------------+------+------------------------|
   |  '-(--| polygon-rings |--)-'      |   
   +-Z-+-EMPTY---------------------+---+   
   |   '-(--| polygon-z-rings |--)-'   |   
   +-M-+-EMPTY---------------------+---+   
   |   '-(--| polygon-m-rings |--)-'   |   
   '-ZM-+-EMPTY----------------------+-'   
        '-(--| polygon-zm-rings |--)-'     

multipoint-tagged-text

|--+--+-EMPTY----------------------+------+---------------------|
   |  '-(--| multipoint-parts |--)-'      |   
   +-Z-+-EMPTY------------------------+---+   
   |   '-(--| multipoint-z-parts |--)-'   |   
   +-M-+-EMPTY------------------------+---+   
   |   '-(--| multipoint-m-parts |--)-'   |   
   '-ZM-+-EMPTY-------------------------+-'   
        '-(--| multipoint-zm-parts |--)-'     

multilinestring-tagged-text

|--+--+-EMPTY---------------------------+------+----------------|
   |  '-(--| multilinestring-parts |--)-'      |   
   +-Z-+-EMPTY-----------------------------+---+   
   |   '-(--| multilinestring-z-parts |--)-'   |   
   +-M-+-EMPTY-----------------------------+---+   
   |   '-(--| multilinestring-m-parts |--)-'   |   
   '-ZM-+-EMPTY------------------------------+-'   
        '-(--| multilinestring-zm-parts |--)-'     

multipolygon-tagged-text

|--+--+-EMPTY------------------------+------+-------------------|
   |  '-(--| multipolygon-parts |--)-'      |   
   +-Z-+-EMPTY--------------------------+---+   
   |   '-(--| multipolygon-z-parts |--)-'   |   
   +-M-+-EMPTY--------------------------+---+   
   |   '-(--| multipolygon-m-parts |--)-'   |   
   '-ZM-+-EMPTY---------------------------+-'   
        '-(--| multipolygon-zm-parts |--)-'     

point-coordinates

|--x_coord--y_coord---------------------------------------------|

point-z-coordinates

|--| point-coordinates |--y_coord-------------------------------|

point-m-coordinates

|--| point-coordinates |--m_coord-------------------------------|

point-zm-coordinates

|--| point-coordinates |--y_coord--m_coord----------------------|

Read syntax diagramSkip visual syntax diagram
linestring-points

                               .-,-----------------------.   
                               V                         |   
|----| point-coordinates |--,----| point-coordinates |---+------|

linestring-z-points

|----| point-z-coordinates |--,--------------------------------->

   .-,-------------------------.   
   V                           |   
>----| point-z-coordinates |---+--------------------------------|

linestring-m-points

|----| point-m-coordinates |--,--------------------------------->

   .-,-------------------------.   
   V                           |   
>----| point-m-coordinates |---+--------------------------------|

linestring-zm-points

|----| point-zm-coordinates |--,-------------------------------->

   .-,--------------------------.   
   V                            |   
>----| point-zm-coordinates |---+-------------------------------|

polygon-rings

   .-,--------------------------------------------------.   
   V                                                    |   
|----(--| linestring-points |--| linestring-points |--)-+-------|

polygon-z-rings

   .-,------------------------------------------------------.   
   V                                                        |   
|----(--| linestring-z-points |--| linestring-z-points |--)-+---|

polygon-m-rings

   .-,------------------------------------------------------.   
   V                                                        |   
|----(--| linestring-m-points |--| linestring-m-points |--)-+---|

polygon-zm-rings

   .-,--------------------------------------------------------.   
   V                                                          |   
|----(--| linestring-zm-points |--| linestring-zm-points |--)-+--|

multipoint-parts

   .-,-------------------------.   
   V                           |   
|------| point-coordinates |---+--------------------------------|

multipoint-z-parts

   .-,---------------------------.   
   V                             |   
|------| point-z-coordinates |---+------------------------------|

multipoint-m-parts

   .-,---------------------------.   
   V                             |   
|------| point-m-coordinates |---+------------------------------|

multipoint-zm-parts

   .-,----------------------------.   
   V                              |   
|------| point-zm-coordinates |---+-----------------------------|

multilinestring-parts

   .-,---------------------------.   
   V                             |   
|----(--| linestring-points |--)-+------------------------------|

multilinestring-z-parts

   .-,-----------------------------.   
   V                               |   
|----(--| linestring-z-points |--)-+----------------------------|

multilinestring-m-parts

   .-,-----------------------------.   
   V                               |   
|----(--| linestring-m-points |--)-+----------------------------|

multilinestring-zm-parts

   .-,------------------------------.   
   V                                |   
|----(--| linestring-zm-points |--)-+---------------------------|

multipolygon-parts

   .-,-----------------------.   
   V                         |   
|----(--| polygon-rings |--)-+----------------------------------|

multipolygon-z-parts

   .-,-------------------------.   
   V                           |   
|----(--| polygon-z-rings |--)-+--------------------------------|

multipolygon-m-parts

   .-,-------------------------.   
   V                           |   
|----(--| polygon-m-rings |--)-+--------------------------------|

multipolygon-zm-parts

   .-,--------------------------.   
   V                            |   
|----(--| polygon-zm-rings |--)-+-------------------------------|

Parameters

x_coord

A numerical value (fixed, integer, or floating point), which represents the X coordinate of a point.

y_coord

A numerical value (fixed, integer, or floating point), which represents the Y coordinate of a point.

z_coord

A numerical value (fixed, integer, or floating point), which represents the Z coordinate of a point.

m_coord

A numerical value (fixed, integer, or floating point), which represents the M coordinate (measure) of a point.

If the geometry is empty, then the keyword EMPTY is to be specified instead of the coordinate list. The EMPTY keyword must not be embedded within the coordinate list

The following table provides some examples of possible text representations.

Table 1. Geometry types and their text representations

Geometry type

WKT representation

Comment

point

POINT EMPTY

empty point

point

POINT ( 10.05 10.28 )

point

point

POINT Z( 10.05 10.28 2.51 )

point with Z coordinate

point

POINT M( 10.05 10.28 4.72 )

point with M coordinate

point

POINT ZM( 10.05 10.28 2.51 4.72 )

point with Z coordinate and M coordinate

linestring

LINESTRING EMPTY

empty linestring

polygon

POLYGON (( 10 10, 10 20, 20 20, 20 15, 10 10))

polygon

multipoint

MULTIPOINT Z(10 10 2, 20 20 3)

multipoint with Z coordinates

multilinestring

MULTILINESTRING M(( 310 30 1, 40 30 20, 50 20 10 )( 10 10 0, 20 20 1))

multilinestring with M coordinates

multipolygon

MULTIPOLYGON ZM((( 1 1 1 1, 1 2 3 4, 2 2 5 6, 2 1 7 8, 1 1 1 1 )))

multipolygon with Z coordinates and M coordinates