ST_PointN
Signature
POINT ST_PointN(GEOMETRY geometry, INT n);
Description
Returns the nth point of geom
if geom
is a LINESTRING
or a
MULTILINESTRING
containing exactly one LINESTRING
; NULL
otherwise.
Do I start counting from 0 or 1?
The index runs from 1 to N.
Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.
Example
SELECT ST_PointN('LINESTRING(1 1, 1 6, 2 2, -1 2))', 2);
-- Answer: POINT(1 6)
SELECT ST_PointN('MULTILINESTRING((1 1, 1 6, 2 2, -1 2))', 3);
-- Answer: POINT(2 2)
SELECT ST_PointN('MULTIPOINT(1 1, 1 6, 2 2, -1 2)', 3);
-- Answer: NULL
-- This MULTILINESTRING contains two LINESTRINGs.
SELECT ST_PointN('MULTILINESTRING((1 1, 1 6, 2 2, -1 2),
(0 1, 2 4))', 3);
-- Answer: NULL
SELECT ST_PointN('LINESTRING(1 1, 1 6, 2 2, -1 2))', 0);
-- Answer: Point index out of range. Must be between 1 and
-- ST_NumPoints.