Select to view content in your preferred language

Rotate Polygon using Attribute

2470
3
05-07-2021 12:13 AM
Labels (1)
BruceBurwell1
Emerging Contributor

Good Morning

I am trying to rotate feature class with over 700 polygons based on the angle in an attribute? These polygons are all based on center points that were buffered and then run the create envelope tool. All the polygons now are oriented N/S. Any wok flows would be appreciated.

Thanks

Bruce Burwell

0 Kudos
3 Replies
anyry
by
Occasional Contributor

Hello, 

Try using arcpy, see the code below.

def rotation(rotatefield):
    def rotatepoint(point, pivotpoint, angle):
        angle_rad = -math.radians(angle)
        ox, oy = pivotpoint.X, pivotpoint.Y
        px, py = point.X, point.Y
        qx = ox + math.cos(angle_rad) * (px - ox) - math.sin(angle_rad) * (py - oy)
        qy = oy + math.sin(angle_rad) * (px - ox) + math.cos(angle_rad) * (py - oy)    
        return arcpy.Point(qx,qy)

    with arcpy.da.UpdateCursor("annotation_polygons",['SHAPE@', rotatefield]) as cursor:
        for row in cursor:
            polylist = []
            for part in row[0]:
                partlist = []
                for pnt in part:
                    if pnt is not None:
                        partlist.append(rotatepoint(pnt, arcpy.Point(row[0][0][0].X, row[0][0][0].Y), row[1])) 
                        polylist.append(partlist)
            row[0] = arcpy.Polygon(arcpy.Array(polylist))
            cursor.updateRow(row)
 

 

0 Kudos
DrVSSKiran
Frequent Contributor

Hi Anyry,

Here is the solution

Step 1: Polygon with Attribute Values. I have created a field name called "Angle" and manually keeping some values. (Refer Screenshot)

DrVSSKiran_0-1620386194137.png

Step 2: Go to the insert tab and click the new notebook

Step 3: Paste the script, which I have attached in mentioned in notepad and attached. (Refer Screenshot)

DrVSSKiran_1-1620386772715.png

Step 4: make changes in two placed feature class name and attribute field name. Refer screenshot.

DrVSSKiran_2-1620386912397.png

Step 5: Hit the Run button in a notebook 

DrVSSKiran_3-1620387146114.png

Step 6: Here is the output results

DrVSSKiran_4-1620387209425.png

Enjoy.....

 

by Anonymous User
Not applicable

This throws a NoneType is not iterable error.

0 Kudos