PostGIS: Count number of vertices of lines and polygons in tables


14

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 ;))

Réponses:


27

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;

many thanks that works perfectly. I knew it must be simple
tjmgis
En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.