I need to export a series of maps along a predefined grid across a state. I'm trying to automate the process with arcpy. Right now I manually choose to export a TIFF file at 500 dpi resolution, 8-bit palette, no compression, and background color set to “no color”. The built in arcpy.mapping.ExportToTIFF code does not support “no color" as a background option.

I'm trying to use arcpy.mapping.ExportToPNG but I can't seem to get the arguments right. I think the problem is with my data frame, df_export_width, or df_export_height arguments. I tried to set up a code following this example, but the code to generate height and width always came back as 0, and didn't work.

My code is below, set up for the state of Colorado. I'm using ArcGIS 10.3.1. Any thoughts?

Import arcpy

#build list of all gridsquares
del grid[0]
#load predefined grid for Colorado


for g in grid:
    mxd = arcpy.mapping.MapDocument('CURRENT')
    export= "C:\Data\CO"+str(g)+".png"
    df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
    arcpy.mapping.ExportToPNG(mxd,export,df,,,resolution,"TRUE","8-BIT_PALETTE","255, 255, 255","255, 255, 255")

For one, the forming of your file pathname is incorrect - the backslash in Python denotes an escape sequence (followed by another ASCII char), so for example, the following code....

print "the backslash is an escape sequence in Python:"
print "C:\data\co\n"
print "this raw string notation is one way to handle it:"
print r"C:\data\co"

...produces this output:

the backslash is an escape sequence in Python:

this raw string notation is one way to handle it:

See details at Python docs: https://docs.python.org/2.0/ref/strings.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.