[GIS] How to modify a cell value in a raster under certain conditions (ArcGIS)

arcpyraster

I have a DEM raster with some negative values. After overlying other shapefiles, I realize that the negative values are for bodies of water (mainly lakes and bays). I want to replace the negative values with the positive values elevation values (lakes). Any suggestion to do this in python? (Con tool will not work: lakes are at different altitude levels).

Best Answer

I would think you could still use the CON tool if you do a little bit of vector work first. If you have a layer of the lakes, you would want them to have an attribute for the base elevation value (as shown in my embedded graphic). I drew this inside a study area polygon because you might want to avoid problems of NoData values by having the study area (green) be 0 or some value to use in the con statement.

enter image description here

So lets say you convert that vector work into a raster and call it studyArea. It has values of 0, 200, or 300 (in my example).

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/myFolder/data"
outCon = Con(Raster("studyArea") > 0, "studyArea", "dem")
outCon.save("C:/myFolder/output/output.img")