Link table values to ExtractByAttributes script

327
0
07-17-2020 03:34 PM
JosephKennedy
New Contributor

Usuing ArcGIS Destop 10.7, I have 83 rasters that I need to loop through and perform an Extract By Attributes on using Python. Each raster has a range of values that the extracted pixels should be between. What I need to be able to do is insert the upper and lower bounding values from a table into the "where_clause".

ExtractByAttributes(in_raster, where_clause)

I'm not exactly sure how to link the appropriate values to the corresponding raster. Each raster is named after a "Map_ID" and the same "Map_ID" is located in the table. The table only has 3 columns, the Map_ID, upper and lower bounding values. The current python script I have is as follows (red text is what needs to call the values from a table):

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
arcpy.env.workspace = "C:\Users\Rast_conversion_Step_1"

# set output folder
outWorkspace = "C:\Users\Rast_conversion_Step_2"

# create list of rasters to perform raster math on
RasterList = arcpy.ListRasters()

for item in RasterList:
      inSQLClause = "Value >= (Map_ID lower value) and Value <= (Map_ID upper value)"
      extractRast = ExtractByAttributes(item, inSQLClause)
      outputRaster = os.path.join(outWorkspace, item)
      ExtractByAttributes.save(outputRaster)

0 Kudos
0 Replies