AnsweredAssumed Answered

Error with arcpy.env.mask

Question asked by r.brso on Nov 27, 2018
Latest reply on Nov 27, 2018 by xander_bakker

Hi! I have a script with a set of environment properties. I'm having a problem to save my outputs due to Error 999998. After some attempts i have figured out that the problem occurs when I set a mask for the environment (a shapefile). If I remove the mask, then my outputs are saved.


Any idea how can I solve this issue?


The error (RuntimeError: Error 999998: Unexpected Error) happens in line 60 of the following script: 



import os
import arcpy
from import *

# Checking spatial analyst extension
if arcpy.CheckExtension('Spatial') == 'Available':
     print('Spatial Analyst extension is not available')

# Setting paths   
inp_ws = os.path.join("D:\\", "master", "data", "cb")
out_ws = os.path.join(inp_ws, "results")
temp_ws = os.path.join(inp_ws, "temp")
lu_folder = os.path.join(inp_ws, "lu")

# Setting geoprocessing environments
arcpy.env.workspace = inp_ws
arcpy.env.scratchWorkspace = temp_ws
arcpy.env.rasterStatistics = "STATISTICS 1 1"
arcpy. env.snapRaster = "soc_default"
arcpy.env.cartographicCoordinateSystem = "PROJCS['South_America_Albers_Equal_Area_Conic',GEOGCS['GCS_South_American_1969',DATUM['D_South_American_1969',SPHEROID['GRS_1967_Truncated',6378160.0,298.25]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-60.0],PARAMETER['Standard_Parallel_1',-5.0],PARAMETER['Standard_Parallel_2',-42.0],PARAMETER['Latitude_Of_Origin',-32.0],UNIT['Meter',1.0]]"
arcpy.env.mask = "BRA_adm0"

# Describing rasters file extension
for dirpath, dirnames, filenames in arcpy.da.Walk(inp_ws, datatype="RasterDataset"):
     dir_lu = [d for d in dirnames if d == 'lu']    
     dirnames = dir_lu
     if dirpath == inp_ws or dirpath == lu_folder:
          print"\nThe formats of input rasters in folder {} are:".format(dirpath)
     for f in filenames:
          path = os.path.join(dirpath, f)
          ext = arcpy.Describe(path).format
          print  "< {0} > for {1}".format(ext, f)
# Cataloging LU maps in a list
lu_scenarios = []
for dirpath, dirnames, filenames in arcpy.da.Walk(lu_folder, datatype='RasterDataset'):
     for f in filenames:

# Setting input data
climate = Raster("climate")
soc_default = Raster("soc_default")
codes_soc = "soc_random_test.txt"
codes_bc = "bc_stock.txt"

for (i, lu_scenario) in enumerate(lu_scenarios):
     lu = Raster(lu_scenario)
     # map algebra: combine climate + lu files
     clim_lu = climate + lu
     # reclass by soc factor
     soc_factor = ReclassByTable(clim_lu, codes_soc, "Code", "Code", "Value")
     # map algebra: create soc stock
     soc = (soc_factor*soc_default)/1000 #tonne C/ha
     # reclass by bc stock
     bc = ReclassByTable(clim_lu, codes_bc, "Code", "Code", "Value") # map algebra: soc stock + bc stock
     tc = soc + bc
     if str(tc) != "":
          tc_output = (temp_ws + "\\" + str(i)+"-tc-test")

     print tc


Thank you very much!!