0

This may seem trivial, but I can seem to track the error and I am very very new to Python, though not to programming. From reading around on the internet for a bit, I think my problem is that .dat ENVI image file isn't being read as a "describe object". But how do I get it to be read as such? I probably need it to read the header info too, any solutions?

Here is my code:

import arcpy #make sure you run the python associated with ArcGIS
import os

filepath = 'filepath'
filename = 'filename'
band_names = range(1,225)

# Path creation
in_folder = filepath + os.sep + 'ENVI'
out_folder = filepath + os.sep + 'GeoTIFF' # preferably an empty folder

# input multiband raster
in_ENVI = in_folder + filename '.dat'
in_raster = raster(in_ENVI)
index = 0

# get raster information specific to each band
desc = arcpy.Describe(in_raster)

################### THIS IS WHERE I GET THE ERROR ##################
Runtime error 
Traceback (most recent call last):
  File "<string>", line 23, in <module>
NameError: name 'raster' is not defined
################### SCRIPT TERMINATED ##############################

for band in desc.children:
    print band
    bandName = band.name
    band_path = os.path.join(in_raster, bandName)
    dest_path = os.path.join(out_folder, filename '_' + band_names(index) + '.tif')
    arcpy.CopyRaster_management(band_path, dest_path, "", "", "", "NONE", "NONE", "")
    index = index + 1
user1481829
  • 23
  • 1
  • 4

1 Answers1

0

Ok so I actually figured it out myself. Here is the code I used. The error was actually not in arcpy.Describe() but in arcpy.CopyRaster_management because I didn't convert band_name[index] to a string.

dest_path = os.path.join(out_folder, filename + str(band_names[index]) + '.tif')
user1481829
  • 23
  • 1
  • 4