All Products
Search
Document Center

:Constructor functions

Last Updated:Jan 23, 2025

Constructor functions create a geometry object from a Well-known Text (WKT) string or convert a given geometry object into other formats. This topic describes the constructor functions supported by the Lindorm streaming engine.

Functions

Function

Description

ST_GeomFromText

Constructs a geometry object based on the specified WKT string.

ST_LineFromMultiPoint

Constructs a LineString object based on the specified MultiPoint object.

ST_MakePoint

Constructs a point object.

ST_MakeLine

Constructs a LineString object based on geometry objects such as points or linestrings.

ST_GeomFromText

The ST_GeomFromText function constructs a geometry object based on the specified WKT string.

Syntax

geometry ST_GeomFromText(string wkt)

Parameters

Parameter

Description

wkt

The WKT string based on which you want to construct a geometry object.

Note
  • You can construct the following types of objects by calling this function: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

  • This function does not support WKT strings that include Spatial Reference Identifiers (SRIDs). You can create a column in the database to store the SRIDs (4326 by default) of the geometry objects that you construct.

  • You can construct an empty geometry object of any supported data type.

Examples

  • Example 1: Construct a point object.

    SELECT ST_GeomFromText('POINT(1 1)') as geom;

    The following result is returned:

    +-------------+
    |    geom     |
    +-------------+
    | POINT (1 1) |
    +-------------+
  • Example 2: Construct a polygon object.

    SELECT ST_GeomFromText('POLYGON (( 1 1, 1 2, 2 2, 2 1, 1 1))') AS poly;

    The following result is returned:

    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                                poly                                                                                                |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | 0020000003000010E600000001000000053FF00000000000003FF00000000000003FF000000000000040000000000000004000000000000000400000000000000040000000000000003FF00000000000003FF00000000000003FF0000000000000 |
    +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  • Example 3: Construct an empty polygon object.

    SELECT ST_GeomFromText('POLYGON EMPTY') as geom;

    The following result is returned:

    +---------------+
    |     geom      |
    +---------------+
    | POLYGON EMPTY |
    +---------------+

ST_LineFromMultiPoint

The ST_LineFromMultiPoint function constructs a LineString object based on the specified MultiPoint object.

Syntax

geometry ST_LineFromMultiPoint(geometry aMultiPoint)

Parameters

Parameter

Description

aMultiPoint

You can call the ST_Collect function to combine multiple specified point objects into a MultiPoint object.

Examples

SELECT ST_AsText(ST_LineFromMultiPoint(ST_Collect(ST_MakePoint(1,2),ST_MakePoint(3,4),ST_MakePoint(5,6)))) AS astext;

The following result is returned:

+-------------------------+
|         astext          |
+-------------------------+
| LINESTRING(1 2,3 4,5 6) |
+-------------------------+

ST_MakePoint

The ST_MakePoint function constructs a point object.

Syntax

geometry ST_MakePoint(double x, double y)

Parameters

Parameter

Description

x

The longitude of the point object that you want to construct. The value of this parameter is a number of the DOUBLE type. If you specify a number of the INTEGER or LONG type, it is automatically converted to the DOUBLE type.

y

The latitude of the point object that you want to construct. The value of this parameter is a number of the DOUBLE type. If you specify a number of the INTEGER or LONG type, it is automatically converted to the DOUBLE type.

Note

This function can be used to construct only 2D point objects without Spatial Reference System (SRS) information.

Examples

SELECT ST_AsText(ST_MakePoint(1, 2)) as text;

The following result is returned:

+-------------+
|    text     |
+-------------+
| POINT (1 2) |
+-------------+

ST_MakeLine

The ST_MakeLine constructs a LineString object based on geometry objects such as points or linestrings.

Syntax

geometry ST_MakeLine(geometry geomA, geometry geomB);
geometry ST_MakeLine(geometry... geoms)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

geoms

The geometry objects that you want to specify.

Note
  • You can specify only the point or LineString objects.

  • If you specify multiple LineString geometry objects, duplicate nodes are deleted in the construction process. For more information, see Example 3.

  • If you specify multiple point geometry objects, duplicate nodes are retained.

Examples

  • Example 1: Construct a LineString object based on given point geometry objects.

    SELECT ST_AsText(ST_MakeLine(ST_MakePoint(1,2), ST_MakePoint(3,4)));

    The following result is returned:

    LINESTRING(1 2, 3 4)
  • Example 2: Construct multiple LineString objects based on given point geometry objects.

    SELECT ST_AsText(ST_MakeLine(ST_MakePoint(1,2), ST_MakePoint(3,4), ST_MakePoint(5,6)));

    The following result is returned:

    LINESTRING(1 2, 3 4, 5 6)
  • Example 3: Construct a LineString object based on given LineString geometry objects.

    SELECT ST_AsText(ST_MakeLine(ST_GeomFromText('LINESTRING(0 0, 1 1)'), ST_GeomFromText('LINESTRING(1 1, 2 2, 3 3)')));

    The following result is returned:

    LINESTRING(0 0, 1 1, 2 2, 3 3)