[GIS] Rotating and moving polygons to different angles using ModelBuilder/ArcPy

arcgis-10.0arcpymodelbuilder

I have a few thousand polygons (all square) that I need to rotate to various angles that are in the attribute table, and then move so that each polygon gets moved 3/4 up from the original centroid, which I have as a point shapefile. It would look like this:

enter image description here

Ideally, I would like to build a model for this process so I can repeat it in the future. I am not all that comfortable with Python, but if that is the only way to get the desired result, I will be willing to try it. I have arcGIS 10 with an ArcView license.

Best Answer

I did this using a python script and numpy to help me with the matrix algebra for rotation and translation of every point.

Here is the key function. You have to unpack the vertices from the feature, transform and reassemble the feature.


import arcpy
import math
import numpy

def trans(px,py,tx,ty,angle):
    '''
    Rotate a point px,py around origin 0,0
    Sense clockwise or anticlockwise
      (default clockwise)
    Transform to plot coords tx,ty
    Does not handle z or m values
    '''
    # angle in degrees +/- 360
    th = math.radians(angle) # theta (radians)
    if sense == 'anticlock':
        matrix = [[math.cos(th),-math.sin(th),tx],
                  [ math.sin(th), math.cos(th),ty],
                  [0,0,1]]
    elif sense == 'clock':
        matrix = [[ math.cos(th),math.sin(th),tx],
                  [-math.sin(th),math.cos(th),ty],
                  [0,0,1]]
    else:
        raise Exception, "sense error in DrawPlotR"
    a = numpy.array(matrix)
    b = numpy.array([px,py,1])
    c = numpy.dot(a,b)
    return (c[0],c[1])

Related Question