[GIS] turn a Result object into a number

arcgis-desktoparcpypython

**import arcpy
from arcpy import env
from arcpy.sa import *
import math
  # Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
   # OverwriteOutput
arcpy.env.overwriteOutput = True
   # Set Geoprocessing environments
arcpy.env.autoCommit = "1000"
arcpy.env.scratchWorkspace = "D:\\NEO\\GISMODELLING\\BestLocationsModel.mdb"
# arcpy.env.extent = "214386.1775 3837166.9542 256099.9616 3907138.0305"
arcpy.env.extent = "D:\\NEO\\GISMODELLING\\BestLocationsModel.mdb\WasteWaterPlant\\Tart_UTM"
arcpy.env.cellSize = "10"
arcpy.env.mask = "D:\\NEO\\GISMODELLING\\BestLocationsModel.mdb\\WasteWaterPlant\\Tart_UTM"
arcpy.env.workspace = "D:\\NEO\\GISMODELLING\\BestLocationsModel.mdb\\WasteWaterPlant"
EucDist_Aggl = "D:/NEO/GISMODELLING/BestLocationsModel.mdb/EucDist_Aggl"
# Process: Get Raster Properties
Max_Aggl = arcpy.GetRasterProperties_management(EucDist_Aggl, "MAXIMUM", "")
print Max_Aggl
delta = int (Max_Aggl)
print delta
a = delta/1000
print a**

when I running this code I have this errore

44250.27734375

Traceback (most recent call last): File "D:\NEO\test.py", line 28,
in
delta = int (Max_Aggl) TypeError: int() argument must be a string or a number, not 'Result'

I need to use the value of Max_Aggl in loops

I try to learn Python as I go

Best Answer

As from the ArcGIS help, getRasterProperties() ...

... returns the output values of a tool when it is executed as a Result object. The advantage of a result object is that you can maintain information about the execution of tools, including messages, parameters, and output. These results can be maintained even after several other tools have been run.

you need to get the value of the result using .getOutput(index), which will return your value of interest as an unicode string at index 0. This string can in turn be converted into a numeric variable using float() and int().

print int(float(Max_aggl.getOutput(0)))
Related Question