# How to identify donut holes with the Field Calculator?

Question asked by RudinA on Jan 27, 2015
Latest reply on Jan 28, 2015 by RudinA

Anyone have any ideas why a field calculator function would return different results than an arcpy function written in pyscripter?

I'm processing hundreds of thousands of polygons in ArcGIS Desktop 10.2.2 in a model and I want to be able to capture which ones contain a donut hole (a.k.a. at least one part of the polygon forms at least one ring).  Since I don't see any pre-built tools for this, I assume the only way to do this without ArcObjects is through an iteration of each record's shape geometry using Python.  I built a python function in pyscripter using an example in the ESRI help at this location as a template and it worked on my sample data.

My problem now is that I get different results when running the python function in ArcMap's field calculator. When the code reads a feature that does have a donut hole in it, the code says it doesn't.

Here's my PyScripter code that gives correct results:

import arcpy

#Begin donut finder function

def has_donut(feat):
donut = 'F'
partcount = feat.partCount
for p in range (0,partcount):
part = feat.getPart(p)
for pnt in part:
if not pnt:
donut = 'T'
return donut
return donut

#set input polygon feature class

in_fc = r"C:\my_geodatababase.gdb\my_feature_class

#Loop over feature class records and print donut search result

with arcpy.da.SearchCursor(in_fc,['OID@','SHAPE@']) as cur:
for row in cur:
oid = str(row[0])
donut_type = has_donut(row[1])
print oid + ": " + donut_type

Here's my ArcMap field calculator setup that returns False even when a polygon contains a donut:

Parser: Python

Pre-Logic Script Code:

def has_donut(feat):

donut = 'F'

partcount = feat.partCount

for p in range (0,partcount):

part = feat.getPart(p)

for pnt in part:

if not pnt:

donut = 'T'

return donut

return donut

Field Calculator Expression:

has_donut( !SHAPE!)