19

I have 23 tables in a PostGIS schema which I need to count the number of vertices of. The tables are a mixture of lines and polygons so realised I need to use ST_NPoints(geom)

So I ran the following query

SELECT count(ST_NPoints(geom) FROM lines;

the result/count equals the number of features in that table and not the total number of vertices of all features in that table.

I must be missing something but cannot figure it out (must be monday morning ;))

dbaston
  • 13,048
  • 3
  • 49
  • 81
tjmgis
  • 3,330
  • 1
  • 23
  • 37

1 Answers1

33

With your query you are only counting the number of rows in your table (see it, as the number of times that you are calling st_npoints), you need to sum the results that returns st_npoints for each geometry

SELECT sum(ST_NPoints(geom)) FROM lines;
Francisco Puga
  • 4,618
  • 21
  • 40