liveBook · Manning

St_npoints

As explained in Just Use Postgres!

ST_NPoints is a PostGIS function that returns the number of points in a geometry.

ST_NPoints returns the number of points that make up a geometry. For polygon analysis, it provides a quick measure of boundary complexity before examining area or spatial relationships. section 10.5.2

Count polygon boundary points

SELECT name, tourism, ST_NPoints(way) FROM florida.planet_osm_polygon WHERE name = 'Walt Disney World'; The query returns Walt Disney World with 473 points, indicating a detailed polygon boundary. section 10.5.2

Listing 10.16 Finding a polygon and the number of points it’s made of
SELECT name, tourism, ST_NPoints(way)
FROM florida.planet_osm_polygon
WHERE name = 'Walt Disney World';

Use the runnable listing to count points for a named polygon, then compare the returned value with the sample output. section 10.5.2

How Just Use Postgres! covers it

How deep it goes
Defines the function and demonstrates one SQL query, stopping short of implementation internals.
Examples
Counts the 473 points defining the Walt Disney World polygon.
What it assumes
Assumes familiarity with SQL, geometry columns, and the PostGIS spatial dataset.
What you can do after
Apply it via PostGIS to count points in geometries returned by spatial queries.
How it connects
Connects geometry point counts with polygons, ST_Area, ST_Within, and ST_Equals.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.