ESRI grid and "info" folder inside the working directory

2639
2
Jump to solution
07-24-2014 07:31 AM
InceptionWoznicki
New Contributor

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 

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

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

In short, there is only one info folder per folder.  For example, 10 grids in a folder will all share the same info folder.  If you want separate info folder for each grid, then you have to copy/export (not using your operating system!!!) each grid to its own folder

View solution in original post

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

In short, there is only one info folder per folder.  For example, 10 grids in a folder will all share the same info folder.  If you want separate info folder for each grid, then you have to copy/export (not using your operating system!!!) each grid to its own folder

0 Kudos
InceptionWoznicki
New Contributor

Thank you very much Mr Patterson!

0 Kudos