0

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")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 19, 2018 at 20:53
2
  • Demft is raster. Instead of str use "demft" in last line. Commented Sep 19, 2018 at 22:13
  • 2
    Also use arcpy.Raster(dem_input) in second line. Commented Sep 19, 2018 at 22:15

1 Answer 1

1

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..."
#Checkout License
class LicenseError(Exception):
 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
 raise LicenseError
except LicenseError:
 print("Spatial Analyst license is unavailable")
except arcpy.ExecuteError:
 print(arcpy.GetMessages(2))
print "Units were converted."
answered Sep 20, 2018 at 20:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.