Returns the number of vertices in a geometry object. Works with all geometry types, including circular strings, curves, polyhedral surfaces, and 3D objects.
Syntax
integer ST_NPoints(geometry g1);Parameters
| Parameter | Description |
|---|---|
| g1 | The geometry object to query. |
Examples
Count vertices in a polygon
SELECT ST_NPoints('POLYGON((0 0,0 1,1 1,0 0))'::geometry);
st_npoints
------------
4
(1 row)Closing vertices are counted. For a polygon defined as
(0 0, 0 1, 1 1, 0 0), the closing point (0 0) is counted, so the total is 4, not 3.