I have created a series of roated Grid Index Features. I wrote an ArcPy script to generate the grids and adds a rotation value field. My plan is to run another ArcPy script that zooms to each grid and exports a PDF. I am using ArcPy instead of Data Driven Pages because of some additional requirements ArcPy fulfills.
The problem I am experiencing is that I'm getting unexpected zoom results when the dataframe is rotated. In the example below, I rotate the dataframe 47 degrees to "straighten" the grid. When I use Zoom to Layer or Zoom to Selected Feature it doesn't provide a tight zoom around the polygon. If the dataframe is not rotated, the zoom works as expected. Rotating the dataframe causes the view to zoom out too far.
Interestingly, when using Data Driven Pages and providing the rotation field, the zoom behaves as I expect. Below are some examples of this phenomenon. How can I get the results of third image (the Data Driven method) using ArcPy?
EDIT 1:
The ArcPy code is simply using the Grid Index Features Geoprocessor to build the grids. Where my code comes into play is when I rotate that geometry. I write the results of the following function to the geometry of each grid with an Update Cursor. The code I'm using for calculating the rotation is this:
def RotateAxis(AnchorX,AnchorY,inputx,inputy, rAngle):
x = inputx - AnchorX
y = inputy - AnchorY
resultx = ((x * math.cos(rAngle)) + (y * math.sin(rAngle))) + AnchorX
resulty = ((x * math.sin(rAngle)) - (y * math.cos(rAngle))) + AnchorY
return (resultx,resulty)
However, even when I manually rotate the grid in ArcMap with the rotate tool, it provides the same results as the code.
Furthermore, it seems like the actual extent doesn't wrap around these polygons. When you use the edit tool and click on the geometry you can see the outline of the extent. I've included another screenshot of this. (I did thicken the outline in the screenshot so it would show up better, its really faint in ArcMap.) I suspect this extent may have something to do with it, but again, I get the same issue even with manually rotated geometry.
I have not found a way to create geometry that is rotated at the time of its creation. Grid Index Features only creates unrotated geometry and thus my work around in using Arcpy to rotate after the fact.
Edit 2 :
Just to add further clarification, all of the grids are different sizes and rotations, so defining a set scale and moving the dataframe extent will not work. The aspect ratio of them however is consistent.
Zoom to Layer - No Dataframe Rotation:
Zoom to Layer - 47 Degree Dataframe Rotation:
Using Data Driven Pages using the Rotation Field:
Rotated Dataframe (317 degrees) with Polygon Extent Visible: