Definition
ST_PointN takes an ST_LineString and an integer index and returns a point that is the nth vertex in the ST_LineString's path.
Syntax
Oracle and PostgreSQL
sde.st_pointn (line1 sde.st_linestring, index integer)
SQLite
st_pointn (line1 st_linestring, index int32)
Return type
ST_Point
Example
The pointn_test table is created with the gid column, which uniquely identifies each row, and the ln1 ST_LineString column. The INSERT statements insert two linestring values. The first linestring doesn't have z-coordinates or measures, while the second linestring has both.
The SELECT query uses the ST_PointN and ST_AsText functions to return the well-known text for the second vertex of each linestring.
Oracle
CREATE TABLE pointn_test (
gid integer,
ln1 sde.st_geometry
);
INSERT INTO POINTN_TEST VALUES (
1,
sde.st_linefromtext ('linestring (10.02 20.01, 23.73 21.92, 30.10 40.23)', 4326)
);
INSERT INTO POINTN_TEST VALUES (
2,
sde.st_linefromtext ('linestring zm(10.02 20.01 5.0 7.0, 23.73 21.92 6.5 7.1, 30.10 40.23 6.9 7.2)', 4326)
);
SELECT gid, sde.st_astext (sde.st_pointn (ln1, 2)) The_2ndvertex
FROM POINTN_TEST;
GID The_2ndvertex
1 POINT (23.73 21.92)
2 POINT ZM (23.73 21.92 6.5 7.1)
PostgreSQL
CREATE TABLE pointn_test (
gid serial,
ln1 sde.st_geometry
);
INSERT INTO pointn_test (ln1) VALUES (
sde.st_linestring ('linestring (10.02 20.01, 23.73 21.92, 30.10 40.23)', 4326)
);
INSERT INTO pointn_test (ln1) VALUES (
sde.st_linestring ('linestring zm(10.02 20.01 5.0 7.0, 23.73 21.92 6.5 7.1, 30.10 40.23 6.9 7.2)', 4326)
);
SELECT gid, sde.st_astext (sde.st_pointn (ln1, 2))
AS The_2ndvertex
FROM pointn_test;
gid the_2ndvertex
1 POINT (23.73 21.92)
2 POINT ZM (23.73 21.92 6.5 7.1)
SQLite
CREATE TABLE pointn_test (
gid integer primary key autoincrement not null
);
SELECT AddGeometryColumn(
NULL,
'pointn_test',
'ln1',
4326,
'linestringzm',
'xyzm',
'null'
);
INSERT INTO pointn_test (ln1) VALUES (
st_linestring ('linestring (10.02 20.01, 23.73 21.92, 30.10 40.23)', 4326)
);
INSERT INTO pointn_test (ln1) VALUES (
st_linestring ('linestring zm(10.02 20.01 5.0 7.0, 23.73 21.92 6.5 7.1, 30.10 40.23 6.9 7.2)', 4326)
);
SELECT gid, st_astext (st_pointn (ln1, 2))
AS "Second Vertex"
FROM pointn_test;
gid Second Vertex
1 POINT ( 23.73000000 21.92000000)
2 POINT ZM ( 23.73000000 21.92000000 6.50000000 7.10000000)