# Detecting ring direction of a polygon using ArcPy

I am using ArcPy in ArcGIS 10.1 to process some geometry using the arcpy.da data access module.

However I have run into a problem with complex Polygons that contain inner rings/holes.

From the documentation in ArcGIS and this question I can detect rings via the None objects in the Point array.

But now I need to know whether these rings are clockwise or counter-clockwise so that I can tag them as inner or outer.

Is there an ArcPy function I can use to detect the rings' directions?

Pass in a list of vertices in the form `[(x1,y1), (x2,y2), ..., (xn, yn)]`. Returns true or false.

``````def is_clockwise(vertices):
if len(vertices) < 3:
return True
area = 0.0
ax, ay = vertices
for bx, by in vertices[1:]:
area += ax * by - ay * bx
ax, ay = bx, by
bx, by = vertices
area += ax * by - ay * bx
return area < 0.0
``````

If you run the Multipart_to_Singlepart tool first, all the geometries that have partCount > 1 will have inner rings. Using ArcPy scripting to read the geometry, the outer ring is returned as the first part, the remaining parts are then holes. You shouldn't need to analyse the ring orientation to figure this out.

• Based on this question and related info at this other question, I do not believe this is correct. You can have a singlepart polygon with a hole whose part count is 1. Parts are distinct from rings. – Chris W Feb 17 '15 at 21:59
• @ChrisW, you are correct. My testing was flawed somehow. However, I discovered this will detect single-part polygons that have a hole, !Shape!.boundary().partCount >1. – klewis Sep 12 '16 at 17:37