ST_NumPoints
Definition
ST_NumPoints returns the number of points (vertices) in a 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
Oracle and PostgreSQL
sde.st_numpoints (geometry1 sde.st_geometry)
SQLite
st_numpoints (geometry1 geometryblob)
Return type
Integer
Example
The numpoints_test table is created with the geotype column, which contains the geometry type stored in the g1 column.
The INSERT statements insert a point, a linestring, and a polygon.
The SELECT query uses the ST_NumPoints function to get the number of points in each feature for each feature type.
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)', 4326)
);
INSERT INTO NUMPOINTS_TEST VALUES (
'linestring',
sde.st_linefromtext ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);
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))', 4326)
);
SELECT geotype, sde.st_numpoints (g1) Number_of_points
FROM NUMPOINTS_TEST;
GEOTYPE Number_of_points
point 1
linestring 2
polygon 5
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)', 4326)
);
INSERT INTO numpoints_test VALUES (
'linestring',
sde.st_linestring ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);
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))', 4326)
);
SELECT geotype, sde.st_numpoints (g1)
AS Number_of_points
FROM numpoints_test;
geotype number_of_points
point 1
linestring 2
polygon 5
SQLite
CREATE TABLE numpoints_test (
geotype text(12)
);
SELECT AddGeometryColumn(
NULL,
'numpoints_test',
'g1',
4326,
'geometry',
'xy',
'null'
);
INSERT INTO numpoints_test VALUES (
'point',
st_point ('point (10.02 20.01)', 4326)
);
INSERT INTO numpoints_test VALUES (
'linestring',
st_linestring ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);
INSERT INTO numpoints_test VALUES (
'polygon',
st_polygon ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 4326)
);
SELECT geotype AS "Type of geometry", st_numpoints (g1) AS "Number of points"
FROM numpoints_test;
Type of geometry Number of points
point 1
linestring 2
polygon 5