AnsweredAssumed Answered

raster extraction

Question asked by sean.woznicki on Feb 25, 2016
Latest reply on Feb 26, 2016 by slynch-esristaff

I have a original tif file which has values from 2 to 28. From that original tif file, I am extracting cells having value >=10 using the following code. The code is working. However, when I open the new extracted tif file in GIS, I found that the cell values range from 10 30 instead of 10 to 28. I would really appreciate any help/ suggestion!   

The code is provided below:

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/Highland/Project/Python_data"

 

outws="C:/Subhasis/Highland/Project/Python_data/HSA_10"

 

#checkout ArcGIS spatial analyst extension license

arcpy.CheckOutExtension("Spatial")

 

inraster = arcpy.ListRasters("*", "TIF")

 

 

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 >= 10}

    sumcnt1 = sum(dct1.values())

    percentage=(float(sumcnt1)/float(sumcnt))

    print i,percentage

    newraster = ExtractByAttributes(str(i), "VALUE>=10")

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

    newraster.save(outname)

Outcomes