1

I can't seem to get the mosaic created for this.

 import arcpy

 arcpy.env.workspace = r"C:\projectTemp\FloodAnalysis\output\2yr\raster"
 arcpy.env.overwriteOutput = True
 srName = r"C:\projectTemp\FloodAnalysis\output\2yr\raster"
 outPut = r"C:\projectTemp\FloodAnalysis\output\2yr"
 rasterName = "2ft.img"
 bands = 1
 method = "First"
 clMap = "First"

 arcpy.MosaicToNewRaster_management(srName, outPut, rasterName, "", "", "", bands,      "First", "First")
  • 1
    so what happens? nothing? error? empty output? – Roland Jan 29 '14 at 21:54
3

You have to enter the parameters in the correct order when using Python. From the ArcGIS 10.2 help page, the following is the correct format:

MosaicToNewRaster_management (input_rasters, output_location, raster_dataset_name_with_extension, {coordinate_system_for_the_raster}, {pixel_type}, {cellsize}, number_of_bands, {mosaic_method}, {mosaic_colormap_mode})

Usually, you bring a list of rasters in the following type of comma-separated list:

[inputRasters, ...]

You can use arcpy.ListRasters() to produce a list of all of the rasters in your workspace that you would like to mosaic:

arcpy.env.workspace = r"C:\projectTemp\FloodAnalysis\output\2yr\raster"
rasters = arcpy.ListRasters()

And to put it all together (In this untested script):

import arcpy

arcpy.env.workspace = r"C:\projectTemp\FloodAnalysis\output\2yr\raster"
arcpy.env.overwriteOutput = True

# Local Variables
outPut = r"C:\projectTemp\FloodAnalysis\output\2yr"
name = "yourOutput.img"
"""Note, there are multiple ways to define a spatial reference,
here I am pointing to a .prj"""
sr = r"C:\path\to\prj\file.prj"
bands = 1
method = "First"
clMap = "First"

# Create raster list
rasters = arcpy.ListRasters()

arcpy.MosaicToNewRaster_management(rasters, outPut, name, sr, "", "", bands, method, clMap)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.