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 specified linestring or multipoint.

If the specified 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).

Syntax

Read syntax diagramSkip visual syntax diagramST_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

ST_Point

Example

The following example illustrates the use of ST_PointN.

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_POINT
  FROM sample_lines
Results:

ID        SECOND_POINT
--------- --------------------------------
        1 POINT (5 5)