<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting an arcobject to a number in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/converting-an-arcobject-to-a-number/m-p/242147#M18828</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There's a few issues:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. You assign the mean &amp;amp; st_dev variables to a raster instead of assigning to the output of the GetRasterProperties tool.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. The GetRasterProperties tool returns a "Result" object which has a GetOutput method that you need to use to access the mean/std values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Your calculation has a few errors - no terminating quote, the text doesn't match any of the variables you set previously, and the "rastercalc" raster has no operator linking it to the rest of the expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code works, but you'll need to check the actual expression as I stuck a "+" operator in front of the&amp;nbsp; "rastercalc" raster so the expression would actually run, substitute it with whatever operator you require.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#...
# Process: Get Raster Properties
Mean = float(arcpy.GetRasterProperties_management(Input_raster, "MEAN").getOutput(0))

# Process: Get Raster Properties (2)
St_Dev = float(arcpy.GetRasterProperties_management(Input_raster, "STD").getOutput(0))

# Process: Raster Calculator
calc='("%s" - %s) / %s + "%s"'%(Input_raster,Mean,St_Dev,rastercalc)
result=arcpy.gp.RasterCalculator_sa(calc)
print result.GetMessages()
print result.GetOutput(0)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:08:13 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2021-12-11T12:08:13Z</dc:date>
    <item>
      <title>Converting an arcobject to a number</title>
      <link>https://community.esri.com/t5/python-questions/converting-an-arcobject-to-a-number/m-p/242146#M18827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Establish Environmental Settings&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "C:/GIS_Rainier/Rainier.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Establish Input Raster&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inRaster = "DEM10"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Get Raster Properties&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STD = arcpy.GetRasterProperties_management(inRaster, "STD")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mean = arcpy.GetRasterProperties_management(inRaster, "MEAN")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Check Data Values and Types&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print Mean&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print type(Mean)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print STD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print type(STD)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Calculate z-score&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outRaster = (inRaster - Mean)/STD&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_raster = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rastercalc = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if rastercalc == '#' or not rastercalc:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rastercalc = "C:\\GIS_Rainier\\Rainier.gdb\\rastercalc" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mean = Input_raster&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;St_Dev = Input_raster&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Get Raster Properties&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.GetRasterProperties_management(Input_raster, "MEAN")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Get Raster Properties (2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.GetRasterProperties_management(Input_raster, "STD")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Raster Calculator&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.gp.RasterCalculator_sa("(\"%Input raster%\" - %Mean%) / %St Dev rastercalc)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Michelle&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Sep 2011 22:15:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-an-arcobject-to-a-number/m-p/242146#M18827</guid>
      <dc:creator>MichelleTotman1</dc:creator>
      <dc:date>2011-09-20T22:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting an arcobject to a number</title>
      <link>https://community.esri.com/t5/python-questions/converting-an-arcobject-to-a-number/m-p/242147#M18828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There's a few issues:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. You assign the mean &amp;amp; st_dev variables to a raster instead of assigning to the output of the GetRasterProperties tool.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. The GetRasterProperties tool returns a "Result" object which has a GetOutput method that you need to use to access the mean/std values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Your calculation has a few errors - no terminating quote, the text doesn't match any of the variables you set previously, and the "rastercalc" raster has no operator linking it to the rest of the expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code works, but you'll need to check the actual expression as I stuck a "+" operator in front of the&amp;nbsp; "rastercalc" raster so the expression would actually run, substitute it with whatever operator you require.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#...
# Process: Get Raster Properties
Mean = float(arcpy.GetRasterProperties_management(Input_raster, "MEAN").getOutput(0))

# Process: Get Raster Properties (2)
St_Dev = float(arcpy.GetRasterProperties_management(Input_raster, "STD").getOutput(0))

# Process: Raster Calculator
calc='("%s" - %s) / %s + "%s"'%(Input_raster,Mean,St_Dev,rastercalc)
result=arcpy.gp.RasterCalculator_sa(calc)
print result.GetMessages()
print result.GetOutput(0)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:08:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-an-arcobject-to-a-number/m-p/242147#M18828</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T12:08:13Z</dc:date>
    </item>
  </channel>
</rss>

