I have the following code:
import arcpy, os
from arcpy import env
from arcpy.sa import *arcpy.env.workspace = "C:/gis/enforcer" #Dummy path
arcpy.env.overwriteOutput = True
dem = "C:/gis/enforcer/dem" #Dummy path
rmseDEM = 0.09 #Dummy value
roads = "C:/gis/enforcer/roads.shp" #Dummy path
rails = "C:/gis/enforcer/rail.shp" #Dummy path
fgdb = "enforcer.gdb" #Dummy patharcpy.env.cellSize = dem
arcpy.env.extent = dem
arcpy.env.sanpRaster = dem
desc = arcpy.Describe(dem)
demResolution = desc.meanCellHeight #Assumes a square
dirName = os.path.dirname(dem)
fgdbPath = dirName + "/" + fgdbarcpy.CheckOutExtension("Spatial")
#-----------------------------------Identify Low Points----------------------------------
analysisSinks = fgdbPath + "/" + "sinkanalysis"
outName = fgdbPath + "/" + "zonemin01"
outZonalStats = ZonalStatistics(analysisSinks, "OBJECTID", dem, "MINIMUM", "NODATA")
outZonalStats.save(outName)
outName02 = "minpnt01" #fgdbPath + "/"
outCon = Con(dem == outName, 1)
outCon.save(outName02)
However, Con in the next to last line seems to crash PythonWin every chance it gets or throws ERROR 010240. I've tried everything from saving it as a TIF to switching to a different directory to no avail. Any recommendations?
print out the path concatenation for outName and outName2... one of the two is not good. You will want to make sure that esri grid filenames don't end in a '/' for sure
outName: C:/gis/enforcer\enforcer.gdb\zonemin01
outName02: C:/gis/enforcer\enforcer.gdb\minpnt01
Not sure what the issue is...
You may need to change outname to Raster(outname) so you're comparing dem to a raster object instead of a string.
The paths seem to be valid:
dirName = C:/gis/enforcer
fgdbPath = C:/gis/enforcer/enforcer.gdb
analysisSinks = C:/gis/enforcer/enforcer.gdb/sinkanalysis
outName = C:/gis/enforcer/enforcer.gdb/zonemin01
Although there is an error on this line:
arcpy.env.sanpRaster = dem (it should be snapRaster)
... it is not causing the error you obtain. It is better to check the solution provided by Luke Pinner and if that does not solve the problem, to check your write privileges on the output fgdb.
Als if you import the os module, it is recommended to use:
analysisSinks = os.path.join(fgdbPath, "sinkanalysis")
... instead of this:
analysisSinks = fgdbPath + "/" + "sinkanalysis"
Hello Xander,
Thank you for your recommendations. I've gone through my code and changed:
analysisSinks = fgdbPath + "/" + "sinkanalysis"
to:
analysisSinks = os.path.join(fgdbPath, "sinkanalysis")
as you recommended.
Additionally, thank you for noting the snapRaster typo. I've fixed that as well. Interesting how it didn't seem to throw an error in another script which I pulled the header information from on this code. I'll go back and fix it there too.
Thanks,
John
Hi Luke,
Thanks for your suggestion. I changed:
outCon = Con(dem == outName, 1)
to:
outCon = Con(dem == Raster(outName), 1)
But, I am still getting the same error. Is there something else I am doing incorrectly?
Thanks,
John
Do it manually with the same files... if it works, copy the syntax from the Results window to see what is required... it is probably something small and poking around trying to get a script to work before the actual process has been tested can be futile.
Dan,
Thanks for your response. The tool output:
outCon = Con(Raster(r"dem") == Raster(r"outName"), 1)
I tried that, as well as changing it to:
outCon = Con(Raster(dem) == Raster(outName), 1)
All of which end up with the same issue:
RuntimeError: ERROR 010240: Could not save raster dataset to C:\gis\enforcer\enforcer.gdb\zonemin01 with output format FGDBR.
I don't understand why there would be a FGDBR write error if I just created the FGDBR in the script immediately before this one. Can the write permissions be set to anyone from within Python?
-John
Are they the results from the Results Window