Skip to main content

ST_NumPoints

Returns the number of points (vertices) in a geometry.

Syntax​

ST_NumPoints(geometry)

Parameters​

ParameterTypeDescription
geometryGeometryInput geometry

Returns​

TypeDescription
Int64Number of points in the geometry

Examples​

Points in LineString​

SELECT ST_NumPoints(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 0)'));
-- Returns: 3

Points in Polygon​

SELECT ST_NumPoints(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))'));
-- Returns: 5 (includes closing point)

Measure Complexity​

SELECT id, ST_NumPoints(geom) as vertex_count
FROM roads
ORDER BY vertex_count DESC;

Compare Original and Simplified​

SELECT
ST_NumPoints(geom) as original,
ST_NumPoints(ST_Simplify(geom, 0.01)) as simplified
FROM coastlines;

Notes​

  • Point geometry returns 1
  • Polygon rings count the closing point separately
  • Useful for measuring geometry complexity
  • Higher point counts may indicate need for simplification

See Also​