3

When I use 'Plus' in Spatial Analyst to add together two 8-bit unsigned rasters (pixel values 0-100) the output raster is 8-bit unsigned (pixel values 0-200) but when I try and do the same thing running a python script the output is a 32 signed raster (pixel values 0-200) . How can I adjust my code to have the output be an 8-bit raster?

# Import needed modules
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
raster1 = arcpy.Raster("C:\Users\XXX\Desktop\Raster_test\Confidence_2008_56m.tif")
raster2 = arcpy.Raster("C:\Users\XXX\Desktop\Raster_test\Producers_2008_56m.tif")
# Execute Plus
outPlus = Plus(raster1, raster2)
# Save the output 
outPlus.save("C:\Users\XXX\Desktop\Raster_test\script_plus2.tif")
  • Although I can't confirm this is the case for this tool, please see this answer to How to reduce Polygon to Raster (Conversion) bit depth? which suggests that there is no way to control bit-depth in some ArcGIS tools. – Midavalo Feb 5 '16 at 20:52
  • Thanks for the reply, I haven'y found a direct answer to my question online but reading about similar issues your suggestion may be the culprit. – Ian Schelly Feb 5 '16 at 21:16
3

Once you did your analysis you can Copy your output with arcpy.CopyRaster_management. Where you can specify bit depth through the pixel_type arg. For example - arcpy.CopyRaster_management("inrast","outrast","","","-9999", "","","8_BIT")

You can then delete the earlier output to cleanup. enter image description here

  • 1
    Thanks for the reply, worked like a charm! I replaced the Output.save() with the arcpy.CopyRaster_management() – Ian Schelly Feb 6 '16 at 0:17
  • great!, if this worked please tick the "accepted answer" green tick, so other users can see the question as an accepted answer. Cheers – yanes Feb 8 '16 at 18:41

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.