Nombre

ST_PointN — Devuelve el número de puntos en un valor ST_LineString o ST_CircularString.

Sinopsis

geometry ST_PointN(geometry a_linestring, integer n);

Descripción

Devuelve el punto enésimo en una sola cadena de línea o cadena de línea circular en la geometría. Los valores negativos se contabilizan hacia atrás desde el final de la cadena de línea, por lo que -1 es el último punto. Devuelve NULL si no hay cadena de línea en la geometría.

[Nota]

Index is 1-based as for OGC specs since version 0.8.0. Backward indexing (negative index) is not in OGC. Previous versions implemented this as 0-based instead.

[Nota]

Si desea obtener el punto n-ésimo de cada cadena de línea en una multiple cadena de línea, utilícelo en conjunción con ST_Dump

This method implements the OGC 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.

Cambiado: 2.0.0 ya no funciona con una sola geometría multilinestrings. En versiones antiguas de PostGIS -- una sola línea MultiLineString trabajaría felizmente con esta función y regresaría el punto de inicio. En 2.0.0 sólo devuelve NULL como cualquier otro MultiLineString.

Cambiado: 2.3.0: indexación negativa disponible (-1 es el último punto)

Ejemplos

This example extracts all POINT geometries from a LineString.

Code
SELECT ST_PointN(
      column1,
      generate_series(1, ST_NPoints(column1))
   )
FROM ( VALUES ('LINESTRING(0 0,1 1,2 2)'::geometry) ) AS foo;
Output
POINT(0 0)
 POINT(1 1)
 POINT(2 2)
(3 rows)
Figure
Geometry figure for visual-st-pointn-01

This example uses a CircularString.

Code
SELECT ST_PointN('CIRCULARSTRING(1 2,3 2,1 2)', 2);
Output
POINT(3 2)
Figure
Geometry figure for visual-st-pointn-02

The index is 1-based. A negative index counts backward from the end of the LineString.

Code
SELECT f
FROM ST_GeomFromText('LINESTRING(0 0 0,1 1 1,2 2 2)') AS g
  CROSS JOIN ST_PointN(g, -2) AS f;
Output
POINT Z (1 1 1)
Figure
Geometry figure for visual-st-pointn-03

Ver también

ST_NPoints