ST_NumPoints
Returns the number of points (vertices) in a geometry.
Syntax
ST_NumPoints(geometry)
Parameters
| Parameter | Type | Description |
|---|---|---|
| geometry | Geometry | Input geometry |
Returns
| Type | Description |
|---|---|
| Int64 | Number 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
- ST_NumGeometries - Count geometries in collection
- ST_Simplify - Reduce point count
- ST_Length - Measure length