Hust did a little test to see if it would work and I get a result with this code (it will add fields to the input featureclass, so it's better to run this on a copy of your data):
def main():
import arcpy
fc = r'C:\GeoNet\ShortestEdge\data.gdb\polygons'
generalize = 0.1
fc_out = r'C:\GeoNet\ShortestEdge\data.gdb\lines_v01'
fld_len1 = "ShortestLength1"
fld_from_pnt1 = "FromPoint1"
fld_to_pnt1 = "ToPoint1"
fld_len2 = "ShortestLength2"
fld_from_pnt2 = "FromPoint2"
fld_to_pnt2 = "ToPoint2"
AddField(fc, fld_len1, "DOUBLE", None)
AddField(fc, fld_from_pnt1, "TEXT", 100)
AddField(fc, fld_to_pnt1, "TEXT", 100)
AddField(fc, fld_len2, "DOUBLE", None)
AddField(fc, fld_from_pnt2, "TEXT", 100)
AddField(fc, fld_to_pnt2, "TEXT", 100)
feats = []
flds = ('SHAPE@', fld_len1, fld_from_pnt1, fld_to_pnt1,
fld_len2, fld_from_pnt2, fld_to_pnt2)
with arcpy.da.UpdateCursor(fc, flds) as curs:
for row in curs:
polygon = row[0]
length1, from_pnt1, to_pnt1, line1 = GetShortestEdgeData(polygon)
feats.append(line1)
polygon2 = polygon.generalize(generalize)
length2, from_pnt2, to_pnt2, line2 = GetShortestEdgeData(polygon2)
feats.append(line2)
curs.updateRow((polygon, length1, from_pnt1, to_pnt1, length2, from_pnt2, to_pnt2, ))
arcpy.CopyFeatures_management(feats, fc_out)
def AddField(fc, fld_name, fld_type, fld_length):
if len(arcpy.ListFields(fc, fld_name)) == 0:
arcpy.AddField_management(fc, fld_name, fld_type, None, None, fld_length)
def GetShortestEdgeData(polygon):
min_length = 99999
prev_pnt = None
side = None
sr = polygon.spatialReference
for part in polygon:
for pnt in part:
if prev_pnt is None:
pass
else:
if pnt is None:
pass
else:
length = GetDist(pnt, prev_pnt)
if length < min_length:
min_length = length
line = arcpy.Polyline(arcpy.Array([prev_pnt, pnt]), sr)
prev_pnt = pnt
length = line.length
from_pnt = line.firstPoint
to_pnt = line.lastPoint
return length, str(from_pnt), str(to_pnt), line
def GetDist(pnt1, pnt2):
import math
return math.hypot(pnt2.X - pnt1.X, pnt2.Y - pnt1.Y)
if __name__ == '__main__':
main()
It will do this on the input polygon and a generalized polygon (set the variable generalize on line 5 with a proper value):
It also creates an output featureclass with the shortest edges.