michelle.totman

Converting an arcobject to a number

Discussion created by michelle.totman on Sep 20, 2011
Latest reply on Sep 20, 2011 by lpinner
I've been stuck on this one for a while. Below is the script I want to be able to run, but the numbers ArcGIS is providing for me are actually imported to Python as arcobjects, so I cannot run the calculation at the end of my script. Can anyone tell me how to convert these arcobjects into numbers so I can use them in calculations? 

import arcpy
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
#Establish Environmental Settings
arcpy.env.workspace = "C:/GIS_Rainier/Rainier.gdb"
arcpy.env.overwriteOutput = True
#Establish Input Raster
inRaster = "DEM10"
#Get Raster Properties
STD = arcpy.GetRasterProperties_management(inRaster, "STD")
Mean = arcpy.GetRasterProperties_management(inRaster, "MEAN")
#Check Data Values and Types
print Mean
print type(Mean)
print STD
print type(STD)
#Calculate z-score
outRaster = (inRaster - Mean)/STD

I also created the function as a model in ArcGIS using raster calculator, and it works when run as a model. If I export my model as a python script, I get what is copy and pasted below. This does not run properly.


# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Script arguments
Input_raster = arcpy.GetParameterAsText(0)

rastercalc = arcpy.GetParameterAsText(1)
if rastercalc == '#' or not rastercalc:
    rastercalc = "C:\\GIS_Rainier\\Rainier.gdb\\rastercalc" # provide a default value if unspecified

# Local variables:
Mean = Input_raster
St_Dev = Input_raster

# Process: Get Raster Properties
arcpy.GetRasterProperties_management(Input_raster, "MEAN")

# Process: Get Raster Properties (2)
arcpy.GetRasterProperties_management(Input_raster, "STD")

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("(\"%Input raster%\" - %Mean%) / %St Dev rastercalc)


I have a working model to do these calculations, so there is no urgency in getting an answer, I'd just be thrilled to learn the solution to my puzzle.

Thanks,
Michelle

Outcomes