In QGIS, is there a way to count the number of vertices of polygons and lines in a given layer, and create a separate field containing these values? I suspect it's a function somewhere in the field calculator but I can't find it.
You can use the excellent 'Vertices Counter' plugin which does exactly this. You can see the step-by-step guide here:
Look in the vector menu, there is a "extract nodes" tool.
As times go by and version changes, some hints concerning the recent QGIS versions 3.2 and 2.18.22 LTR (by Aug. 7th, 2018). In QGIS 2.18 the Vertices Counter plugin works as usual, but seems not yet been ported to QGIS 3. But fortunally, there is another solution available in field calculator that you expected to find nearly six years ago.
Two relevant functions are available:
MULTIPOINT geometry of the source geoemtries nodes and
num_geometries() counts the geometries in a collection or
so combining these functions and creating a virtual field will accomplish this task:
if you or anyone are interested with arcmap , this page - HowTo: Count the vertices for line or polygon features in ArcMap - can help you...
1. Right-click the layer to be evaluated in the Table of Contents and click Open Attribute Table. 2. From the Table Options drop-down, click Add Field to add a new field to the table. 3. Name the field VxCount and select Long Integer for the field type. Click OK. 4. Right-click the heading of the new field and click Field Calculator. The geoprocessing tool, Calculate Field, can also be used to populate the field. 5. Under Parser, select Python. 6. In the main expression box, set: VxCount = !shape!.pointcount 7. Click OK.
i hope it helps you...