PostGISGeometry Accessors

ST_NumPoints

What is ST_NumPoints?

ST_NumPoints is a PostGIS function that returns the number of points in a LINESTRING or CIRCULARSTRING. For other geometry types it returns NULL.

SQL
ST_NumPoints(geometry line)integer

For counting vertices in any geometry type, use ST_NPoints instead.

When would you use ST_NumPoints?

Use ST_NumPoints when you explicitly need the vertex count of a single linestring — for bounds-checking before ST_PointN, or to filter lines with minimum complexity:

SQL
1SELECT id, ST_NumPoints(geom) AS vcount
2FROM tracks
3WHERE GeometryType(geom) = 'LINESTRING'
4  AND ST_NumPoints(geom) >= 100;

For mixed-type tables, use ST_NPoints which handles every geometry type.

FAQs

What is the difference between ST_NumPoints and ST_NPoints?

ST_NumPoints only works on LINESTRING/CIRCULARSTRING and returns NULL elsewhere. ST_NPoints works on any geometry and sums across all parts and rings.

Why does ST_NumPoints return NULL for my polygons?

By design — ST_NumPoints is a linestring-only accessor. Use ST_NPoints for polygons or any other type.

How do I access the Nth point?

ST_PointN(line, n) with 1-based indexing. Pair with ST_NumPoints to bound the index.

Is ST_NumPoints fast?

Yes — the count is cached in the coordinate-sequence header, so the call is O(1).