<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: raster extraction in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632859#M49311</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, 30 is not in the data. The upper limit is 28.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Feb 2016 15:18:38 GMT</pubDate>
    <dc:creator>InceptionWoznicki</dc:creator>
    <dc:date>2016-02-26T15:18:38Z</dc:date>
    <item>
      <title>raster extraction</title>
      <link>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632857#M49309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a original tif file which has values from 2 to 28. From that original tif file, I am extracting cells having value &amp;gt;=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.&lt;SPAN class="diff-delete"&gt; I would really appreciate any help/ suggestion!&lt;/SPAN&gt;&lt;SPAN class="diff-add"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="diff-add"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; The code is provided below&lt;SPAN class="diff-delete"&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_145643881961571 jive_text_macro" data-renderedposition="112_8_872_16" jivemacro_uid="_145643881961571"&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;import arcpy, os&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#To overwrite output&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Set environment settings&lt;/P&gt;&lt;P&gt;env.workspace = "C:/Subhasis/Highland/Project/Python_data"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;outws="C:/Subhasis/Highland/Project/Python_data/HSA_10"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#checkout ArcGIS spatial analyst extension license&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;inraster = arcpy.ListRasters("*", "TIF")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for i in inraster:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = ("VALUE", "COUNT")&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)}&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt = sum(dct.values())&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct1 = {k:v for (k,v) in dct.items() if k &amp;gt;= 10}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt1 = sum(dct1.values())&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; percentage=(float(sumcnt1)/float(sumcnt))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i,percentage&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newraster = ExtractByAttributes(str(i), "VALUE&amp;gt;=10")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname=os.path.join(outws,str(i))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newraster.save(outname)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Feb 2016 22:21:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632857#M49309</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2016-02-25T22:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: raster extraction</title>
      <link>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632858#M49310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is the 30 actually in the data, or just listed as the upper limit in the symbology?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Feb 2016 22:26:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632858#M49310</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-02-25T22:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: raster extraction</title>
      <link>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632859#M49311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, 30 is not in the data. The upper limit is 28.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Feb 2016 15:18:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632859#M49311</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2016-02-26T15:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: raster extraction</title>
      <link>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632860#M49312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for testing purposes I'd include (see highlighted 3 lines)&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;for i in inraster:&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = ("VALUE", "COUNT") &lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} &lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt = sum(dct.values())&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct1 = {k:v for (k,v) in dct.items() if k &amp;gt;= 10}&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt1 = sum(dct1.values())&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; percentage=(float(sumcnt1)/float(sumcnt))&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i,percentage&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;STRONG&gt;&lt;CODE&gt;&lt;SPAN class="n"&gt;&amp;nbsp; arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;CalculateStatistics_management(str(i))&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;STRONG&gt;&lt;SPAN class="n"&gt;&lt;CODE&gt;&lt;SPAN class="n"&gt;&amp;nbsp; maxValue&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetRasterProperties_management&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(str(i)&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"MAXIMUM"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;STRONG&gt;&lt;SPAN class="n"&gt;&lt;SPAN class="p"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print maxValue&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newraster = ExtractByAttributes(str(i), "VALUE&amp;gt;=10")&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname=os.path.join(outws,str(i))&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newraster.save(outname)&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;and the same for newraster&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Feb 2016 15:59:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-extraction/m-p/632860#M49312</guid>
      <dc:creator>SteveLynch</dc:creator>
      <dc:date>2016-02-26T15:59:39Z</dc:date>
    </item>
  </channel>
</rss>

