ST_PointN function

The ST_PointN function takes a linestring or a multipoint and an index as input parameters and returns that point in the linestring or multipoint that is identified by the index. The resulting point is represented in the spatial reference system of the given linestring or multipoint.

If the given linestring or multipoint is null or is empty, then null is returned. If the index is smaller than 1 or larger than the number of points in the linestring or multipoint, then null is returned and a warning condition is returned (SQLSTATE 01HS2).

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_PointN(geometry,index )

Parameters

geometry
A value of type ST_LineString or ST_MultiPoint that represents the geometry from which the point that is identified by index is returned.
index
A value of type INTEGER that identifies the nth point which is to be returned from geometry.

Return type

db2gse.ST_Point

Example

The following example illustrates the use of ST_PointN.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_lines (id INTEGER, line ST_LineString)

INSERT INTO sample_lines
  VALUES (1, ST_LineString ('linestring (10 10, 5 5, 0 0, 10 0, 5 5, 0 10)', 0) )

SELECT id, CAST ( ST_AsText (ST_PointN (line, 2) ) AS VARCHAR(60) ) SECOND_INDEX
  FROM sample_lines
Results:

ID        SECOND_INDEX
--------- --------------------------------
        1 POINT (5.00000000 5.00000000)