I have this simple piece of python code to test whether a raster has integer values or not:

        res = arcpy.GetRasterProperties_management(ws, 'VALUETYPE')
        res = res.getOutput(0)
        if res > 8:
            print res

I run this in a loop for a number of rasters. Problem is, it prints out a list of 3's.

I'm guessing that the 'res' variable is not a single number at all and when you do a logical test on it, it looks at a certain attribute and when you print res, it prints a different attribute.

Can anyone explain how I should do this test properly?

  • 1
    `getOutput()' is a method on a Result object This can return either a recordset or a string. – GeoSharp Mar 14 '14 at 11:14

The value types are stored as "unicode" string with the meanings given below, as you know. So what you need to do is using int(res) instead of res for testing. Also, I suggest that you use a different name for the first "res" (a Result Object) and the second res :

reso = arcpy.GetRasterProperties_management(ws, 'VALUETYPE')
res = reso.getOutput(0)
        if int(res) > 8:
            print res

0 = 1-bit
1 = 2-bit
2 = 4-bit
3 = 8-bit unsigned integer
4 = 8-bit signed integer
5 = 16-bit unsigned integer
6 = 16-bit signed integer
7 = 32-bit unsigned integer
8 = 32-bit signed integer
9 = 32-bit floating point
10 = 64-bit double precision
11 = 8-bit complex
12 = 64-bit complex
13 = 16-bit complex
14 = 32-bit complex
  • Thanks. This explains it. Although I see no need to create another variable name as I will not reuse the object - I only care about the result. It makes the code a bit clearer IMO. – James Mar 14 '14 at 11:45

If you look at the help for this tool, it clearly states that the top of the page that number 3 for VALUETYPE is 8-bit unsigned integer, did you look at the help for this tool?

  • Did you read the question? My question was why if I do a logical test for values above 8, does it return a value that is below 8 (3). Radouxju gave the right answer that the number returned is a string (which I missed when reading the help), so I need to cast to an int first. – James Mar 14 '14 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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