ST_AsText function
The ST_AsText function takes a geometry as an input parameter and returns its well-known text representation.
If the given geometry is null, then null is returned.
This function can also be called as a method.
Syntax
Parameter
- geometry
- A value of type ST_Geometry or one of its subtypes to be converted to the corresponding well-known text representation.
Return type
CLOB(2G)
Example
In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
After capturing
and inserting the data into the SAMPLE_GEOMETRIES table, an analyst
wants to verify that the values inserted are correct by looking at
the well-known text representation of the geometries.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries(id SMALLINT, spatial_type varchar(18),
geometry ST_GEOMETRY)
INSERT INTO sample_geometries(id, spatial_type, geometry)
VALUES
(1, 'st_point', ST_Point(50, 50, 0)),
(2, 'st_linestring', ST_LineString('linestring
(200 100, 210 130, 220 140)', 0)),
(3, 'st_polygon', ST_Polygon('polygon((110 120, 110 140,
130 140, 130 120, 110 120))', 0))
The following SELECT statement lists the spatial
type and the WKT representation of the geometries. The geometry
is converted to text by the ST_AsText function. It is then cast
to a varchar(120) because the default output of the ST_AsText function
is CLOB(2G).
SELECT id, spatial_type, cast(geometry..ST_AsText
AS varchar(150)) AS wkt
FROM sample_geometries
Results:
ID SPATIAL_TYPE WKT
------ ------------------ ------------------------------------------------
1 st_point POINT ( 50.00000000 50.00000000)
2 st_linestring LINESTRING ( 200.00000000 100.00000000,
210.00000000 130.00000000, 220.00000000
140.00000000)
3 st_polygon POLYGON (( 110.00000000 120.00000000,
130.00000000 120.00000000, 130.00000000
140.00000000, 110.00000000140.00000000,
110.00000000 120.00000000))