0

I am mosaicing rasters in arcpy but it is returning the error, AttributeError: 'module' object has no attribute 'MosaictoNewRaster_management'

I am using the code:

import arcpy
from arcpy.sa import *
import os
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension('Spatial')
shfolders=r'F:\Sheyenne\Final_Imagery\For_Moasic\Sheyenne'
vikfolders=r'F:\Sheyenne\Final_Imagery\For_Moasic\Viking'
out=r'F:\Sheyenne\Final_Imagery\For_Moasic\Mosaiced'
for folder in os.listdir(shfolders):
    if not os.path.isdir(os.path.join(out,folder)): 
        os.makedirs(os.path.join(out,folder)) 
    arcpy.env.workspace=os.path.join(shfolders,folder)
    shrasters=arcpy.ListRasters('*.tif')
    for folder in os.listdir(vikfolders):
        arcpy.env.workspace=os.path.join(vikfolders,folder)
        vikrasters=arcpy.ListRasters('*.tif')
    for sh, vik in zip (shrasters,vikrasters):
            arcpy.MosaictoNewRaster_management([sh,vik],out, sh,"PROJCS['NAD_1983_UTM_Zone_14N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-99.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]","16_BIT_UNSIGNED","30","1","LAST","FIRST")
print "Done Mosaicing"

Within shfolders there are 4 folders with 80 .tif files each and within vikfolders there are 4 folders with 80 .tif files each. I am zipping the .tif files between shfolders and vikfolders and mosaicing the zipped files. The problem here seems to be with arcpy not recognizing the tool. I am using anaconda, I am not sure if that matters.

2
  • Can you get the code sample to work, but with a couple of your images? Jul 21, 2016 at 18:30
  • by copying and pasting the python snippet from arcgis when I mosaic just two rasters it does work, so the tool must be available. Jul 21, 2016 at 18:34

2 Answers 2

1

First I would suggest looking at Arcpy.GetMessages() to see if there are some more helpful error messages that arcpy is giving that you aren't seeing.

One big problem that I've run into with MosaictoNewRaster_management is it failing when I am trying to merge too many rasters together which ends in failure when the resulting raster would be too large for its file format. One way to test if this is the case is by using the same syntax that you're currently using on just a few of the rasters that you want to merge to see if it completes.

The suggested way to get past this is to use a mosaic dataset instead which in most instances will work as raster when going through processing. To do this, use AddRastersToMosaicDataset_management.

1
  • I'll look into it, the resulting raster is not too large though. Jul 21, 2016 at 20:23
0

You are receiving that error because the tool is called MosaicToNewRaster and not MosaictoNewRaster.

Python is unforgiving when it comes to correct capitalization of function names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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