Functions / PostGIS / ST_NPoints
PostGISGeometry Accessors

ST_NPoints

What is ST_NPoints?

ST_NPoints is a PostGIS function that returns the total number of vertices in a geometry, counting every point across all parts, rings, and nested components.

SQL
ST_NPoints(geometry g)integer

Includes the closing vertex of polygon rings and all duplicates as stored.

When would you use ST_NPoints?

Use ST_NPoints for vertex-count profiling — identifying over-dense geometries that slow down rendering or spatial operations, validating simplification outcomes, and storage planning:

Code
undefined

It is also the standard input to heuristics like "is this geometry heavy enough to warrant generalization for a low zoom?"

FAQs

What is the difference from ST_NumPoints?

ST_NumPoints returns the vertex count of a single LINESTRING only — other types return NULL. ST_NPoints works on every geometry type and sums across parts.

Does ST_NPoints count the closing vertex of rings?

Yes. The closing vertex is stored in the coordinate sequence, so it contributes to the count.

How big a vertex count is too big?

Depends on workload. For interactive map tiles, anything above a few thousand vertices per feature at mid-zoom usually justifies simplification. For analytical workloads, multi-million-vertex rivers and coastlines are common.

Is ST_NPoints fast?

Yes — the count is maintained in the coordinate-sequence header and does not require iterating vertices.