I'm trying to execute a script that will create a mosaic dataset that includes Landsat imagery and I keep running into this error. I'm fairly new at writing Python scripts, so I'm sure I'm just missing something small, but I honestly cannot figure this one out after searching around a lot for a fix. My code is below:

# Imports
import arcpy
import os
from arcpy import env
env.overwriteOutput = True

# Define Variables
image_dir = r"E:\GIS 4090\Week 11\In Class Exercises\Data\Landsat_p114r75"
output_gdb = r"E:\GIS 4090\Week 11\In Class Exercises\Results\Challenge.gdb"
mosaic_name = "Multispectral"

arcpy.env.workspace = image_dir
image_list = arcpy.ListRasters()

# Create File Geodatabase
# Use os to get the output_gdb+dir ad output_gdb_name from output_gdb.
output_gdb_dir = os.path.dirname(output_gdb)
output_gdb_name = os.path.basename(output_gdb)
if arcpy.Exists(output_gdb) != True:
    arcpy.CreateFileGDB_management(output_gdb_dir, output_gdb_name)
    print("File Geodatabase exists!")

# Create Mosaic Dataset
# Tool help at http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-mosaic-dataset.htm
projection = arcpy.SpatialReference(32750)
arcpy.CreateMosaicDataset_management(output_gdb, mosaic_name, projection)
print("Mosaic Dataset created.")

# Add rasters to mosaic dataset
# Use os.path.join to create the "path_to_mosaic" variable
# http://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-rasters-to-mosaic-dataset.htm
rasttype = "Landsat 7 ETM+"
updatecs = "UPDATE_CELL_SIZES"
updatebnd = "UPDATE_BOUNDARY"
updateovr = "UPDATE_OVERVIEWS"
buildpyr = "BUILD_PYRAMIDS"
buildthumbs = "BUILD_THUMBNAILS"
opdesc = "6 band Landsat imagery for analysis"
path_to_mosaic = os.path.join(output_gdb, mosaic_name)
arcpy.AddRastersToMosaicDataset_management(path_to_mosaic, rasttype, image_list, \
updatecs, updatebnd, updateovr, buildpyr, calcstats, buildthumbs, opdesc)
print("Rasters added to mosaic.")

# Not sure if the following code section is needed:

#Calculate Statistics on Mosaic Dataset
skip_factor_x = "5"
skip_factor_y = "5"
arcpy.CalculateStatistics_management(os.path.join(output_gdb, mosaic_name), \
skip_factor_x, skip_factor_y)
print("Statistics Calculated.")

  • 1
    Your parameters are skipping a few values, where you have buildpyr is looking for a number not a string. To skip optional parameters you need to tell the tool what the parameter you're setting is: arcpy.AddRastersToMosaicDataset_management(path_to_mosaic, rasttype, image_list, updatecs, updatebnd, updateovr, build_pyramids=buildpyr, calculate_statistics=calcstats, build_thumbnails=buildthumbs, operation_description=opdesc) - everything is normal until update_overviews but then you jump straight to build_pyramids, skipping 7 optional parameters which will take their default value. Apr 10, 2018 at 22:22
  • There appears to be much more than a code snippet here. Try taking code out to see if you can create one that still shows the error.
    – PolyGeo
    Apr 17, 2018 at 9:16