<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Extract By Mask emptied my attribute table in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/extract-by-mask-emptied-my-attribute-table/m-p/152040#M5134</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 85, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 44, in clip_to_shape&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7030, in ExtractByMask&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_mask_data)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7026, in Wrapper&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_raster)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in &amp;lt;lambda&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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):
 masks=[]
 for raster in rasters:
&amp;nbsp; temp = create_mask(raster)
&amp;nbsp; masks.append(temp)
 del temp
 return masks

def unify_masks(rasters):
 for i in range(len(rasters)):
&amp;nbsp; if i == 0: mask = arcpy.sa.Times(rasters&lt;I&gt;,1)
&amp;nbsp; else: mask = arcpy.sa.Times(rasters&lt;I&gt;,mask)
 return mask
 
def clip_to_mask(rasters,mask):
 outputs = []
 for raster in rasters:
&amp;nbsp; temp = arcpy.sa.Times(mask,raster)
&amp;nbsp; outputs.append(temp)
&amp;nbsp; del temp
 return outputs
 
def clip_to_shape(rasters,shape):
 outputs = []
 for raster in rasters:
&amp;nbsp; temp = arcpy.sa.ExtractByMask(raster,shape)
&amp;nbsp; outputs.append(temp)
&amp;nbsp; 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:
&amp;nbsp; total_count += row.getValue("count")
&amp;nbsp; total_sum += row.getValue("sum")
 rows = arcpy.UpdateCursor(zsum_table)
 for row in rows:
&amp;nbsp; Lcb = row.getValue("sum")
&amp;nbsp; Scb = row.getValue("count")
&amp;nbsp; Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count)
&amp;nbsp; row.setValue(newfieldname, Fr)
&amp;nbsp; rows.updateRow(row)
 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)&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:09:09 GMT</pubDate>
    <dc:creator>ThomasStanley</dc:creator>
    <dc:date>2021-12-11T08:09:09Z</dc:date>
    <item>
      <title>Extract By Mask emptied my attribute table</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/extract-by-mask-emptied-my-attribute-table/m-p/152040#M5134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 85, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 44, in clip_to_shape&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7030, in ExtractByMask&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_mask_data)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7026, in Wrapper&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_raster)&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in &amp;lt;lambda&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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):
 masks=[]
 for raster in rasters:
&amp;nbsp; temp = create_mask(raster)
&amp;nbsp; masks.append(temp)
 del temp
 return masks

def unify_masks(rasters):
 for i in range(len(rasters)):
&amp;nbsp; if i == 0: mask = arcpy.sa.Times(rasters&lt;I&gt;,1)
&amp;nbsp; else: mask = arcpy.sa.Times(rasters&lt;I&gt;,mask)
 return mask
 
def clip_to_mask(rasters,mask):
 outputs = []
 for raster in rasters:
&amp;nbsp; temp = arcpy.sa.Times(mask,raster)
&amp;nbsp; outputs.append(temp)
&amp;nbsp; del temp
 return outputs
 
def clip_to_shape(rasters,shape):
 outputs = []
 for raster in rasters:
&amp;nbsp; temp = arcpy.sa.ExtractByMask(raster,shape)
&amp;nbsp; outputs.append(temp)
&amp;nbsp; 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:
&amp;nbsp; total_count += row.getValue("count")
&amp;nbsp; total_sum += row.getValue("sum")
 rows = arcpy.UpdateCursor(zsum_table)
 for row in rows:
&amp;nbsp; Lcb = row.getValue("sum")
&amp;nbsp; Scb = row.getValue("count")
&amp;nbsp; Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count)
&amp;nbsp; row.setValue(newfieldname, Fr)
&amp;nbsp; rows.updateRow(row)
 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)&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:09:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/extract-by-mask-emptied-my-attribute-table/m-p/152040#M5134</guid>
      <dc:creator>ThomasStanley</dc:creator>
      <dc:date>2021-12-11T08:09:09Z</dc:date>
    </item>
  </channel>
</rss>

