I am trying to create a python script to run several ArcMap tools in succession on a DEM. The script will ideally create a random raster (based on a normal distribution, with a mean of 0 and a standard dev. of 2), then add this to a DEM to form a DEM + random raster. The viewshed tool will then be carried out on this DEM+. I want this to loop 20 times.

This is the code I currently have:

# Program to calculate probable viewshed from a DEM using ArcMap tools
# Author: David Ely, 02/06/2016
# Status: Work In Progress
# This program must be placed in the same directory folder as the DEM

# Import the required libraries
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension = 'Spatial'

# Set the environment to allow overwrites to data
arcpy.env.overwriteOutput = True

# Load in the DEM and store it's extent
print 'DEM file name: '
DEM = Raster(raw_input()) # User inputs the name of the DEM file
DEMextent = DEM.extent

# Enter the RMSE of the DEM and the output path for the analyses
print 'Enter RMSE of DEM: '
RMSE = raw_input()
print 'Enter output path for analyses: '
outpath = raw_input()

# define i for incremental loop and loop for analysis
i = 0
while i<20:
    print 'procedure #' + str(i)
    distribution = 'NORMAL 0 ' + RMSE
    outname = 'rand' + str(i)
    arcpy.CreateRandomRaster_management(outpath, outname, distribution, DEMextent, 5)
    randrast = Raster(outpath + '\\' + 'rand' + str(i))
    addrast = randrast + DEM
    i = i+1

before I added the code to carry out the map algebra in the while loop the create random raster tool would work every time. However, once the next two lines of code were added the createrandomraster tool fails to execute every other time (error 999999).

Does anyone know why this could be?

closed as off-topic by PolyGeo Sep 30 '16 at 1:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you always get the error every other time? I tried running the script and got a 999999 error the first time, but it ran ok after that. Is another process accessing the DEM or output folder? – jon_two Jun 2 '16 at 11:12
  • I always get it every other time. There aren't any other processes using the folder no. Thanks. – D. Ely Jun 2 '16 at 12:11

Browse other questions tagged or ask your own question.