# ArcGIS function to subtract cell from next cell in a raster?

Using ArcGIS 10.5.1 - I have a raster with certain values (elevation in this case). I'd like to generate a raster that is based on each cell subtracted from its neighboring cell (the one to the direct left). Is there a function that would do this? Example:

Input raster:

• 6 16 14
• 6 10 14
• 8 10 14
• Desired output raster:

• No Data 10 -2
• No Data 4 4
• No Data 2 4
• Used Raster --> Float. Here is my header file

• Are you using the ArcGIS Spatial Analyst? What have you tried?
– PolyGeo
Commented Mar 29, 2018 at 2:56
• You could use python and with RasterToNumpyArray() create a 2D numpy array. Then you could copy the array and add a 0's to the left in the first array and a 0's column to the right in the second array. Having these two arrays, you could substract them, declare the first column as a NoData value (-9999) and then use NumPyArrayToRaster() in order to get the resulting raster. Commented Mar 29, 2018 at 2:56
• Shift your raster 1 cell right and subtract. I'd export file to floating, edit header file and import it back. Commented Mar 29, 2018 at 3:31
• I don't know python (but could ask for help). I tried Euclidean distance, but that's not what I want. I found raster to float and ran it successfully on my DEM and know how to subtract rasters. How do I edit the header? Commented Mar 29, 2018 at 4:43

If you do not want use python then this can be done with model builder, by shifting the grid left by 1 pixel, do the maths then shifting it back. Doing this introduces a column of nodata on the right so the final step is to use the original clip to clip it back to the original size.

The model would be:

The important thing is to set the environment setting of the minus tool to be the union of the extents of the original and shifted grid, this allows the no data column to be created.

• This worked perfectly. Note: Processing Extent is set under Geoprocessing Environments. Also, in shift, the value used is the raster cell size (3 in my case, it was a 3 ft x 3ft raster), and it's for the x. It's not a raster count such as 1; it's the units of the raster. Commented Mar 30, 2018 at 22:42

You need notepad only to edit header (*.hdr) file of floating raster.

From:

ncols         348
nrows         355
xllcorner     1758048.7257138
yllcorner     5905009.5863752
cellsize      1
NODATA_value  -9999
byteorder     LSBFIRST


To:

ncols         348
nrows         355
xllcorner     1758049.7257138
yllcorner     5905009.5863752
cellsize      1
NODATA_value  -9999
byteorder     LSBFIRST


i.e. third row from the top.

Workflow for 1m*1m raster resolution using tools:

arcpy.Warp_management(in_raster="dem", source_control_points="'0 0'", target_control_points="'1 0'", out_raster="../SCRATCH/shifted", transformation_type="POLYORDER0", resampling_type="NEAREST")
arcpy.gp.RasterCalculator_sa(""""dem" - "shifted"""", "../SCRATCH/diff")


Input and output:

• I cannot see a difference between your from and to header file. I located mine and opened it in notepad. I added it to the initial question. Commented Mar 29, 2018 at 5:24
• I meant to say 3rd row. Commented Mar 29, 2018 at 6:53