AnsweredAssumed Answered

Using arcpy to create slope surfaces

Question asked by jborgion Champion on Mar 19, 2020
Latest reply on Mar 19, 2020 by jborgion

ArcGIS Pro 2.5

 

I have a number of .tif  and ,img images that I need to convert into slope surfaces (as discussed here Display A Slope Raster ) and have  been following the steps shown here:  Slope—Help | Documentation .

 

However, I get one of two errors depending on where I send the slope.save() to.  Here is my script:

import arcpy
from arcpy.sa import *
import os

inDir = r'C:\JoesStuff\SouthernImages'
#outWS = r'C:\JoesStuff\SouthernImages\SlopeRasters' # to a folder
outWS = r'C:\JoesStuff\SouthernImages\Rasters.gdb'  # to a gdb

for i in os.listdir(inDir):
    if i.endswith('.tif') or i.endswith('.img'):
        inRaster = os.path.join(inDir,i)
        outFile = i.split('.')[0]
        outRaster = f'{outWS}\{outFile}Slope'
        outMeasurement = 'PERCENT_RISE'
        zFactor = 1
        method = 'PLANAR'
        zUnit = 'METER'
   
    outSlope = Slope(inRaster, outMeasurement, zFactor, method, zUnit)
    outSlope.save(outRaster)

with line 6 commented and line 7 active this error is returned:

 

RuntimeError: ERROR 010240: Could not save raster dataset to 
C:\JoesStuff\SouthernImages\Rasters.gdb\12TVK1276Slope with output format FGDBR.

 

if I try to save the slope to a directory by executing line 6 with line 7 commented  this error is returned

 

RuntimeError: ERROR 010240: Could not save raster dataset to 
C:\JoesStuff\SouthernImages\SlopeRasters\12TVK1276Slope with output format GRID.

 

I know the slope surfaces are being created, because when I comment line 20, and replace it with a print statement, the loop runs just fine.  I have run tool manually and it works just great on individual input .tif or .img.

Outcomes