Getting min and max from list of arcobjects

813
5
01-24-2012 05:49 AM
JacobFraser
New Contributor
I'm working on a simple script that will extract the lowest and highest values present from a group on input rasters. The values seem to be extracted to the lists properly but when I try to run the min and max function on the list I get an error: Runtime error <type 'exceptions.TypeError'>: 'list' object is not callable

import arcpy
from arcpy import env
inputs = arcpy.GetParameterAsText(0)
worklist = inputs.split(";")

rastmin = list()
rastmax = list()

for file in worklist:
    min = arcpy.GetRasterProperties_management(file, "MINIMUM")
    max = arcpy.GetRasterProperties_management(file, "MAXIMUM")
    rastmin.append(float(min.getOutput(0)))
    rastmax.append(float(max.getOutput(0)))

else:
    x = min(rastmin)
    y = max(rastmax)
    arcpy.AddMessage(x)
    arcpy.AddMessage(y) 


Thanks in advance.
Tags (2)
0 Kudos
5 Replies
RaphaelR
Occasional Contributor II
hi Jacob,
you cannot use the built-in min/max function names as variable names.
change them to for example to Rmin/Rmax or something else.
i don´t quite understand what "else" is in there for.
Rmin = arcpy.GetRasterProperties_management(file, "MINIMUM")
Rmax = arcpy.GetRasterProperties_management(file, "MAXIMUM")

rastmin.append(float(Rmin.getOutput(0)))
rastmax.append(float(Rmax.getOutput(0)))
0 Kudos
JacobFraser
New Contributor
Thanks for pointing that out Rafael, I fixed that but still get the same error. The rastmin and rastmax lists seem to get filled correctly and when I do a type() on the items in the list it says they are float.
0 Kudos
RaphaelR
Occasional Contributor II
weird, i just put your code into a sample tool and i think it worked (prints out the absolute max and min from the rasters).

what did you use for the input parameter?
i used "Raster Layer" and set it to multivalue.
0 Kudos
JacobFraser
New Contributor
Weird indeed, I just restarted ArcMap again and now it works.
Thanks for your help.
0 Kudos
ChrisSnyder
Regular Contributor III
Don't forget to use the "result object"! The syntax would actually be like this:

min = arcpy.GetRasterProperties_management(file, "MINIMUM").GetOutput(0)
0 Kudos