Minimum polygon angle

07-08-2018 11:04 PM
New Contributor III

I would like to have an information about the minimum angle in every polygon in my database. Is there a way to evaluate it automatically? I need this information to find polygons which have very sharp angles, which might indicate that those polygons have to be corrected. some example of the polygon which I am looking for is presented in the attached image.

0 Kudos
1 Reply
MVP Esteemed Contributor

If memory serves... but you will have to change the 'angle = np.sum ….' line to 'angle = np.min….'

import numpy as np
import arcpy
def angles_poly(a, inside=True, in_deg=True):
    """Sequential angles from a poly* shape
    a = a.getPart()
    a =np.asarray([[i.X, i.Y] for j in a for i in j])
    if len(a) < 2:
        return None
    elif len(a) == 2:  # **** check
        ba = a[1] - a[0]
        return np.arctan2(*ba[::-1])
        angles = []
        if np.allclose(a[0], a[-1]):  # closed loop
            a = a[:-1]
            r = (-1,) + tuple(range(len(a))) + (0,)
            r = tuple(range(len(a)))
        for i in range(len(r)-2):
            p0, p1, p2 = a[r[i]], a[r[i+1]], a[r[i+2]]
            ba = p1 - p0
            bc = p1 - p2
            cr = np.cross(ba, bc)
            dt =, bc)
            ang = np.arctan2(np.linalg.norm(cr), dt)
    if in_deg:
        angles = np.degrees(angles)
    angle = np.sum(angles)  # ---- change to np.min
    return angle

It is a '*.cal' file so the __esri_field_calculator_splitter__ line should split everything into the code block and expression line when you load it.

NOTE... haven't test this in a while