When I use the Basic Polygon labeling in ArcGIS Pro it will rotate the label (if it doesn't fit, so not always):
However, after publishing the map as a web map, the label rotation disappears:
If you label on the "center line" you will be able to obtain rotated labels, although some funky stuff is going on:
The rotation was based on the "center line" of the polygon. This was achieved by using first:
Minimum Bounding Geometry—Help | ArcGIS Desktop (with the RECTANGLE_BY_AREA option) and then running a snippet of code to create the lines:
def main():
import arcpy
import os
fc_in = r'C:\GeoNet\ParcelsMinArea\test.gdb\Parcels_MinBoundAreaRect'
fc_out = r'C:\GeoNet\ParcelsMinArea\test.gdb\Parcels_MinBoundAreaRect_lines2'
fld_lbl = 'ParcelID'
sr = arcpy.Describe(fc_in).spatialReference
ws, fc_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(ws, fc_name, "POLYLINE", None, None, None, sr)
arcpy.AddField_management(fc_out, fld_lbl, "TEXT", None, None, 20)
with arcpy.da.InsertCursor(fc_out, ('SHAPE@', fld_lbl)) as curs_out:
with arcpy.da.SearchCursor(fc_in, ('SHAPE@', fld_lbl)) as curs:
for row in curs:
polygon = row[0]
parcelID = row[1]
polyline = GetCenterLineFromRectangle(polygon)
curs_out.insertRow((polyline, parcelID, ))
def GetCenterLineFromRectangle(polygon):
lst_pnts = []
for part in polygon:
for pnt in part:
lst_pnts.append(pnt)
mid_pnts = []
for i in range(len(lst_pnts)-1):
pnt_i = lst_pnts[i]
pnt_n = lst_pnts[i+1]
mid_pnt = arcpy.Point((pnt_i.X + pnt_n.X)/2.0,(pnt_i.Y + pnt_n.Y)/2.0)
mid_pnts.append(mid_pnt)
sr = polygon.spatialReference
line1 = arcpy.Polyline(arcpy.Array([mid_pnts[0], mid_pnts[2]]), sr)
line2 = arcpy.Polyline(arcpy.Array([mid_pnts[1], mid_pnts[3]]), sr)
if line1.length > line2.length:
return line1
else:
return line2
if __name__ == '__main__':
main()
Labeling is based on the lines, and a transparent color is used for the lines (using on the line alignment).