Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Simple Map Algebra Looped Through Rasters in a Directory

$
0
0
I think I must be missing something pretty basic here because this isn't a complex operation. That said, I've always had difficulty with Map Algebra in scripts. I'd like to apply a constant multiplier to all of the rasters in a directory. They are in . tif format. When I run the separately in Python I get this error:

Traceback (most recent call last):
File "C:\Users\Derek\Desktop\multiply rasters.py", line 15, in <module>
for raster_image in raster_list:
TypeError: 'NoneType' object is not iterable

When I run in it piecemeal in the Python window I get this error:

Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'

I don't think that the raster is being recognized as an input during the multiplication. I also don't know what else to try. Here is the code:

import arcpy,os,sys,string
from arcpy import env
from arcpy.sa import *


arcpy.CheckOutExtension("Spatial")


input_folder = r'C:\Users\Derek\Desktop\ToJordan\ToJordan\landsat'
arcpy.env.worspace = input_folder


#Set reflectance constant
const = 0.0001


# Get raster list, loop through and multiply be constant
raster_list = arcpy.ListRasters()
for raster_image in raster_list:
print raster_image
rast_mult = Raster(raster_image) * const
raster_mult_out = input_folder + os.sep + raster_image + "_reflect.img"
rast_mult.save(raster_mult_out)
print raster_image + " Finished"

I hope someone can help. Thanks!

Viewing all articles
Browse latest Browse all 2485

Trending Articles