3

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?

asked Jun 6, 2013 at 15:22

2 Answers 2

5

How about this snippet? From PySAL source code.

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[0]
 for bx, by in vertices[1:]:
 area += ax * by - ay * bx
 ax, ay = bx, by
 bx, by = vertices[0]
 area += ax * by - ay * bx
 return area < 0.0
answered Jun 6, 2013 at 15:41
1

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.

answered Jun 6, 2013 at 19:20
2
  • 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. Commented Feb 17, 2015 at 21:59
  • 1
    @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. Commented Sep 12, 2016 at 17:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.