Returns the Nth point in a LineString or circular string. Negative index values count from the end of the LineString, so -1 returns the last point. Returns NULL if the input geometry is not a LineString.
Syntax
geometry ST_PointN(geometry aLinestring, integer n)Parameters
| Parameter | Description |
|---|---|
aLinestring | The LineString or circular string geometry. |
n | The 1-based index of the point to return. Negative values count from the end: -1 is the last point. |
Examples
Get 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)Get 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)Usage notes
To get the Nth point of each LineString within a MultiLineString, useST_PointNtogether withST_Dump.
ST_PointN supports circular strings and curves, and preserves Z coordinates for 3D geometries.该文章对您有帮助吗?