Hi,
i try to execute the following commands in the python window
(the spatial analyst extension is checked out)
import arcpy from arcpy.sa import * # Set Mask environment arcpy.env.mask = r'mask' #calculate temp = Raster("rasterA") - Raster("rasterB") temp.save("Result")
RasterA and rasterB are in my dataframe.
After executing temp = Raster("rasterA") - Raster("rasterB")
a raster 'temp' appears in my dataframe (source = temporary raster 'minus_ras' in my default geodatabase.
if a then execute temp.save("Result")
I get the following Arcmap drawing error:
"One or more layers failed to draw:
temp: The table was not found. [fras_blk_minus_ras]
temp: The table was not found."
In the geodatabase an entry "Result" can be found, but it's a File Geodatabase Table instead of a File Geodatabase Raster, and I can't add it to my dataframe..
Anybody knows what's going wrong?
Thanks!
Solved! Go to Solution.
1. what is "mask"? If that's a raster or feature layer, I suggest using the real path to the data on disk.
2. What are your workspace settings? Temporary rasters are always saved in grid format so if you're doing a lot of map algebra I've always felt it makes sense to set the workspace and scratch workspace to a folder, and then either .save() or copy your results to a file geodatabase when you are done if that's where you want to save the rasters.
import arcpy from arcpy.sa import * from arcpy import env env.workspace = r"d:\user\work" env.scratchWorkspace = env.workspace # set mask to a path to a dataset on disk env.mask = arcpy.Describe("mask").catalogPath # calculate temp = Raster("rasterA") - Raster("rasterB") temp.save("Result")
1. what is "mask"? If that's a raster or feature layer, I suggest using the real path to the data on disk.
2. What are your workspace settings? Temporary rasters are always saved in grid format so if you're doing a lot of map algebra I've always felt it makes sense to set the workspace and scratch workspace to a folder, and then either .save() or copy your results to a file geodatabase when you are done if that's where you want to save the rasters.
import arcpy from arcpy.sa import * from arcpy import env env.workspace = r"d:\user\work" env.scratchWorkspace = env.workspace # set mask to a path to a dataset on disk env.mask = arcpy.Describe("mask").catalogPath # calculate temp = Raster("rasterA") - Raster("rasterB") temp.save("Result")
1. My Mask was a polygon shapefile. Specifying its name in the dataframe instead of the path didn't cause any problems.
2. Originally the default workspace was '..\ArcGIS\Default.gdb'
Setting the workspaces to a folder solved my problem! Thanks a lot!!
Do you know why using the geodatabase as the workspace didn't work out? Should map algebra always be done outside a file geodatabase?
thanks again!
> Do you know why using the geodatabase as the workspace didn't work out?
Map algebra will use the env.scratchFolder for temporary grids if it needs a place to write them. This would fail if for some reason the env.scratchFolder (which is a dynamic property designed to always provide you a writable folder) is not available or corrupt. Normally there isn't a problem.... you may want to debug this with "print env.scratchFolder" and look there and maybe it will be obvious why you couldn't write there.
If the workspace is a geodatabase and the the scratch workspace is a folder, maybe it would work.
I think different raster workflows work better with certain file formats, but I'm kind of old school so I like grids. I also like the performance advantages of having a .save() of a temporary grid simply rename it instead of having to actually save the temporary raster to a permanent raster somewhere else. My feeling is that file gdbs are more useful as a raster storage and retrieval format, not as a raster workspace, because files are just a more natural format for raster datasets, with their very large sizes and the inherent spatial indexing of pixel locations. Also, quite a while ago Steve Lynch said doing map algebra with folder workspaces is a good plan and he would know.