ST_NumPoints
Definition
ST_NumPoints returns the number of points (vertices) in an ST_Geometry.
For polygons, both the starting and ending vertices are counted, even though they occupy the same location.
Note that this number is different than the NUMPTS attribute of the ST_Geometry type. The NUMPTS attribute contains a count of the vertices in all the parts of the geometry including separators that occur between parts. There is one separator between each part. For example, a multipart linestring with three parts has two separators. In the NUMPTS attribute, each separator is counted as one vertex. Conversely, the ST_NumPoints function does not include the separators in the vertex count.
Syntax
sde.st_numpoints (g1 sde.st_geometry)
Return type
Integer
Example
The numpoints_test table is created with the geotype column, which contains the ST_Geometry type stored in the g1 geometry column.
The INSERT statements insert a point, a linestring, and a polygon.
Oracle
CREATE TABLE numpoints_test (geotype varchar(12), g1 sde.st_geometry); INSERT INTO NUMPOINTS_TEST VALUES ( 'point', sde.st_pointfromtext ('point (10.02 20.01)', 0) ); INSERT INTO NUMPOINTS_TEST VALUES ( 'linestring', sde.st_linefromtext ('linestring (10.02 20.01, 23.73 21.92)', 0) ); INSERT INTO NUMPOINTS_TEST VALUES ( 'polygon', sde.st_polyfromtext ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 0) );
PostgreSQL
CREATE TABLE numpoints_test (geotype varchar(12), g1 sde.st_geometry); INSERT INTO numpoints_test VALUES ( 'point', sde.st_point ('point (10.02 20.01)', 0) ); INSERT INTO numpoints_test VALUES ( 'linestring', sde.st_linestring ('linestring (10.02 20.01, 23.73 21.92)', 0) ); INSERT INTO numpoints_test VALUES ( 'polygon', sde.st_polygon ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 0) );
The query lists the geometry type and the number of points in each feature.
Oracle
SELECT geotype, sde.st_numpoints (g1) Number_of_points FROM NUMPOINTS_TEST; GEOTYPE Number_of_points point 1 linestring 2 polygon 5
PostgreSQL
SELECT geotype, sde.st_numpoints (g1) AS Number_of_points FROM numpoints_test; geotype number_of_points point 1 linestring 2 polygon 5