# Converting DEM units using Map Algebra and Python

I am trying to write a bit of code that combines a bunch of DEMs that match up perfectly and convert the elevation values of the pixel cells from meters to feet. This is all using Pyscripter and Python 2.7.

I found some code on stack exchange (Add two rasters in python using map algebra) that I tried to translate using my own variables, but cannot get it to work. I can create the mosaic fine, but once it gets to the Map Algebra part it crashes on the expression.

Here is my code. I pretty much took what the post had and translated using my own variables. I also tried putting the expression in eval() and it still crashed. Putting '"' + .... + '"' didn't work either.

``````#Convert DEM values to feet.
dem_input = str(mos_wrk) + "\\" + str(mos_name)
demft = dem_input*3.28084
demft.save(str(mos_wrk)+"\\"+str(demft)+"_ft")
``````
• Demft is raster. Instead of str use "demft" in last line. – FelixIP Sep 19 '18 at 22:13
• Also use arcpy.Raster(dem_input) in second line. – FelixIP Sep 19 '18 at 22:15

Thank you @FelixIP for the help. I managed to correct my mistake. By using the arcpy.Raster() function I, then, had to check out a Spatial Analyst license in the script. Below is my final draft of the code. It is converting Meters to Feet

``````print "Starting Process 2: Converting Units to Feet..."
pass
try:
if arcpy.CheckExtension("Spatial") == "Available":
arcpy.CheckOutExtension("Spatial")

arcpy.env.workspace = wrkspc
dem_input = mos_wrk + "\\" + mos_name
demft = arcpy.Raster(dem_input)*3.28084
demft.save(str(mos_wrk)+"\\"+ str(mos_name) +"_ft")

else:
# raise a custom exception