Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save riyadparvez/4475330 to your computer and use it in GitHub Desktop.
Save riyadparvez/4475330 to your computer and use it in GitHub Desktop.
This blog post shows how to add constant value to every grid in ArcGIS raster file.

Adding constant value to raster using arcpy#

Using overloaded arcpy addition (+) operator you can add constant value to raster.

constantValue = 5
outputRaster = inputRaster + constantValue

Now every cell value of outputRaster will be incremented by 5.

Apparently this is a great approach. You are just using simple addition operation. But the problem is outputRaster won't have any attribute table even if inputRaster has one. Because when you are adding two rasters if one of the rasters doesn't have attribute table, the output raster won't have one.

So how can you add constant value to a raster without losing attribute table? There's no direct solution to this problem, but there's a workaround. First create a constant raster, then add.

outputRaster = inputRaster + constantRaster

Now outputRaster will have attribute table where every value of grid is increased by the amount specified in constantRaster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment