2

I have national woody vegetation raster files for Australia for years between 1988-2017. These files are separated into spatial tiles with the same name. So, what I would like to do is combine raster files with the same name together. Here is my code:

import os, arcpy

workspace  = r"C:\Users\lawtond\Rasters\Woody"
list_raster= [] # the list must exist before you can append
walk       = arcpy.da.Walk(workspace, type="GRID")
output_location  = r"C:\Users\lawtond\Rasters\Woody"

for dirpath, dirnames, filenames in walk:
    for file in filenames:
        if "woody13" in file.lower():
            list_raster.append(os.path.join(dirpath,file)) # FULL path to each raster

print (list_raster)

arcpy.MosaicToNewRaster_management (list_raster, output_location, "merged_woody_2013.tif","1", "FIRST")

However I get the following error:

Message File Name   Line    Position    
Traceback               
    <module>    <module3>   18      
    MosaicToNewRaster   C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py 13191       
ExecuteError: ERROR 000622: Failed to execute (Mosaic To New Raster). Parameters are not valid.
ERROR 000628: Cannot set input into parameter coordinate_system_for_the_raster.

What am I doing wrong here?

  • Where does new_list_raster come from? It should be list_raster. Note: Python is a case sensitive language, woody is not the same as Woody so I suggest if 'woody13' in file.lower(): list_raster.append(os.path.join(path,file)) may serve your needs better. – Michael Stimson Jul 19 '18 at 6:01
  • @MichaelStimson Sorry, I uploaded the wrong code. It is fixed now. – Douglas Jul 19 '18 at 6:01
  • Still, I think your biggest problem is that you're only appending the file, you need to append the os.path.join(dirpath,file) to the list so the processor can find each raster when you're done. – Michael Stimson Jul 19 '18 at 6:05
  • 1
    It looks like the error stems from the order of your arguments in the MosaicToNewRaster_management function. The 3rd argument is "1" which is not a valid coordinate system parameter. Try: arcpy.MosaicToNewRaster_management (list_raster, output_location, "merged_woody_2013.tif", "","", "", "1", "FIRST", "") – Alex P Jul 19 '18 at 6:22
  • 2
    @AlexP that worked! I'll make a note of that for my future coding endeavors. – Douglas Jul 19 '18 at 6:29
1

It looks like the error stems from the order of your arguments in the MosaicToNewRaster_management() function. The 3rd argument is "1" which is not a valid coordinate system parameter. Try the following code:

arcpy.MosaicToNewRaster_management (list_raster, output_location, "merged_woody_2013.tif", "","", "", "1", "FIRST", "")
2

I like the way you've built a list and then fed it into your GP tool, building a list is fast. As I indicated in my comment you need to have the FULL path to the raster in your list for it to be useful, your mosaic to new dataset can't find each input raster (the list will look like ['woody13','woody13','woody13'..]) which doesn't help. Try it this way:

import os, arcpy

workspace  = r"C:\Users\lawtond\Rasters\Woody"
list_raster= [] # the list must exist before you can append
walk       = arcpy.da.Walk(workspace, type="GRID")
output_location  = r"C:\Users\lawtond\Rasters\Woody"

for dirpath, dirnames, filenames in walk:
    for file in filenames:
        if "woody13" in file.lower():
            list_raster.append(os.path.join(dirpath,file)) # FULL path to each raster

arcpy.MosaicToNewRaster_management (list_raster, output_location, "merged_woody_2013.tif","1", "FIRST")
  • I added the list_raster = [] to the code and still receive the same error. – Douglas Jul 19 '18 at 6:13
  • I have updated the code. – Douglas Jul 19 '18 at 6:15
  • Do these GRIDs have coordinate systems defined? If not what coordinate system are they in? What do you see when the list_raster is printed (not the whole text, just a few items). Are your inputs truly GRID? – Michael Stimson Jul 19 '18 at 6:15
  • Yes, they are in GCS_GDA_1994 – Douglas Jul 19 '18 at 6:17

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.