how to get max and min from a raster using arcpy?
Create a raster object using the full path to your raster. Raster objects have the properties minimum
and maximum
.
>>> rastFullPath = r"C:\Rasters\rasters.gdb\Slope"
>>> rast = arcpy.Raster (rastFullPath)
>>> rast.minimum
0.0
>>> rast.maximum
64.9616928100586
Or you can use your method and convert the output from unicode
to float
:
>>> float (arcpy.GetRasterProperties_management (rast, "MAXIMUM").getOutput (0))
64.9616928100586
>>> float (arcpy.GetRasterProperties_management (rast, "MINIMUM").getOutput (0))
0.0
That is simply indicating that the value is a Unicode string. You can use this unicode string in most situations. However, if you need to fully control the type, convert it to float format.
test = unicode('261.22')
>>> test
u'261.22'
>>> type(test)
<type 'unicode'>
test2 = float(test)
>>> test2
261.22
>>> type(test2)
<type 'float'>