ERROR 000628: Cannot set input into parameter coordinate_system_for_the_raster

12253
4
05-21-2015 11:02 PM
RobertBeno
New Contributor

I am trying to batch mosaic rasters using arcpy.MosaicToNewRaster_management in arcpy:

 

#This is for mosaicking rasters
import arcpy
from arcpy import env

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

projection = arcpy.SpatialReference(4326) 

coordinate_system =  projection

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

for raster in  range(0,4):
    output_list = ["Luzon_loss.tif","Palawan_losss.tif","Negros_Panay_loss.tif","Mindanao_loss.tif"]
    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], 1, coordinate_system)
    print raster+ " is ok!" 


print "Finish all of them!"

However, I always get this error:

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.

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Is that the coordinate system you want or the coordinate system of the data?  If it is the former, it won't work.  You need to project your data into the coordinate system you want before mosaicing

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Hi Robert,

One issue I can see is that the list_all_raster variable is having issues with the formatting and the continuation lines (and you have a \new.. in the middle and a few too many ").  I'm sure that a half dozen others on this forum will be able to write this code in a cleaner way, but since so much of the long tif file name is the same, you can get the variable set with a simple loop.  If you copy and past this in your code, make sure to check that the forest names and the N and E values pairs are set correctly....and my spelling is correct.

Once the variable is set correctly, try you process again to see if there is another issue.

theList = [["Luzon","20N_120E"], ["Luzon","30N_120E"], ["Luzon","20N_110E"], \
          ["Palawan","20N_120E"], ["Palawan","10N_110E"], ["Palawan","20N_110E"], \
          ["Negros_Panay","10N_120E"], ["Negros_Panay","10N_110E"], \
          ["_Mindanao","10N_120E"], ["_Mindanao","10N_110E"], ["_Mindanao","20N_110E"]]
cnt = 0
for tif in theList:
  if cnt == 0:
      list_all_rasters = "(newlossGreater_" + tif[0] + "forests_onlyloss_" + tif[1] + ".tif"
      cnt += 1
  else:
      list_all_rasters = list_all_rasters + "; newlossGreater_" + tif[0] + "forests_onlyloss_" + tif[1]  + ".tif"
list_all_rasters = list_all_rasters + ")"
print list_all_rasters

The cnt == 0 is to make sure the ( with no ; at the front.  That way each of the following tifs in the list start with the ;

Once you exit the for statement, I add the closing ")"

If you need the full variable wrapped in quotes for the input, you may need to do some slight adjustments.

This may not fix the problem completely, but first things first.  Good luck!

0 Kudos
SepheFox
Frequent Contributor

The error seems to indicate that the syntax used for the parameter is invalid for the parameter type. Looking at the help for setting spatial reference (ArcGIS Desktop), the syntax is supposed to be like this:

# Create a spatial reference object using a factory code

#

sr = arcpy.SpatialReference()

sr.factoryCode = 3857

sr.create()

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Actually I think what he has is ok (I think that's how I usually do it), although I would use the variable name sr like you have, and there is no need to reassign it to a new variable.  ArcGIS Help (10.2, 10.2.1, and 10.2.2)

My guess is the spatial reference error is coming up because the first argument he is using list_all_rasters, is invalid based on how he was creating it.  If he uses my code, or a cleaner version when someone else rewrites is, I think he could then just use " list_all_rasters" as the first argument (and not "list_all_rasters[rasters]").  There still might be an issues with the spatial reference s you mention, but I don't have a chunk of data handy to test it with right now.