Invert Raster

3425
4
08-01-2011 03:23 AM
jamiefinney
New Contributor III
Is it possible to invert a raster in ArcView + spatial analyst?

I can manually invert the raster using the following expression "(("Fac" - Z_Max) * -1) + Z_min" where z_max/min are manually looked up and replaced using the legend eg. (("Fac" - 1000) * -1) + 0.

however i've got lots of these to run in batch so i don't want to have to manually look up the values each time. i need to run the cost distance tool on these files so they can't have negative numbers my only option at the moment is to use generic min/max numbers then reclass any negative numbers to 0 which isn't ideal

this seems like a pretty straight forward task i'm sure there must be a better way.
Tags (2)
0 Kudos
4 Replies
jamiefinney
New Contributor III
or is there a way to follow the highest cost path rather than the least cost path?
0 Kudos
TimothyHales
Esri Notable Contributor
Here is something I threw together really quick.  It ran fine for me and properly inverted the values of the input raster.

import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
 
InputRaster = "\\c:\\temp\\Input.img"
OutputRaster = "\\c:\\temp\\Output.img"

RasterMax = arcpy.GetRasterProperties_management(InputRaster,"MAXIMUM")
OutputRasterMax = (RasterMax.getOutput(0))

RasterMin = arcpy.GetRasterProperties_management(InputRaster, "MINIMUM")
OutputRasterMin = (RasterMin.getOutput(0))

RasterInvert = ((Minus(InputRaster, float(OutputRasterMax))*(-1)+ float(OutputRasterMin)))
RasterInvert.save(OutputRaster)
0 Kudos
jamiefinney
New Contributor III
thales007 thanks just the function i was looking for, knew there must be a way.
0 Kudos
TimothyHales
Esri Notable Contributor
No problem.  Glad to be able to help.
0 Kudos