TransWikia.com

Determining the number of vertices of a selected object in QGIS 3

Geographic Information Systems Asked on February 26, 2021

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

2 Answers

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

Correct answer by Erik on February 26, 2021

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

Answered by Kadir Şahbaz on February 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP