1

This is just a continuation of my former post:Batch Mosaic Rasters: arcpy.MosaicToNewRaster_management (ERROR 000628: Cannot set input into parameter coordinate_system_for_the_raster) --where I batch process mosaic rasters using arcpy.MosaicToNewRaster_management. The first file from the "list_all_rasters" has been successfully processed but the next file was not. Pretty weird, since all of my input rasters have the same number of bands and other properties.

This is my code:

   #This is for mosaicing rasters
   import arcpy
   from arcpy import env
   env.overwriteOutput = True

   #Set the current workspace and other env 't variables
   env.workspace = r"C:\thesis\for_sampling\sampling_outputs\new_loss"
   env.nodata = "MINIMUM"
   env.compression = "LZ77"

   list_all_rasters = ["newlossGreater_Luzonforests_onlyloss_20N_120E.tif;newlossGreater_Luzonforests_onlyloss_30N_120E.tif;\
newlossGreater_Luzonforests_onlyloss_20N_110E.tif","newlossGreater_Palawanforests_onlyloss_20N_120E.tif;\
newlossGreater_Palawanforests_onlyloss_10N_110E.tif;\newlossGreater_Palawanforests_onlyloss_20N_110E.tif",\
"newlossGreater_Negros_Panayforests_onlyloss_10N_120E.tif;newlossGreater_Negros_Panayforests_onlyloss_10N_110E.tif",\
"newlossGreater_Mindanaoforests_onlyloss_10N_120E.tif;newlossGreater_Mindanaoforests_onlyloss_10N_110E.tif;\
newlossGreater_Mindanaoforests_onlyloss_20N_110E.tif"]

   output_list = ["Luzon_loss_try.tif","Palawan_loss_try.tif","Negros_Panay_loss_try.tif","Mindanao_loss_try.tif"]

   for raster in range(0,3):
       env.workspace = r"C:\thesis\for_sampling\sampling_outputs\new_loss"
       print raster # checking the list
       arcpy.MosaicToNewRaster_management(list_all_rasters[raster], r"C:\thesis\for_sampling\sampling_outputs", \
                                   output_list[raster], "GCS_WGS_1984.prj", "1_BIT", "0.00025", 1)   


   print "Finish all of them!"

And this is the error message:

   ExecuteError: Failed to execute. Parameters are not valid.
   ERROR 000157: Input and target dataset should have the same number of bands
   Failed to execute (MosaicToNewRaster).

I'm pretty sure that that my input files are set to have the same number bands with my output files ( which is 1, in this case). I've double checked my files, and all of them are not corrupted.

1

First ensure that the input and target raster contain the same number of bands.

pixel_type (1_BIT)

  • You must set the pixel type to match your existing input raster datasets. If you do not set the pixel type, the 8-bit default will be used and your output may be incorrect.

I suggest to run this tool from GUI (ArcMAP) and after a successful run, extract the proper parameters, and then continue with batch processing.

Some points about your code:

  • You don't have to set env.workspace in each iteration! you have already set it at the beginning of your code.

  • Your input and output list contains 4 elements but your loop iterates from 0 to 2 (only 3 elements)

Correct Code:

for raster in range(0,4):
   print list_all_rasters[raster] # checking the list
   arcpy.MosaicToNewRaster_management(list_all_rasters[raster], r"C:\thesis\for_sampling\sampling_outputs",output_list[raster], "GCS_WGS_1984.prj", "1_BIT", "0.00025", 1)
  • I remove the back slash on my list_all_rasters, change my range as you advised and it worked! – brentiemapper May 22 '15 at 13:11

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.