Copy Raster Error

1878
3
11-11-2013 03:21 PM
MargaretWooten
New Contributor
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")
Tags (2)
0 Kudos
3 Replies
MargaretWooten
New Contributor
UPDATE: Code randomly started working and then stopped again when it was almost done when I got the same error. I will just convert the last few .dat files by hand, but I would like to know possible causes for the weird behavior so that I can better understand python/arc. The only thing I changed was erasing the extra parameters in the copy raster call (only left input raster and output raster).  Anyone?
0 Kudos
MargaretWooten
New Contributor
Last addendum:

Tried Copy Raster on the rest of my .dat files in ArcMap and it is no longer working again. Also tried using Resample in Management which also failed. I'm not sure what's going on or what is causing these operations to fail, but I've tried everything I can think of to no avail. Anyone have any clue as to what might be going on?

Looks like I'm going over to ENVI to see if I can't convert these files to tiffs.

Thanks for your time.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Are you sure these .dat files are actually rasters?  (I have never used/seen a .dat file extension for a raster)

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


From http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000094000000

CopyRaster_management (in_raster, out_rasterdataset, {config_keyword}, {background_value}, {nodata_value}, {onebit_to_eightbit}, {colormap_to_RGB}, {pixel_type}, {scale_pixel_value}, {RGB_to_Colormap})

You are passing in the .dat as the first parameter (which is expecting a raster) but I suspect you are not doing that.  Maybe I don't understand what are the .dat files.
0 Kudos