import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.AddMessage("Creating Elevation Raster") arcpy.env.workspace = FD_addr list = arcpy.ListRasters("*", "ALL") raster0 = arcpy.Raster(list[0]) raster1 = arcpy.Raster(list[1]) elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0) elevation.save(FD_addr)
The inputs need to be "raster objects" to work in teh new map algebra. Try this:import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.AddMessage("Creating Elevation Raster") arcpy.env.workspace = FD_addr list = arcpy.ListRasters("*", "ALL") raster0 = arcpy.Raster(list[0]) raster1 = arcpy.Raster(list[1]) elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0) elevation.save(FD_addr)
elevation.save("my_output")
Yep - on the last line try:elevation.save("my_output")
The raster "my_output" should then be saved to the 'FD_addr' workspace.
Question though: Does 'FD_addr' point to a feature dataset within a geodatabase? Last I checked, I thought that you can't write rasters to a feature dataset (has to be directly to the GDB).
elevation.save("C:/output/file_gdb.gdb/elevation") # or whatever the path/filename you want for your out raster
I don't see in the code anywhere that you are setting the variable 'FD_addr' (maybe it is above the imports somewhere?) to actually set the env.workspace.
Could try somehting like:elevation.save("C:/output/file_gdb.gdb/elevation") # or whatever the path/filename you want for your out raster
If this works, at least then you know it's an issue with the workspace/path being set properly.
R_
(not sure how you make it so that code appears in gray?)
Still didn't work 😕
I'm setting the workspace here:
env.workspace = FD_addr
list = arcpy.ListRasters("*", "ALL")
(not sure how you make it so that code appears in gray?)
I feel that has to be working because the rasters being inserted into list are the rasters in that location (I double checked.)
FD_addr is set way in the beginning of the code.
import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.AddMessage("Creating Elevation Raster") arcpy.env.workspace = FD_addr list = arcpy.ListRasters("*", "ALL") raster0 = arcpy.Raster(list[0]) raster1 = arcpy.Raster(list[1]) elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0) print "temporary: ",elevation.isTemporary elevation.save(FD_addr) print "temporary: ",elevation.isTemporary
import arcpy, os
arcpy.CheckOutExtension('Spatial')
arcpy.AddMessage("Creating Elevation Raster")
arcpy.env.workspace = FD_addr
list = arcpy.ListRasters("*", "ALL")
raster0 = arcpy.Raster(list[0])
raster1 = arcpy.Raster(list[1])
elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0)
elevation.save()
Interesting. Are you sure you hard-coded it to an "existing" FGDB? If so, what do you mean it didn't work? Didn't create the raster with your hard-coded name, created a blank raster? Error messages?
What does it report if make the modifications in red?
import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.AddMessage("Creating Elevation Raster") arcpy.env.workspace = FD_addr list = arcpy.ListRasters("*", "ALL") raster0 = arcpy.Raster(list[0]) raster1 = arcpy.Raster(list[1]) elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0) print "temporary: ",elevation.isTemporary elevation.save(FD_addr) print "temporary: ",elevation.isTemporary
R_
Also, it looks like elevation.save(FD_addr) is telling it to save with the filename of the workspace. Workspace is normally a folder or FGDB, not a file.
It's my understanding that elevation.save() would save it in the current workspace as raster dataset "elevation".
Now that I think about it, before trying the above code, what happens if you try this (of course, make sure the FD_addr is set to a FGDB that the current user has write access to):
import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.AddMessage("Creating Elevation Raster") arcpy.env.workspace = FD_addr list = arcpy.ListRasters("*", "ALL") raster0 = arcpy.Raster(list[0]) raster1 = arcpy.Raster(list[1]) elevation = arcpy.sa.Con(raster1 - raster0 >= 0, raster1 - rasters0, 0) elevation.save()