Extract By Mask emptied my attribute table

04-18-2014 07:30 AM
New Contributor III
I've been trying to automate the process of clipping thematic rasters to the same extent and then subdividing them by polygon. However, there have been a lot of errors along the way. Here's the latest:
Runtime error  Traceback (most recent call last):   File "<string>", line 85, in <module>   File "<string>", line 44, in clip_to_shape   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7030, in ExtractByMask     in_mask_data)   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper     result = wrapper(*args, **kwargs)   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7026, in Wrapper     out_raster)   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>     return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. The table was not found. The table was not found. [VAT_times_ras1] Table attachments not supported in this release of the Geodatabase. The table was not found. [VAT_Extract_tim11] The table was not found. [VAT_Extract_tim11] A column was specified that does not exist. A column was specified that does not exist. The table was not found. [VAT_Extract_tim11] The operation was attempted on an empty geometry. Failed to execute (ExtractByMask).

This occurs at the beginning of the 2nd iteration of the for loop. Examination of the data layers shows that the attribute tables of masked_themes are being emptied by the 1st iteration, for an unknown reason. (The headers are still there.)

import matplotlib.pyplot as plt
arcpy.env.workspace = 'in_memory'
arcpy.env.snapRaster = r'Fr Demo\Q70slope'
arcpy.env.cellSize = r'Fr Demo\Q70slope'
# store working lists
provinces = [r'Physiographic Provinces\PhysioPacific',r'Physiographic Provinces\PhysioAtlantic',r'Physiographic Provinces\PhysioCentral',r'Physiographic Provinces\PhysioDarien']
themes = ['HWSDunit1kmWGS','Geo1kmWGS',r'Fr Demo\Q70slope']
validators = [r'USGS\Combined\MitchCatBinary1kmGCS',r'U of Oslo\NicCatBinary1kmGCS',r'El Salvador\1km rasters\EScat1kmGCSBinaryClip',r'GLC\GLC1kmGCSbinary']
trainers = [r'Training\TrainingWeighted1kmGCS',r'Training\TrainingAll1kmGCS',r'Training\TrainingSampled1kmGCS']

def create_mask(raster):
 # create presence raster
 temp = arcpy.sa.IsNull(raster)+1
 temp2 = arcpy.sa.LessThan(temp,2)
 mask= arcpy.sa.SetNull(temp2,1,'value=0')
 del temp, temp2
 return mask
def create_masks(rasters):
 for raster in rasters:
  temp = create_mask(raster)
 del temp
 return masks

def unify_masks(rasters):
 for i in range(len(rasters)):
  if i == 0: mask = arcpy.sa.Times(rasters,1)
  else: mask = arcpy.sa.Times(rasters,mask)
 return mask
def clip_to_mask(rasters,mask):
 outputs = []
 for raster in rasters:
  temp = arcpy.sa.Times(mask,raster)
  del temp
 return outputs
def clip_to_shape(rasters,shape):
 outputs = []
 for raster in rasters:
  temp = arcpy.sa.ExtractByMask(raster,shape)
  del temp
 return outputs
def get_Fr_table(theme,landslides):
 fieldname = "value"
 newfieldname = 'Fr'
 zsum_table = arcpy.sa.ZonalStatisticsAsTable(theme, fieldname, landslides, 'temp', 'DATA', 'SUM')
 arcpy.AddField_management(zsum_table, newfieldname,"DOUBLE")
 rows = arcpy.UpdateCursor(zsum_table)
 total_count, total_sum = 0,0
 for row in rows:
  total_count += row.getValue("count")
  total_sum += row.getValue("sum")
 rows = arcpy.UpdateCursor(zsum_table)
 for row in rows:
  Lcb = row.getValue("sum")
  Scb = row.getValue("count")
  Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count)
  row.setValue(newfieldname, Fr)
 return zsum_table
# create raster mask for all layers
masks = create_masks(themes) + create_masks(trainers)
mask = unify_masks(masks)
del masks

# mask all layers
masked_themes = clip_to_mask(themes, mask)
masked_trainers = clip_to_mask(trainers, mask)
masked_validators = clip_to_mask(validators, mask)
del mask
for province in provinces:
 # get name of physiographic province
 n = province.find('\Physio')+7
 province_name = province[n:]
 print province_name
 # clip layers to province
 province_themes = clip_to_shape(masked_themes, province)
 province_trainers = clip_to_shape(masked_trainers, province)
 province_validators = clip_to_shape(masked_validators, province)
0 Kudos
0 Replies