I am trying to batch mosaic rasters using arcpy.MosaicToNewRaster_management in arcpy:
#This is for mosaicking a lot of rasters import arcpy from arcpy import env arcpy.CheckOutExtension("Spatial") env.overwriteOutput = True #Set the current workspace env.workspace = r"C:\thesis\for_sampling\sampling_outputs\new_loss" env.nodata = "MINIMUM" env.compression = "LZ77" coordinate_system = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],\ #UNIT["Degree",0.0174532925199433],AUTHORITY["EPSG",4326]]' 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.tif","Palawan_losss.tif","Negros_Panay_loss.tif","Mindanao_loss.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!"The error talks about coordinate systems. I've tried to use "GCS_WGS_1984.prj" bu it didn't work. I also put that .prj file into the current workspace, still the same error:
arcpy.MosaicToNewRaster_management(list_all_rasters[raster], r"C:\thesis\for_sampling\sampling_outputs" , output_list[raster], 1, coordinate_system) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 11613, in MosaicToNewRasterraise e 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. I also tried to change the variable: coordinate_system = arcpy.SpatialReference(4326), but the error persists.
أكثر...
#This is for mosaicking a lot of rasters import arcpy from arcpy import env arcpy.CheckOutExtension("Spatial") env.overwriteOutput = True #Set the current workspace env.workspace = r"C:\thesis\for_sampling\sampling_outputs\new_loss" env.nodata = "MINIMUM" env.compression = "LZ77" coordinate_system = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],\ #UNIT["Degree",0.0174532925199433],AUTHORITY["EPSG",4326]]' 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.tif","Palawan_losss.tif","Negros_Panay_loss.tif","Mindanao_loss.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!"The error talks about coordinate systems. I've tried to use "GCS_WGS_1984.prj" bu it didn't work. I also put that .prj file into the current workspace, still the same error:
arcpy.MosaicToNewRaster_management(list_all_rasters[raster], r"C:\thesis\for_sampling\sampling_outputs" , output_list[raster], 1, coordinate_system) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 11613, in MosaicToNewRasterraise e 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. I also tried to change the variable: coordinate_system = arcpy.SpatialReference(4326), but the error persists.
أكثر...