Line feature - get number of vertices

807
2
01-01-2012 09:38 AM
OlivierOlivier
New Contributor III
Hi,

I'm searching a way to get the number of vertices composing a line, without counting them. I have not many experiences in Python, but unless I missed something searching forums and documentation, it seems that it's not a feature property as I expected. Am I right ?

Thanks to all answers

Olivier
Tags (2)
0 Kudos
2 Replies
FrédéricPRALLY
Esri Contributor
Hi Olivier,

To calculate the number of vertices composing a line, you can use calculate fields using logic with Python.

See sample below:

Parser:
Python

Expression:
getNumberOfVertices( !Shape!)

Code Block:
def getNumberOfVertices(feature):
    partnum = 0
    vertices = []
    while partnum < feature.partCount:
        part = feature.getPart(partnum)
        pnt = part.next()
        pntcount = 0
        while pnt:
            vertices.append(pntcount)
            pnt = part.next()
            pntcount+=1
        partnum+=1
        
    return len(vertices)


or load getNumberOfVertices.cal in joined file.

Have a good day,

Best regards,

Fred
0 Kudos
OlivierOlivier
New Contributor III
Hi Frederic,

Thanks for this kind answer, it will improve my basic python knowledge. I hoped that vertices would be an attribute of each line feature but it amazingly seems that it's not the case.

Happy New Year,

Olivier
0 Kudos