<?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 mosaic dataset update with arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/mosaic-dataset-update-with-arcpy/m-p/1208576#M65451</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I try to update a mosaic dataset with arcpy and then populate two fields (AcquisitionDate and Sensor) based on the name of each raster. What I see is the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When I first add the rasters to the mosaic dataset, everything works fine&lt;/LI&gt;&lt;LI&gt;When I repeat the operation (specifying "EXCLUDE_DUPLICATES) I notice that the corresponding two fields of the new rasters are populated correctly, but the old rasters already present in the mosaic have their fields reset to null.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Do you have any idea of whats happening with my code?&lt;/P&gt;&lt;P&gt;Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime
from datetime import datetime

print('Preparing and reading data')

arcpy.env.workspace = r"\\workspace\IMM"
mdname = r"IMM.gdb/land_bgd"
inpath = r"\\workspace\IMM\Base"

print("Building the list of the rasters already present")
rstList=[]
fields = ['Name','AcquisitionDate','Sensor']
with arcpy.da.SearchCursor(mdname, fields) as cursor:
    for row in cursor:
        rstList.append(row[0])
print(rstList)


print('Doing the mosaic')    
arcpy.management.AddRastersToMosaicDataset(mdname, "Raster Dataset", inpath, "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", None, 0, 1500, None, '*.TIF', "NO_SUBFOLDERS", "EXCLUDE_DUPLICATES", "BUILD_PYRAMIDS", "NO_STATISTICS", "NO_THUMBNAILS", '', "NO_FORCE_SPATIAL_REFERENCE", "NO_STATISTICS", None, "NO_PIXEL_CACHE", r"C:\Users\text\AppData\Local\ESRI\rasterproxies\land_bgd")

print('Populating fields')
with arcpy.da.UpdateCursor(mdname, fields) as cursor:
    for row in cursor:
        if row[0]not in rstList:
            acqDate = datetime.strftime(datetime.strptime(row[0].split('_')[0], '%Y%m%d'),'%d/%m/%Y')
            row[1]=acqDate
            row[2]=row[0].split('_')[3]
        cursor.updateRow(row)
del cursor, row
print ("Done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Sep 2022 07:16:47 GMT</pubDate>
    <dc:creator>bogdanpalade2</dc:creator>
    <dc:date>2022-09-01T07:16:47Z</dc:date>
    <item>
      <title>mosaic dataset update with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/mosaic-dataset-update-with-arcpy/m-p/1208576#M65451</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I try to update a mosaic dataset with arcpy and then populate two fields (AcquisitionDate and Sensor) based on the name of each raster. What I see is the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When I first add the rasters to the mosaic dataset, everything works fine&lt;/LI&gt;&lt;LI&gt;When I repeat the operation (specifying "EXCLUDE_DUPLICATES) I notice that the corresponding two fields of the new rasters are populated correctly, but the old rasters already present in the mosaic have their fields reset to null.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Do you have any idea of whats happening with my code?&lt;/P&gt;&lt;P&gt;Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime
from datetime import datetime

print('Preparing and reading data')

arcpy.env.workspace = r"\\workspace\IMM"
mdname = r"IMM.gdb/land_bgd"
inpath = r"\\workspace\IMM\Base"

print("Building the list of the rasters already present")
rstList=[]
fields = ['Name','AcquisitionDate','Sensor']
with arcpy.da.SearchCursor(mdname, fields) as cursor:
    for row in cursor:
        rstList.append(row[0])
print(rstList)


print('Doing the mosaic')    
arcpy.management.AddRastersToMosaicDataset(mdname, "Raster Dataset", inpath, "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", None, 0, 1500, None, '*.TIF', "NO_SUBFOLDERS", "EXCLUDE_DUPLICATES", "BUILD_PYRAMIDS", "NO_STATISTICS", "NO_THUMBNAILS", '', "NO_FORCE_SPATIAL_REFERENCE", "NO_STATISTICS", None, "NO_PIXEL_CACHE", r"C:\Users\text\AppData\Local\ESRI\rasterproxies\land_bgd")

print('Populating fields')
with arcpy.da.UpdateCursor(mdname, fields) as cursor:
    for row in cursor:
        if row[0]not in rstList:
            acqDate = datetime.strftime(datetime.strptime(row[0].split('_')[0], '%Y%m%d'),'%d/%m/%Y')
            row[1]=acqDate
            row[2]=row[0].split('_')[3]
        cursor.updateRow(row)
del cursor, row
print ("Done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 07:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mosaic-dataset-update-with-arcpy/m-p/1208576#M65451</guid>
      <dc:creator>bogdanpalade2</dc:creator>
      <dc:date>2022-09-01T07:16:47Z</dc:date>
    </item>
  </channel>
</rss>

