6

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?

1
  • minLSTresult should return your value. Try print minLSTresult.
    – F_Kellner
    Dec 31, 2015 at 20:58

2 Answers 2

13

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
0
7

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'>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.