# Calculate polygon sides

2416
6
09-13-2011 10:14 AM
New Contributor
Hi all !

I have a polygon shp, and i want to calculate for this shp how many sides has each polygon, as the below image. Is it possible ? im almost sure that it is possible.

Tags (3)
6 Replies
MVP Honored Contributor
This counts vertices, minus 1, in the Field Calculator which should be the number of sides.

Parser:
Python

Expression:
`MySub(!shape!)`

Codeblock:
```def MySub(feat):
partnum = 0

# Count the number of points in the current multipart feature
partcount = feat.partCount
pntcount = 0

# Enter while loop for each part in the feature (if a singlepart feature
# this will occur only once)
#
while partnum < partcount:
part = feat.getPart(partnum)
pnt = part.next()

# Enter while loop for each vertex
#
while pnt:
pntcount += 1
pnt = part.next()

# If pnt is null, either the part is finished or there is an
# interior ring
#
if not pnt:
pnt = part.next()
partnum += 1
pntcount = pntcount - 1
return pntcount
```
New Contributor

This worked perfectly! Thanks

Esri Notable Contributor
You can convert the polygon file to a polyline file using the Split Line at Vertices tool.  Then Spatially Join the Polygon to the Polyline.  There will be a count field in the output.
Esri Notable Contributor
Great code sample Darren.  Thanks for sharing!
by
Esri Regular Contributor
If your polygons are simple without holes or multiparts, you can do the following:
- Add a field of type = LONG.
- Use Calculate Field tool with this expression: !shape!.pointcount - 1; and specify PYTHON as the expression type.

The resulting values should be the polygon side counts.
New Contributor
Hi folks !

Thanks a lot for your suggestions, i'm going to test your advices and i tell you how i was.

Regards.