AnsweredAssumed Answered

ESRI grid and "info" folder inside the working directory

Question asked by sean.woznicki on Jul 24, 2014
Latest reply on Jul 24, 2014 by sean.woznicki

Hi Guys,

 

I have a silly question to ask. Using the below code, I want to extract a new raster from an original raster using value field and I want to automate the process for 70 more rasters. However, for testing purpose, I 'm using only 3 rasters.

 

Out of 3 rasters inside the working directory, this code works only for one raster which has both " ESRI grid" and "info" folder inside the working directory. I was not able to keep the "info" folders of other two raster inside the working directory as the "info" folder of 1st raster is already in the working directory.

 

I know it is stupid question. But could you please let me know how can i keep the "info" folders of other two rasters inside the working directory, so that code will work and I can automate the process?

 

Thank you very much for your time and help!

 

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") 

 

# create a list of all rasters in current workspace 

lst_ras = arcpy.ListRasters() 

 

 

threshold = 0.75 

for ras in lst_ras: 

    flds = ("VALUE", "COUNT") 

    dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(ras, flds)} 

    sumcnt = sum(dct.values()) 

    threscnt = sumcnt * threshold 

 

   

    cnt, result = 0, 0 

    for k in sorted(dct): 

        cnt += dct[k] 

        # print " - Value = {0}, Sum = {1}".format(k, cnt) 

        if cnt < threscnt: 

            result = int(k) 

        else: 

            break 

 

    print "Threshold = {0}".format(result) 

    attExtract = ExtractByAttributes(ras, "VALUE>={0}".format(result)) 

    outname = os.path.join(outws,"{0}{1}".format(ras, result)) 

    attExtract.save(outname) 

 

 

arcpy.CheckInExtension("Spatial")

Outcomes