ST_PointN — Return the Nth point in the first linestring or circular linestring in the geometry. Return NULL if there is no linestring in the geometry.
geometry ST_PointN(geometry a_linestring, integer n);
Return the Nth point in the first linestring or circular linestring in the geometry. Return NULL if there is no linestring in the geometry.
![]() | |
Index is 1-based as for OGC specs since version 0.8.0. Previous versions implemented this as 0-based instead. |
![]() | |
If you want to get the nth point of each line string in a multilinestring, use in conjunction with ST_Dump |
This method implements the OpenGIS Simple Features
Implementation Specification for SQL 1.1.
This method implements the SQL/MM specification. SQL-MM 3: 7.2.5, 7.3.5
This function supports 3d and will not drop the z-index.
This method supports Circular Strings and Curves
-- Extract all POINTs from a LINESTRING
SELECT ST_AsText(
ST_PointN(
column1,
generate_series(1, ST_NPoints(column1))
))
FROM ( VALUES ('LINESTRING(0 0, 1 1, 2 2)'::geometry) ) AS foo;
st_astext
------------
POINT(0 0)
POINT(1 1)
POINT(2 2)
(3 rows)
--Example circular string
SELECT ST_AsText(ST_PointN(ST_GeomFromText('CIRCULARSTRING(1 2, 3 2, 1 2)'),2));
st_astext
----------
POINT(3 2)