Select to view content in your preferred language

mosaic dataset update with arcpy

421
0
09-01-2022 12:16 AM
bogdanpalade2
Regular Contributor

Hi all,

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:

  • When I first add the rasters to the mosaic dataset, everything works fine
  • 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.

Do you have any idea of whats happening with my code?

Here it is:

 

 

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")

 

0 Kudos
0 Replies