Select to view content in your preferred language

Python Map Algebra error: Failed to execute (output)

2525
1
07-08-2015 10:49 PM
KarolinaKorzeniowska
Deactivated User

Dear Jake,

I have a problem with another equation where I am using minimum and maximum value from my data. I am using the following code:

RI_tif = "C:\\output.tif"

# Process: Get Raster Properties

arcpy.GetRasterProperties_management(v6_tif, "MINIMUM", "")

# Process: Get Raster Properties (2)

arcpy.GetRasterProperties_management(v6_tif, "MAXIMUM", "")

# Process: Raster Calculator (3)

outSubt = (Raster("6.tif")-(float(Property))/((float(Property (2))-(float(Property))

outSubt.save("C:\\output_tif")

I have an error in the last line "Failed to execute (output)." I think that the problem is with the min, max values which I am using in the equation. Probably I implemented them in a wrong way. However, I could not find at ESRI website some example how to do this. Do you have maybe idea how to implement these values in python?

Thanks in advance.

Tags (1)
0 Kudos
1 Reply
curtvprice
MVP Esteemed Contributor

Here's a formatted version of your code:

RI_tif = "C:\\output.tif"

# Process: Get Raster Properties
arcpy.GetRasterProperties_management(v6_tif, "MINIMUM", "")

# Process: Get Raster Properties (2)
arcpy.GetRasterProperties_management(v6_tif, "MAXIMUM", "")

# Process: Raster Calculator (3)
outSubt = (Raster("6.tif")-(float(Property))/((float(Property (2))-(float(Property))
outSubt.save("C:\\output_tif")

I don't think you're translating very well from the ModelBuilder export.  That can be a challenge, but that's how we learn sometimes.

The following would work better.  Note how I'm not working on the root folder of your C drive but one folder beneath it (usually a good idea for many reasons).

import arcpy
from arcpy.sa import *
from arcpy import env
env.workspace = "C:\\workspace"
input_tif = "v6.tif" # in c:\workspace
gridmin = float(arcpy.GetRasterProperties_management(input_tif, "MINIMIMUM"))
gridmax = float(arcpy.GetRasterProperties_management(input_tif, "MAXIMUM"))
outRaster = Raster(input_tif) - (gridmin / (gridmax - gridmin))
outRaster.save("output.tif")
0 Kudos