Select to view content in your preferred language

Multiplying Rasters Problem

2019
1
Jump to solution
09-25-2012 10:06 AM
RobinCheskin
Occasional Contributor
I am having a very frustrating problem with using the Times() function to multiply two rasters together. One of the rasters is created by ReclassByTable, and for some odd reason its output is not recognized as a raster (see red):
#Import modules
import os
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

#Set local variables
wks = arcpy.GetParameterAsText(0) # input workspace
inRaster1 = arcpy.GetParameterAsText(1) # input raster layer
inRaster2 = arcpy.GetParameterAsText(2) # input raster layer
inRaster3 = arcpy.GetParameterAsText(3) # input raster layer
inRaster4 = arcpy.GetParameterAsText(4) # input raster layer
inRaster5 = arcpy.GetParameterAsText(5) # input raster layer
inRaster6 = arcpy.GetParameterAsText(6) # input raster layer
inRaster7 = arcpy.GetParameterAsText(7) # input raster layer
inRaster8 = arcpy.GetParameterAsText(8) # input raster layer
inRaster9 = arcpy.GetParameterAsText(9) # input raster layer
inRaster10 = arcpy.GetParameterAsText(10) # input raster layer
env.workspace = wks
cellSize = 100
outExtent = Extent(871599.89, 982834.44, 912502.09, 1070920.9)
ReMapTable_dbf = "P:\\Crime_Analysis\\Testing_Training\\RiskTerrainModeling\\RobinAdrienne\\AggAssaults\\ReMapTable.dbf"

#Multiply Raster by a constant with CreateConstantRaster
constantValue1 = arcpy.GetParameterAsText(11) # input weight value
outConstRaster1 = CreateConstantRaster(constantValue1, "FLOAT", cellSize, outExtent)
outReclass1 = ReclassByTable(inRaster1, ReMapTable_dbf , "FROM", "TO", "VALUE", "DATA")
outTimes1 = Raster(outReclass1)* outConstRaster1
outRaster1 = "Wt_" + os.path.basename(inRaster1)
outTimes1.save(outRaster1) # save raster


I keep getting the same error:
[PHP]outTimes1 = Raster(outReclass1)* outConstRaster1
TypeError: expected a raster or layer name
[/PHP]

I already checked that the ReMap Table was working b/c when I save outReclass1 it gives me a raster where all the values are equal to 1 (which is what I want). In previous versions of the script, I had used a model builder to create the raster where all values are equal to 1 and used the times function successfully with outConstRaster1. However, I want to use the ReclassByTable in a python script because it is faster than model builder, but it is not working for me.

I also tried making outReclass1 a raster layer for the times function, but that did not work either.

Please help!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobinCheskin
Occasional Contributor
Found a solution. Apparently I did not need to designate outReclass1 a raster, and the "*" operator must be next to outReclass1 with no spaces, which seems very silly to me.

#Multiply Raster by a constant with CreateConstantRaster
constantValue1 = arcpy.GetParameterAsText(11) # input weight value
outConstRaster1 = CreateConstantRaster(constantValue1, "FLOAT", cellSize, outExtent)
outReclass1 = ReclassByTable(inRaster1, ReMapTable_dbf , "FROM", "TO", "VALUE", "DATA")
outTimes1 = outReclass1* outConstRaster1
outRaster1 = "Wt_" + os.path.basename(inRaster1)
outTimes1.save(outRaster1) # save raster

View solution in original post

0 Kudos
1 Reply
RobinCheskin
Occasional Contributor
Found a solution. Apparently I did not need to designate outReclass1 a raster, and the "*" operator must be next to outReclass1 with no spaces, which seems very silly to me.

#Multiply Raster by a constant with CreateConstantRaster
constantValue1 = arcpy.GetParameterAsText(11) # input weight value
outConstRaster1 = CreateConstantRaster(constantValue1, "FLOAT", cellSize, outExtent)
outReclass1 = ReclassByTable(inRaster1, ReMapTable_dbf , "FROM", "TO", "VALUE", "DATA")
outTimes1 = outReclass1* outConstRaster1
outRaster1 = "Wt_" + os.path.basename(inRaster1)
outTimes1.save(outRaster1) # save raster
0 Kudos