ST_NUMPOINTS scalar function

The ST_NUMPOINTS function takes a geometry as an input parameter and returns the number of points that were used to define that geometry. For example, if the geometry is a polygon and five points were used to define that polygon, then the returned number is 5.

If geometry is null, the result is the null value. If geometry is empty, 0 (zero) is returned.

Read syntax diagramSkip visual syntax diagramST_NUMPOINTS(geometry)
geometry
A value of type ST_GEOMETRY or one of its subtypes for which the number of points is returned.

The result of the function is INTEGER.

Example

For a variety of geometries in a table, use ST_NUMPOINTS to determine how many points are within each geometry.

CREATE TABLE sample_geometries (id VARCHAR(18), geometry QSYS2.ST_GEOMETRY);

INSERT INTO sample_geometries (id, geometry)
  VALUES (1, QSYS2.ST_POINT('point (44 14)')),
         (2, QSYS2.ST_LINESTRING('linestring (0 0, 20 20)')),
         (3, QSYS2.ST_POLYGON('polygon((0 0, 0 40, 40 40, 40 0, 0 0))')),
         (4, QSYS2.ST_MULTIPOINT('multipoint((0 0), (10 20), (15 20), (30 30))')),
         (5, QSYS2.ST_MULTILINESTRING('MultiLineString((10 10, 20 20), (15 15, 30 15))')),
         (6, QSYS2.ST_MULTIPOLYGON('MultiPolygon(((10 10, 10 20, 20 20, 20 15, 10 10)),
                                                 ((60 60, 70 70, 80 60, 60 60 )))'));

SELECT id, QSYS2.ST_GEOMETRYTYPE(geometry) AS spatial_type, 
       QSYS2.ST_NUMPOINTS (geometry) AS num_points
  FROM sample_geometries;
Results:

ID   SPATIAL_TYPE      NUM_POINTS
--   ---------------   ----------  
 1   ST_POINT                  1
 2   ST_LINESTRING             2
 3   ST_POLYGON                5
 4   ST_MULTIPOINT             4
 5   ST_MULTILINESTRING        4
 6   ST_MULTIPOLYGON           9