Constructor functions

更新时间:
复制 MD 格式

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

Returns a Geometry object that corresponds to the specified WKT string.

Syntax

geometry ST_GeomFromText(string wkt)

Parameters

Parameter

Description

wkt

The specified WKT string.

Note
  • The Geometry object supports the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

  • WKT strings that contain spatial reference system information are not supported. If the WKT format includes a Spatial Reference Identifier (SRID), you must store the SRID in a separate column. The SRID is used only as an identifier. The default SRID is 4326.

  • You can create an EMPTY object of any data type.

Examples

  • Example 1: The Geometry object is a Point.

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

    The following result is returned:

    +-------------+
    |    geom     |
    +-------------+
    | POINT (1 1) |
    +-------------+
  • Example 2: The Geometry object is a Polygon.

    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: The Geometry object is EMPTY.

    SELECT ST_GeomFromText('POLYGON EMPTY') as geom;

    The following result is returned:

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

ST_LineFromMultiPoint

Returns a LineString object that corresponds to the specified MultiPoint object.

Syntax

geometry ST_LineFromMultiPoint(geometry aMultiPoint)

Parameters

Parameter

Description

aMultiPoint

The specified MultiPoint object. You can use the ST_Collect function to combine Point objects into a MultiPoint object.

Example

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

Constructs a Point object.

Syntax

geometry ST_MakePoint(double x, double y)

Parameters

Parameter

Description

x

The longitude value x. The value must be of the DOUBLE type. If you enter a value of the INTEGER or LONG type, it is automatically converted to the DOUBLE type.

y

The latitude value y. The value must be of the DOUBLE type. If you enter a value of the INTEGER or LONG type, it is automatically converted to the DOUBLE type.

Note

This function does not support setting a spatial reference system or creating 3D objects.

Example

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)