<?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: Create Time Field in Raster Mosaic in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548995#M42875</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; &amp;nbsp; #set the mosaic dataset &amp;nbsp; ws_mosaic = r'C:\MyFolder\MyGDB.gdb\MosaicDS' &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; # add the date field &amp;nbsp; arcpy.AddField_management (ws_mosaic, "_calcDate", "DATE") &amp;nbsp; print "Date field added"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; # calcuate the date field &amp;nbsp; ras = str(ws_mosaic) &amp;nbsp; fld = "_calcDate" &amp;nbsp; cursor = arcpy.UpdateCursor(ras, '', '', '', 'Name')&amp;nbsp;&amp;nbsp; &amp;nbsp; # in this case, the actual date to start from was not important &amp;nbsp; startDate = datetime.datetime(1901,1,1) &amp;nbsp; step = datetime.timedelta(days=1) &amp;nbsp; d = startDate&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; # now populate the date field &amp;nbsp; for row in cursor:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retVal = datetime.datetime.strptime(str(d), '%Y-%m-%d %H:%M:%S') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fld, retVal) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row) &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d += step &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Dec 2013 11:44:12 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2013-12-20T11:44:12Z</dc:date>
    <item>
      <title>Create Time Field in Raster Mosaic</title>
      <link>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548993#M42873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greeting,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a Raster Mosaic in a geodatabase of daily groundwater surfaces.&amp;nbsp; I've come across a web page that explains how to insert a time field in the Raster Mosaic in ArcMap.&amp;nbsp; But, I'd really like to do the process automatically in Arcpy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know the Arcpy steps for doing this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California Department of Water Resources&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 09:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548993#M42873</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2013-12-20T09:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create Time Field in Raster Mosaic</title>
      <link>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548994#M42874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jonathan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Essentially all you will need to do is add a field to your mosaic dataset and calcualte the desired date.&amp;nbsp; Is your mosaic dataset updated on a daily basis with new raster imagery?&amp;nbsp; Can you describe was steps you would like to automate?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 09:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548994#M42874</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-12-20T09:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create Time Field in Raster Mosaic</title>
      <link>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548995#M42875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; &amp;nbsp; #set the mosaic dataset &amp;nbsp; ws_mosaic = r'C:\MyFolder\MyGDB.gdb\MosaicDS' &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; # add the date field &amp;nbsp; arcpy.AddField_management (ws_mosaic, "_calcDate", "DATE") &amp;nbsp; print "Date field added"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; # calcuate the date field &amp;nbsp; ras = str(ws_mosaic) &amp;nbsp; fld = "_calcDate" &amp;nbsp; cursor = arcpy.UpdateCursor(ras, '', '', '', 'Name')&amp;nbsp;&amp;nbsp; &amp;nbsp; # in this case, the actual date to start from was not important &amp;nbsp; startDate = datetime.datetime(1901,1,1) &amp;nbsp; step = datetime.timedelta(days=1) &amp;nbsp; d = startDate&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; # now populate the date field &amp;nbsp; for row in cursor:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retVal = datetime.datetime.strptime(str(d), '%Y-%m-%d %H:%M:%S') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fld, retVal) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row) &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d += step &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 11:44:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548995#M42875</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-12-20T11:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create Time Field in Raster Mosaic</title>
      <link>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548996#M42876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much for showing me how to do this!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a Raster Mosaic Dataset within a geodatabase of groundwater surfaces.&amp;nbsp; They are named as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GWSurface_20130701&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GWSurface_20130702&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GWSurface_20130731&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I modified my code to add a field name (called "SurfaceDate") to my Raster Mosaic Dataset table, then looped through the table and updated the SurfaceDate field with the last 8 characters of the surface name.&amp;nbsp; Works great!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California Department of Water Resources&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;##Create Raster Mosaic Dataset to contain Surfaces.
print "Creating Surfaces Raster Dataset."
FeatureDatasetName = "Surfaces"
arcpy.CreateMosaicDataset_management(OutDatasetPath,FeatureDatasetName,Spatial_Reference)
##Add an 8 character Text field to hold Date as YYYYMMDD.
RasterDatasetLocation = os.path.join(OutFolderPath,GeoDatabaseName,"Surfaces")
arcpy.AddField_management(RasterDatasetLocation, "SurfaceDate","Text","","",8)

DateStart = date(2013,7,1)
DateEnd = date(2013,7,31)
for dt in rrule(DAILY, dtstart=DateStart, until=DateEnd):

&amp;nbsp;&amp;nbsp;&amp;nbsp; ##Do lots of processing in this loop.

##Populate Raster Mosaic Table with Dates.
arcpy.env.workspace = os.path.join(OutFolderPath,GeoDatabaseName,"Surfaces")
ras = str(os.path.join(OutFolderPath,GeoDatabaseName,"Surfaces"))
flds = ["Name","SurfaceDate"]
cursor = arcpy.da.UpdateCursor(ras,flds)
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; RasterName = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; DateString = RasterName[-8:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = DateString
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
print "Contours Completed."&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-time-field-in-raster-mosaic/m-p/548996#M42876</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2021-12-11T23:44:54Z</dc:date>
    </item>
  </channel>
</rss>

