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.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityNumber of points - just simple formula in QGIS field calculator:
num_points($geometry)
See the screenshot below: in this case, the number of vertices of each feature is added to the field "vertex" in the attribute table. Alternatively, you can create also "Create a new field" and get results there.
You can use the excellent 'Vertices Counter' plugin which does exactly this. You can see the step-by-step guide here:
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:
nodes_to_points()
creates MULTIPOINT
geometry of the source geoemtries nodes and
num_geometries()
counts the geometries in a collection or MULTI...
geometry
so combining these functions and creating a virtual field will accomplish this task:
resulting in
Look in the vector menu, there is a "extract nodes" tool.