extract new raster by attribute value

2154
0
07-18-2014 01:34 PM
InceptionWoznicki
New Contributor

Hello,

 

I have a really stupid question to ask. I want to make three new raster based on three values ( 9, 11, and 13) from original raster. I have 5 original rasters.Therefore, the total new raster would be 15. So, I thought to make a "for loop" for inraster like showed in my code.

 

The only problem is that each original raster has two folders: 1) is the name of the raster which is different for different raster, 2) is "info" folder (which is same for all rasters). Due to the same "info" folder name for each raster, I am not able to keep all the rasters directly in my assigned working directory. I have to create an extra 5 folders inside my working directory and inside each individual folder, i have the raster file.

 

I want to know " how do I access to each original raster as they are not exactly in the working directory".

 

Hopefully, I everybody can understand my question. I am providing the code below.

 

Thank you!

 

Code:

 

import arcpy, os

from arcpy import env

from arcpy.sa import *

 

#To overwrite output

arcpy.env.overwriteOutput = True

 

#Set environment settings

env.workspace = "C:/Subhasis/Test/Neshanic_Python"

 

outws="C:/Subhasis/Test/Neshanic_Python/extract"

 

#checkout ArcGIS spatial analyst extension license

arcpy.CheckOutExtension("Spatial")

 

# set local variable

inraster = [01367620-r-r,01367700-r-r,01367770-r-r,01367910-r-r,01379000-r-r]

for i in inraster:

STI_list=[9,11,13]

    for j in STI_list:

        attExtract = ExtractByAttributes(str(i), "VALUE>=" + str(j))

        outname=os.path.join(outws,str(i), str(j))

        attExtract.save(outname)

0 Kudos
0 Replies