Branched from: Help: Batch - composite bands Arc-python
Hi,
I would like use this script, but it fails. Some hint?
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Teste_Auto_CLEIA\Ima_compactadas'</SPAN>
<SPAN class="comment token"># list all folders in a directory</SPAN>
folders <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListWorkspaces<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"L8*"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Folder"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Inside main directory, already have other folders, but the bands are always inside folders that begin with "L8", e.g. "L8227069".</SPAN>
<SPAN class="comment token">#The output files place</SPAN>
outws <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Teste_Auto_CLEIA\Imagem'</SPAN> <SPAN class="comment token"># Line 9</SPAN>
<SPAN class="keyword token">for</SPAN> folder <SPAN class="keyword token">in</SPAN> folders<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> folder
rasters <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*.tif"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># I already erased the bands which I won't use</SPAN>
chk4 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'band{0}.tif'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># I changed the range</SPAN>
rasters <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>a <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> rasters <SPAN class="keyword token">if</SPAN> a<SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">9</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">in</SPAN> chk4<SPAN class="punctuation token">]</SPAN>
name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>outws<SPAN class="punctuation token">,</SPAN> rasters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"_"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># I wrote "outws"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CompositeBands_management<SPAN class="punctuation token">(</SPAN>rasters<SPAN class="punctuation token">,</SPAN> name<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># I put it</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>rasters<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I'm using ArcMap 10.1 and the bands names aren't the same, for instance, "LO82270682017183CUB00_B1", ... , "LO82270682017183CUB00_B7".
Thanks!