<?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: Help: Batch - composite bands  Arc-python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740337#M57255</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. I just want to list from &lt;STRONG&gt;LC81360432015069LGN00_toa_band2.tif &lt;/STRONG&gt; to&lt;STRONG&gt; LC81360432015069LGN00_toa_band7.tif &lt;/STRONG&gt; from each folder.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Zia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Aug 2015 03:26:31 GMT</pubDate>
    <dc:creator>ZiaAhmed</dc:creator>
    <dc:date>2015-08-06T03:26:31Z</dc:date>
    <item>
      <title>Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740335#M57253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;I am trying to make&amp;nbsp; a composite band of six raster files. I have do this for&amp;nbsp; +40 scenes of Landsat 8 processed data. Each scene folder contains about +12 tif files, I want create multi-tif file with&amp;nbsp; following bands using Arc-python batch mode:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band2.tif&lt;/TD&gt;&lt;TD&gt;# Blue &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band3.tif"&lt;/TD&gt;&lt;TD&gt;# Green&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band4.tif"&lt;/TD&gt;&lt;TD&gt;# Red&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band5.tif"&lt;/TD&gt;&lt;TD&gt;# NIR &lt;/TD&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band6.tif&lt;/TD&gt;&lt;TD&gt;# SWIR 1&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC81360432015069LGN00_toa_band7.tif"&lt;/TD&gt;&lt;TD&gt;# SWIR 2&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following python script works fine when the folder&amp;nbsp; contains only above six files. For this, I have to&amp;nbsp; reorganize all 40 folders accordingly,&amp;nbsp; I do not want to do this. This there any way to create a file list only with above six files? Help will be appreciated. Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Zia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;import arcpy, os&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;arcpy.env.workspace = r'E:\Landsat8\Process_data_2015\'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;# list all folders in a directory&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;folders = arcpy.ListWorkspaces()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;for folder in folders:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = folder&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters("*.tif")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = os.path.join(rasters[1].split("_")[0] + ".tif")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CompositeBands_management(rasters, name)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;print "Processing complete"&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2015 14:01:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740335#M57253</guid>
      <dc:creator>ZiaAhmed</dc:creator>
      <dc:date>2015-08-05T14:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740336#M57254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This would require removing the unwanted rasters from the list "rasters". Should be easy to do if you can exclude/include by a part of the name. Do you a list of a sample folder that has 12+ tifs?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2015 17:40:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740336#M57254</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-05T17:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740337#M57255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. I just want to list from &lt;STRONG&gt;LC81360432015069LGN00_toa_band2.tif &lt;/STRONG&gt; to&lt;STRONG&gt; LC81360432015069LGN00_toa_band7.tif &lt;/STRONG&gt; from each folder.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Zia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Aug 2015 03:26:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740337#M57255</guid>
      <dc:creator>ZiaAhmed</dc:creator>
      <dc:date>2015-08-06T03:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740338#M57256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately you did not answer my question. It is important to know which file names you wish to exclude in order to know how to exclude them. Let's suppose you have the following rasters in a folder (see the list "rasters" in the code below, ending on band1.tif until band12.tif). You can use list comprehension to filter out the ones you don't need:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rasters = ['LC81360432015069LGN00_toa_band1.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band2.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band3.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band4.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band5.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band6.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band7.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band8.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band9.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band10.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band11.tif',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'LC81360432015069LGN00_toa_band12.tif']

chk4 = ['band{0}.tif'.format(i) for i in range(2, 8)]
rasters = [a for a in rasters if a[-9:] in chk4]
print rasters&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will yield:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;['LC81360432015069LGN00_toa_band2.tif',
'LC81360432015069LGN00_toa_band3.tif',
'LC81360432015069LGN00_toa_band4.tif',
'LC81360432015069LGN00_toa_band5.tif',
'LC81360432015069LGN00_toa_band6.tif',
'LC81360432015069LGN00_toa_band7.tif']&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... only the bands 2 until 7. This will only work if the assumption made before is true...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740338#M57256</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T07:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740339#M57257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Xander. It&amp;nbsp; works fine if&amp;nbsp; I work with only one folder&amp;nbsp; that contains only 12 tif files as you mentioned in your code. But in my case,&amp;nbsp; I have to work with 42 folders. Each folders&amp;nbsp; contains following tif files and file names is different.&amp;nbsp;&amp;nbsp; I just I want list file &lt;STRONG&gt;*_toa_band2.tif,&amp;nbsp; *_toa_band3.tif,&amp;nbsp; *_toa_band4.tif,*_toa_band5.tif,&amp;nbsp; *_toa_band6.tif,&amp;nbsp; and&amp;nbsp; *_toa_band7.tif&lt;/STRONG&gt; from each folder. &lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;Zia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Folder name:&lt;/P&gt;&lt;P&gt;LC81360432015085-SC20150730095903&lt;/P&gt;&lt;P&gt;LC81360442015085-SC20150730095903&lt;/P&gt;&lt;P&gt;LC81360452015085-SC20150730095903&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Files in a folder (LC81360432015085-SC20150730095903)&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/120896_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Aug 2015 04:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740339#M57257</guid>
      <dc:creator>ZiaAhmed</dc:creator>
      <dc:date>2015-08-06T04:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740340#M57258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would something like this help...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, os
rasters = ['LC81360432015069LGN00_toa_band1.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band2.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band3.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band4.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band5.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band6.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band7.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band8.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band9.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band10.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band11.tif',&amp;nbsp; 
'LC81360432015069LGN00_toa_band12.tif']
bandsrequired = [2, 3, 4, 5, 6, 7]
for rastif in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # get rid of the .tif part
&amp;nbsp;&amp;nbsp;&amp;nbsp; ras = rastif.split(".")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the last bit band??
&amp;nbsp;&amp;nbsp;&amp;nbsp; band = ras.split("_")[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; bandNum = int(band.lstrip("band"))

&amp;nbsp;&amp;nbsp;&amp;nbsp; if bandNum in bandsrequired:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something here
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ras&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:30:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740340#M57258</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-12T07:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740341#M57259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. I have modified your&amp;nbsp; codes. Now it works for all folders. &lt;/P&gt;&lt;P&gt;I appreciate your help. &lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;Zia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#-------------------------------------&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r'E:\LandsatTest'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# list all folders in a directory&lt;/P&gt;&lt;P&gt;folders = arcpy.ListWorkspaces()&lt;/P&gt;&lt;P&gt;for folder in folders:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = folder&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters("*_toa_band*.tif")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk4 = ['band{0}.tif'.format(i) for i in range(2, 8)]&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = [a for a in rasters if a[-9:] in chk4]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = os.path.join(rasters[1].split("_")[0] + ".tif")&lt;/P&gt;&lt;P&gt;print(rasters)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Aug 2015 07:58:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740341#M57259</guid>
      <dc:creator>ZiaAhmed</dc:creator>
      <dc:date>2015-08-06T07:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help: Batch - composite bands  Arc-python</title>
      <link>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740342#M57260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could put the line creating the list called "chk4" outside the loop. It will be the same for each iteration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you mark the post that answered the question as the "correct answer" to close the thead?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Aug 2015 11:43:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-batch-composite-bands-arc-python/m-p/740342#M57260</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-06T11:43:52Z</dc:date>
    </item>
  </channel>
</rss>

