Name

ST_PointN — 返回几何图形中第一条直线串或圆形直线串中的第N点。

Synopsis

geometry ST_PointN(geometry a_linestring, integer n);

描述

返回几何图形中单个线串或圆形线串中的第N个点。负值从线串的末尾向后计数,因此-1是最后一个点。如果几何图形中没有线串,则返回NULL。

[Note]

从0.8.0版开始,OGC规范的索引是从1开始的。向后索引(负索引)不在OGC中,以前的版本将其实现为从0开始。

[Note]

如果要获取多重线串中每条线串的第N点,请与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

[Note]

已更改:2.0.0不再适用于单个几何体多线串。在旧版本的PostGIS中,单行多行字符串可以很好地与该函数配合使用,并返回起点。在2.0.0中,它只是像任何其他多行字符串一样返回NULL。

已更改:2.3.0:可用的负索引(-1为最后一点)

示例

-- 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)
(1 row)

SELECT ST_AsText(f)
FROM ST_GeomFromText('LINESTRING(0 0 0, 1 1 1, 2 2 2)') AS g
  ,ST_PointN(g, -2) AS f; -- 1 based index

    st_astext
-----------------
 POINT Z (1 1 1)
(1 row)

另请参阅

ST_NPoints