13

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.

10

Number of points - just simple formula in QGIS field calculator:

num_points($geometry)

enter image description here

7

You can use the excellent 'Vertices Counter' plugin which does exactly this. You can see the step-by-step guide here:

Counting Number of Vertices in a Layer

  • Thanks Ujaval. I'm afraid python kind of scares me but I just got around to looking at your blog today and it works! Thanks very much and I'm sorry for not looking at this sooner. R – crichard75 Nov 30 '12 at 15:20
  • 1
    It seems that this plugin is no longer available in QGIS 3.0+ – user3386170 Dec 21 '18 at 19:53
  • Correct. See the other answer where you can achieve the same using a formula in the field calculator num_points($geometry) – spatialthoughts Dec 28 '18 at 6:19
3

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:

enter image description here

resulting in

enter image description here

2

Look in the vector menu, there is a "extract nodes" tool.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Thanks Giovanni but it’s not quite what I’m looking for. I just tried “extracting nodes” and counting “Points in Polygon”. I’m afraid the shapefile I am dealing with consists of multiple abutting polygons. The polygons were created by snapping to vertex. Extracting nodes creates multiple overlapping points which end up in the count. I’m looking for a way to count the nodes of each individual polygon, so a square polygon may have 4 nodes, not the potential 16 nodes or more from abutting polygons. – crichard75 Aug 29 '12 at 19:07
  • Then you need to import your data into a fully topological gis = GRASS, you can do it in qgis using the grass plugin. – Giovanni Manghi Aug 30 '12 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.