<?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 Read specific raster file using python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218515#M16785</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to read a specific raster image file using python, however, getting some difficulties. Can you please help me? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the details about the files:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, os, string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LstRst = arcpy.ListRasters("*", "img")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for Rst in LstRst:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, "_stanislaus.img")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;when I print Rst, it prints all raster images with _stanislaus.img. Now, I need to read an specific image like "aug08_2010_stanislaus.img". Can you please tell me how to do that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jan 2012 20:26:42 GMT</pubDate>
    <dc:creator>RameshGautam</dc:creator>
    <dc:date>2012-01-17T20:26:42Z</dc:date>
    <item>
      <title>Read specific raster file using python</title>
      <link>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218515#M16785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to read a specific raster image file using python, however, getting some difficulties. Can you please help me? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the details about the files:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, os, string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LstRst = arcpy.ListRasters("*", "img")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for Rst in LstRst:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, "_stanislaus.img")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;when I print Rst, it prints all raster images with _stanislaus.img. Now, I need to read an specific image like "aug08_2010_stanislaus.img". Can you please tell me how to do that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 20:26:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218515#M16785</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2012-01-17T20:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Read specific raster file using python</title>
      <link>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218516#M16786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm confused. If you know the file name, why not just substitute the file name for "_stanislaus.img"?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
 import sys, os, string
 from arcpy.sa import *
 from arcpy import env
 arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"
 LstRst = arcpy.ListRasters("*", "img")
 for Rst in LstRst:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, "aug08_2010_stanislaus.img")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Or, are you looking for how to substitute a variable into the file name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
 import sys, os, string
 from arcpy.sa import *
 from arcpy import env
 arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"
 LstRst = arcpy.ListRasters("*", "img")
 fileprefix = "aug08_2010"
 for Rst in LstRst:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, fileprefix + "_stanislaus.img")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:40:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218516#M16786</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T10:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read specific raster file using python</title>
      <link>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218517#M16787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot for your prompt help. When I replace "_stanislaus.img" by "aug08_2010_stanislaus.img", it can't print the file, however, as you have mentioned in second option by using fileprefix, we can read this file. Do you know why? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your help. I apprecaite it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm confused. If you know the file name, why not just substitute the file name for "_stanislaus.img"?&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
 import sys, os, string
 from arcpy.sa import *
 from arcpy import env
 arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"
 LstRst = arcpy.ListRasters("*", "img")
 for Rst in LstRst:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, "aug08_2010_stanislaus.img")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst
&lt;/PRE&gt;&lt;BR /&gt;Or, are you looking for how to substitute a variable into the file name?&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
 import sys, os, string
 from arcpy.sa import *
 from arcpy import env
 arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"
 LstRst = arcpy.ListRasters("*", "img")
 fileprefix = "aug08_2010"
 for Rst in LstRst:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Img1 = string.find(Rst, fileprefix + "_stanislaus.img")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Img1 &amp;gt; -1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print Rst
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:40:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-specific-raster-file-using-python/m-p/218517#M16787</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2021-12-11T10:40:26Z</dc:date>
    </item>
  </channel>
</rss>

