mwooten3

Copy Raster Error

Discussion created by mwooten3 on Nov 11, 2013
Latest reply on Nov 12, 2013 by jamesfreddyc
I'm using CopyRaster to convert a bunch of .dat files to .tif in python, but keep getting the following error:

Traceback (most recent call last):
File "C:\Users\mwooten3\Desktop\Projects\Terrestrial Ecology\Code\convert_dat2tif.py", line 27, in <module>
arcpy.CopyRaster_management(indat, outtif, "", "", "256", "NONE", "NONE", "", "NONE", "NONE")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 11034, in CopyRaster
raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (CopyRaster).

It's a short code modified from the one exported from ArcMap Modelbuilder, meant to iterate through a set of folders and convert the .dat files to .tif. The process on one file works in ArcMap, but not in Python. I changed the paths to make sure there were no spaces, and also tried saving to a short filename. I even tried using the original script generated from modelbuilder without making changes and got the same error. I keep looking for careless errors but can't seem to find anything. Any ideas what is wrong or suggestions? My code is posted below.

Many thanks,
Maggie
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# convert_dat2tif.py
# Created on: 2013-11-11 14:07:05.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
import glob
import os


path = 'D:\\MaggieData\\TE_Data\\Graphics\\'
datpath = path + 'Dats\\'
tifpath = path + 'Tifs\\'


for folder in glob.iglob(datpath + '*'): # dat folder contains folders classified data, extracted, etc.
    type_ = os.path.basename(folder) # type_refers to classified data, extracted, stack, total, or percent
    for indat in glob.iglob(folder + '\\*.dat'): # go through all dat files in type_ folders, set them equal to paths or indat files that need to be converted to tif
        outtif = tifpath + type_ + '\\' + os.path.basename(indat)[:-3] + 'tif' # output is tiffs folder // type_ name // + suffix of indat file (minus the dat extension) plus a .tif extension
        print 'Processing %s ' %(indat)

        # Process: Copy Raster-- does nothing but convert to tiff
        arcpy.CopyRaster_management(indat, outtif, "", "", "256", "NONE", "NONE", "", "NONE", "NONE")

Outcomes