Arcpy workflow fails to execute

134
3
09-20-2018 06:45 AM
Stephen_A_Oladayiye
New Contributor

I have a python workflow created to read image files (in folders) and simply write the raster attributes to a text file. The script runs up to line 7, writes out the header, and aborts without reporting any error. I can't figure out what issues are hidden in lines 8 - 20. I use 10.3.1.

import arcpy, sys, os
from arcpy import env
env.workspace = "Z:\..."
root_folder = env.workspace
out_file = open("Z:\....txt","a")
#Next line creates an header to properly identify the properties.
out_file.write("BANDCOUNT"+'\t'+"CATALOGPATH"+'\t'+"COMPRESSIONTYPE"+'\t'+"EXTENT"+'\t'+"FORMAT"+'\t'+"HASRAT"+'\t'+"HEIGHT"+'\t'+"MAXIMUM"+'\t'+"MINIMUM"+'\t'+"ISINTEGER"+'\t'+"MEANCELLHEIGHT"+'\t'+"MEANCELLWIDTH"+'\t'+"NAME"+'\t'+"NODATAVALUE"+'\t'+"PATH"+'\t'+"PIXELTYPE"+'\t'+"SPATIALREFERENCE"+'\t'+"STANDARDDEVIATION"+'\t'+"UNCOMPRESSEDSIZE"+'\t'+"WIDTH"+'\n')
ext = [".bil",".bip",".bsq",".bmp",".flv",".img",".dt0",".dt1",".dt2",".ecw",".img",".raw",".grd",".gif",".hgt",".jpg",".jpeg",".jpc",".jpe",".sid",".view",".png",".tif",".tiff"]
for root, dirs, files in os.walk(root_folder):
    for filename in files:
        if filename.endswith(tuple(ext)):
            try:
                raspath = root + "\\" + filename
                ras = arcpy.Raster(raspath)
                rasDescription = (str(ras.bandCount) +'\t'+ str(ras.catalogPath)+'\t' +str(ras.compressionType)+'\t'+ str(ras.extent)+'\t'+'\t'+'\t'+'\t'+str(ras.format)+'\t'+str(ras.hasRAT)+'\t'+str(ras.height)+'\t'+str(ras.maximum)+'\t'+ str(ras.minimum)+'\t'+str(ras.isInteger)+'\t'+ str(ras.meanCellHeight)+'\t'+str(ras.meanCellWidth)+'\t'+str(ras.name)+'\t'+str(ras.noDataValue)+'\t'+str(ras.path)+'\t'+str(ras.pixelType)+'\t'+str(ras.spatialReference)+'\t'+str(ras.standardDeviation)+'\t'+str(ras.uncompressedSize)+'\t'+str(ras.width))
                out_file.write(rasDescription+'\n')
            except RuntimeError:
                continue 
out_file.flush()
out_file.close()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
3 Replies
JoshuaBixby
MVP Esteemed Contributor

Sharing with Python

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

lacking data to test with, have you tried throwing a print statement in before writing the file in the try-except block.

better still, maybe get rid of the try-except block so you get an error message that might be useful

0 Kudos
DarrenWiens2
MVP Honored Contributor

Either use raw strings (r'Z:\...') or forward slashes in your paths. I'm guessing nothing triggers the if statement, or possibly nothing is read into walk, at all, because the paths are incorrect.

0 Kudos