Select to view content in your preferred language

Minimum polygon angle

931
1
07-08-2018 11:04 PM
KK2
by
Occasional Contributor

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
DanPatterson_Retired
MVP Emeritus

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])
    else:
        angles = []
        if np.allclose(a[0], a[-1]):  # closed loop
            a = a[:-1]
            r = (-1,) + tuple(range(len(a))) + (0,)
        else:
            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 = np.dot(ba, bc)
            ang = np.arctan2(np.linalg.norm(cr), dt)
            angles.append(ang)
    if in_deg:
        angles = np.degrees(angles)
    angle = np.sum(angles)  # ---- change to np.min
    return angle
__esri_field_calculator_splitter__
angles_poly(!Shape!)

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