Can Arcpy even do this?

Discussion created by Sycosys on Nov 15, 2011
Latest reply on Nov 15, 2011 by JScheirer-esristaff
So I have this wonderful bit of code which pans through a reference grid and exports imagery with worldfile but it is only accurate if my reference grid is set to the exact pixel ratio as the display view.

if I create a square grid for instance the problem is that the exported images are misaligned in the vertical. I can get around this by calibrating the script and grid to the exact pixel dimensions of the screen, mine happens to be 1638x880..

is there a way around this vertical stacking error so that i may give this code to anyone and have it perform as expected?

I can provide screenshots of the error if you need to see it.

import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\Users\atimpson\Desktop\Work\GridExportTesting"

mxd = mapping.MapDocument("Current")

fc = "Grid"
count = str(arcpy.GetCount_management(fc))

x = 1

while x < int(count) + 1:
    rows = arcpy.SearchCursor(fc, "ID = " + str(x))
    for row in rows:
        xmin, ymin, xmax, ymax  = row.shape.extent.XMin, row.shape.extent.YMin, row.shape.extent.XMax, row.shape.extent.YMax
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        newExtent = df.extent
        newExtent.XMin, newExtent.YMin, newExtent.XMax, newExtent.YMax = xmin, ymin, xmax, ymax
        df.extent = newExtent
        mapping.ExportToJPEG(mxd, r"C:\temp\python\JPEG_" + str(x) + ".jpg", df, df_export_width=1638, df_export_height=880, world_file=True)
        print('Exported image' )
        print(x, 'of', count)
    x += 1

print("Export Complete")