I am having an issue when attempting to export to a TIFF in arcmap, using ArcPy in Python.
The full process I have scripted is as follows:
- Add rasters to a raster catalog
- panning to the raster data in the catalog layer in arcmap
- Exporting the result to a tiff
The above process loops through a total of 44 different raster catalogs, exporting each raster output to a different tiff name.
The odd thing is sometimes the error does not arise, other times I receive this error:
- AttributeError: PageLayoutObject: Error in executing ExportToTIFF
A shortened version of the script is as follows:
# create geodatabase
arcpy.CreateFileGDB_management(outpath, "RasCat.gdb")
# set projection information for raster catalog
prjfile = BNG
# set counter to 0
count = 1
# count raster files
total = len(RASTERF) # This is a table with all the raster names
for catalog in RASTERF:
# output raster catalog
outrascatp = os.path.join(gdbp,catalog)
# create FGDB unmanaged raster catalog
arcpy.CreateRasterCatalog_management(gdbp, catalog, prjfile, raster_management_type='UNMANAGED')
# loop through tiles in 'tilestoadd' list
for tile in tilestoadd:
# tile tif file path
tile1locp = os.path.join(outpath,tile[0],catalog+'.tif')
tile2locp = os.path.join(outpath,tile[1],catalog+'.tif')
tile3locp = os.path.join(outpath,tile[2],catalog+'.tif')
tile4locp = os.path.join(outpath,tile[3],catalog+'.tif')
# Load raster catalog arcpy.RasterToGeodatabase_conversion(tile1locp+';'+tile2locp+';'+tile3locp+';'+tile4locp,outrascatp)
count += 1
# CREATE 20x20 MOSAICED TIFFS USING ARC FOR EACH RASTER CATALOG
# sheet mxd path
mxdtypemxdp = os.path.join(newREPMATp,'TILE.mxd')
# duplicate sheet mxd path
mxdtypemxdp2 = os.path.join(newREPMATp,'TILE_copy.mxd')
# for every present 20x20 combination do the following
for product in AOIs:
# mosaiced tiffs path
mostifp = newREPMATp + '\\MOSTIFFS\\' + product
*# Photoshop tiffs path
PSp = os.path.join(newREPMATp,'PSTIFFS',product)
# check if file path does not exist if not create file path
# link to Photoshop
psApp = Dispatch('Photoshop.Application')
# run Photoshop in the background
psApp.Visible = False
# set the options for exporting in photoshop
options = Dispatch('Photoshop.TiffSaveOptions')
# ps_appLZWTIFFCompression
options.ImageCompression = 2
# no layers
options.Layers = False*
# the location of the AOI shapefile
AOIfcp = os.path.join(outpath,'AOI',product+'.shp')
# set 'AOItile' as an arcGIS layer
AOI = arcpy.mapping.Layer(AOIfcp)
# for every catalog in the geodatabase
for dataf in RASTERF:
# set mxd connection (SHEET)
mxd = arcpy.mapping.MapDocument(mxdtypemxdp)
# set data frame
df = arcpy.mapping.ListDataFrames(mxd, "SHEET DATA")[0]
# get first layer in mxd
lyrF = arcpy.mapping.ListLayers(mxd,'*',df)[0]
# replace 'lyrF' data source
lyrF.replaceDataSource(gdbp,"FILEGDB_WORKSPACE",dataf,False)
# add 'AOItile' to mxd
arcpy.mapping.AddLayer(df, AOI, 'BOTTOM')
# pan to 20x20 tile AOI extent
df.panToExtent(AOI.getSelectedExtent())
# save as 'mxdtypemxdp2' (SHEET_copy)
mxd.saveACopy(mxdtypemxdp2)
# delete reference to original mxd, df, lyrF
del mxd
del df
del lyrF
# set new mxd connection
mxd = arcpy.mapping.MapDocument(mxdtypemxdp2)
# set data frame
df = arcpy.mapping.ListDataFrames(mxd, "SHEET DATA")[0]
# change document view to page layout
mxd.activeView = ("PAGE_LAYOUT")
# refresh table of contents
arcpy.RefreshTOC()
# refresh the view
arcpy.RefreshActiveView()
tiff = mostifp + '\\' + dataf+'.tif'
# export mxd to TIFF format
arcpy.mapping.ExportToTIFF(mxd,tiff,"PAGE_LAYOUT",resolution="660.4")
### THIS IS WHERE THE ERROR SEEMS TO OCCUR ####
del mxd, df
I have looked up the error on many forums, one of them pointed towards the file path: Does arcpy have an issue with directory names starting with a number?
I was previously using the os module to control path concatenation e.g
os.path.join(path1,path2)
but have reverted it to the above script to rule this possibility out e.g
path1 + '\\' + path2
.
One more thing, I have run the script within ArcMap, ArcCatalog and Workflow Manager with the same result.
Software versions: ArcGIS 10.2.2 Python 2.7
-
You mention you've encountered the error in ArcMap, ArcCatalog and WFM. Is this all on the same machine? Or are you getting this behavior on multiple machines? Have you by any chance also had this error with a manual tiff export?Dan_h_b– Dan_h_b2014年10月16日 10:37:50 +00:00Commented Oct 16, 2014 at 10:37
-
No I (or other users) recieve this error on different machines, I can manually export to Tiff from arcmap with no problems, I even tried manually opening and exporting from the mxd to TIFF once the error had arisen and can still successfully export.Leroy– Leroy2014年10月16日 11:24:13 +00:00Commented Oct 16, 2014 at 11:24
1 Answer 1
I think I may have solved it myself..
I was opening a template mxd, saving it as a new mxd, doing some changes then exporting to a tiff from the new mxd. Each time the loop run it was using the same template mxd, It is possible that at some point the reference to the mxd variable became locked (and did not update) so arc could not export the data from the new mxd to a tiff?
To get round this I did all the required changes and exported from the template mxd (removing the need to create a new the mxd or change the mxd variable). This seemed to solve the issue!