[GIS] how to get max and min from a raster using arcpy

arcpyraster-calculatorstatistics

I have a land surface temperature raster file and I want the max and min of it.

minLSTresult = arcpy.GetRasterProperties_management(raster_result, "MINIMUM")

minLST = minLSTresult.getOutput(0)

minLST returns u'261.22'. How could I only get the number of it?

Best Answer

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