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:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="keyword token">import</SPAN> os
inDir <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\JoesStuff\SouthernImages'</SPAN>
<SPAN class="comment token">#outWS = r'C:\JoesStuff\SouthernImages\SlopeRasters' # to a folder</SPAN>
outWS <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\JoesStuff\SouthernImages\Rasters.gdb'</SPAN> <SPAN class="comment token"># to a gdb</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>inDir<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> i<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.tif'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">or</SPAN> i<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.img'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
inRaster <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>inDir<SPAN class="punctuation token">,</SPAN>i<SPAN class="punctuation token">)</SPAN>
outFile <SPAN class="operator token">=</SPAN> i<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
outRaster <SPAN class="operator token">=</SPAN> f<SPAN class="string token">'{outWS}\{outFile}Slope'</SPAN>
outMeasurement <SPAN class="operator token">=</SPAN> <SPAN class="string token">'PERCENT_RISE'</SPAN>
zFactor <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
method <SPAN class="operator token">=</SPAN> <SPAN class="string token">'PLANAR'</SPAN>
zUnit <SPAN class="operator token">=</SPAN> <SPAN class="string token">'METER'</SPAN>
outSlope <SPAN class="operator token">=</SPAN> Slope<SPAN class="punctuation token">(</SPAN>inRaster<SPAN class="punctuation token">,</SPAN> outMeasurement<SPAN class="punctuation token">,</SPAN> zFactor<SPAN class="punctuation token">,</SPAN> method<SPAN class="punctuation token">,</SPAN> zUnit<SPAN class="punctuation token">)</SPAN>
outSlope<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>outRaster<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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.<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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.<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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.