Returns the Nth point of a LineString or circular LineString object.
Syntax
geometry ST_PointN(geometry aLinestring, integer n)Parameters
| Parameter | Description |
|---|---|
aLinestring | The LineString object or circular LineString object to query. |
n | The index of the point to return. Negative values count backward from the end: -1 returns the last point. |
Usage notes
Returns NULL if
aLinestringis not a LineString.To get the Nth point of each LineString in a MultiLineString, combine
ST_PointNwithST_Dump.Supports circular strings and curves.
Supports 3D geometries and preserves Z coordinates.
Examples
Return the first point of a LineString:
SELECT ST_AsText(ST_PointN('LINESTRING(0 0,2 2)'::geometry, 1)); st_astext
------------
POINT(0 0)
(1 row)Return the last point using a negative index:
SELECT ST_AsText(ST_PointN('LINESTRING(0 0,2 2)'::geometry, -1)); st_astext
------------
POINT(2 2)
(1 row)