2

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.

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?

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")
inraster = arcpy.ListRasters("*", "GRID")
for i in inraster:
 flds = ("VALUE", "COUNT") 
 dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} 
 sumcnt = sum(dct.values())
 dct1 = {k:v for (k,v) in dct.items() if k >= 15}
 sumcnt1 = sum(dct1.values())
 percentage=(float(sumcnt1)/float(sumcnt))
 print percentage
 newraster = ExtractByAttributes(str(i), "VALUE>=15")
 outname=os.path.join(outws,str(i))
 newraster.save(outname)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 24, 2014 at 14:46
4
  • 3
    The "info" directory contents are part of the grid format. You can copy multiple grids into a single workspace, but you can't merge info directories at the filesystem level without data loss. Commented Jul 24, 2014 at 16:10
  • 1
    Further to Vince's advice you should always use ArcCatalog to move spatial data otherwise you get yourself into the mess that you are in. If a folder (e.g. c:\temp) was going to hold multiple ESRI grids then you only ever see 1 info folder but this contains important information about every grid dataset. Use ArcCatalog to copy and paste all your ESRI grids into a single folder. Commented Jul 24, 2014 at 16:45
  • @Vince and Hornbydd, Thanks for your quick response. What I did I converted the grid to TIF format which has no common file between TIF files and that solved my problem. Thanks guys! Commented Jul 24, 2014 at 17:43
  • @Inception I think you should write your comment up as an answer, perhaps referencing the advice offered by Vince and Hornbydd to make it worthwhile. Commented Aug 10, 2014 at 1:22

1 Answer 1

0

As indicated in the Comments the asker of this question was able to achieve a solution by converting the grid to TIF which is a more self contained format that does not require some parts of it to be written to a common folder (i.e. info).

Had the original format been a mandatory requirement then this could also have been achieved by using ArcPy Copy and Delete functions that are aware of how to move all parts of the grid correctly.

answered Aug 15, 2014 at 23:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.