7

How can I determine how many vertices/nodes a selected feature has in QGIS 3?

Taras
  • 32,823
  • 4
  • 66
  • 137
Eliasse
  • 453
  • 4
  • 13

3 Answers3

13

You can use the following script in QGIS Python Editor. Select a layer, run the script and select a feature.

def n_vertices(selected, _, __):
    n = len(selected)
if n == 1:
    g = iface.activeLayer().selectedFeatures()[0].geometry()
    print(len([v for v in g.vertices()]))
elif n > 1:
    print("Select only one feature")

iface.activeLayer().selectionChanged.connect(n_vertices)

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
12

num_points($geometry) returns the number of vertices of the current feature.

Taras
  • 32,823
  • 4
  • 66
  • 137
Erik
  • 16,269
  • 1
  • 24
  • 43
5

Try using the icon"Identify Features" tool (Ctrl+Shift+I) from the Attributes Toolbar.

Click on the target feature and check the (Derived) tab, where you may see the 'Vertices' attribute

result

Taras
  • 32,823
  • 4
  • 66
  • 137