<?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 Using arcpy.da.Walk to mosaic multiple rasters? in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41091#M2255</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have many hundreds of GeoTiff files to mosaic. The problem is that they are stored in a sub-directory structure whereby I need to traverse down into each sub-directory, mosaic all rasters in that location, and then go back up and down into all the other sub-directories sequentially to perform the same action. Some example directories would appear as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c:\dem\250k\001&amp;nbsp; (do all rasters here)&lt;/P&gt;&lt;P&gt;.............&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \002 (do all rasters here)&lt;/P&gt;&lt;P&gt;.............&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \003 (do all rasters here)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the following Python snippet on the forum, but it finds and mosaics all rasters in all sub-directories to a single output layer. I need to find a way to "walk" into the sub-directories and output a single output for each. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;workspace = r"c:\dem\250k"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rasters = []&lt;/P&gt;&lt;P&gt;walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")&lt;/P&gt;&lt;P&gt;for dirpath, dirnames, filenames in walk:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dirpaths.append(os.path.join(dirpath, dirnames)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters.append(os.path.join(dirpath, filename))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ras_list = ";".join(rasters)&lt;/P&gt;&lt;P&gt;arcpy.MosaicToNewRaster_management(ras_list,workspace,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "test.tif", "", "16_BIT_SIGNED", "", "1", "LAST")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# return SA license&lt;/P&gt;&lt;P&gt;arcpy.CheckInExtension("Spatial")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Mar 2016 11:52:21 GMT</pubDate>
    <dc:creator>DonRaymond</dc:creator>
    <dc:date>2016-03-16T11:52:21Z</dc:date>
    <item>
      <title>Using arcpy.da.Walk to mosaic multiple rasters?</title>
      <link>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41091#M2255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have many hundreds of GeoTiff files to mosaic. The problem is that they are stored in a sub-directory structure whereby I need to traverse down into each sub-directory, mosaic all rasters in that location, and then go back up and down into all the other sub-directories sequentially to perform the same action. Some example directories would appear as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c:\dem\250k\001&amp;nbsp; (do all rasters here)&lt;/P&gt;&lt;P&gt;.............&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \002 (do all rasters here)&lt;/P&gt;&lt;P&gt;.............&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \003 (do all rasters here)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the following Python snippet on the forum, but it finds and mosaics all rasters in all sub-directories to a single output layer. I need to find a way to "walk" into the sub-directories and output a single output for each. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;workspace = r"c:\dem\250k"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rasters = []&lt;/P&gt;&lt;P&gt;walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")&lt;/P&gt;&lt;P&gt;for dirpath, dirnames, filenames in walk:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dirpaths.append(os.path.join(dirpath, dirnames)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters.append(os.path.join(dirpath, filename))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ras_list = ";".join(rasters)&lt;/P&gt;&lt;P&gt;arcpy.MosaicToNewRaster_management(ras_list,workspace,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "test.tif", "", "16_BIT_SIGNED", "", "1", "LAST")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# return SA license&lt;/P&gt;&lt;P&gt;arcpy.CheckInExtension("Spatial")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2016 11:52:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41091#M2255</guid>
      <dc:creator>DonRaymond</dc:creator>
      <dc:date>2016-03-16T11:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.da.Walk to mosaic multiple rasters?</title>
      <link>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41092#M2256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Don,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a an example on how to do this.&amp;nbsp; The below example mosaicks 3 band rasters together in each directory.&amp;nbsp; It outputs a new TIF called 'Mosaic.tif' to each directory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
env.workspace = r"E:\Temp\Python\UserData"


walk = arcpy.da.Walk(env.workspace, topdown=True, datatype="RasterDataset")
for dirpath, dirnames, filenames in walk:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print dirpath
&amp;nbsp;&amp;nbsp;&amp;nbsp; rasterList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in filenames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster = os.path.join(dirpath, file)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasterList.append(raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MosaicToNewRaster_management(rasterList, dirpath, "Mosaic.tif", "", "", "", 3)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:35:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41092#M2256</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T21:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.da.Walk to mosaic multiple rasters?</title>
      <link>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41093#M2257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much for your help, Jake. I will give this a try today.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2016 13:40:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/using-arcpy-da-walk-to-mosaic-multiple-rasters/m-p/41093#M2257</guid>
      <dc:creator>DonRaymond</dc:creator>
      <dc:date>2016-03-16T13:40:09Z</dc:date>
    </item>
  </channel>
</rss>

