Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Below I have a snippet of a much larger code that I cannot get to work and I am not sure why. It seems that I always have trouble using arcpy functions with rasters. Can anyone help me get this code to work? Thanks!

outpath = 'G:\\PROJECTS\\Cedar\\Environmental\\FEMA\\Results\\Processing.gdb'
arcpy.env.workspace = outpath

# List the relative elevation rasters in gdb and Mosiac
rasters = arcpy.ListRasters('Rel_elv*')
arcpy.MosaicToNewRaster_management(rasters, outpath, 'Relative')

I have tried all sorts of different ways to do this and the mosiac to new raster function does not seem to like my list.

share|improve this question
2  
What error message are you seeing from the code? If you include that in your question it may encourage people to help. –  PolyGeo Sep 3 '12 at 2:01
add comment

2 Answers 2

I've just been reading about ValueTable and this may be what you need.

"A value table is a flexible object that can be used as input for a multivalue parameter."

The code below is untested.

outpath = 'G:\\PROJECTS\\Cedar\\Environmental\\FEMA\\Results\\Processing.gdb'  
arcpy.env.workspace = outpath  # List the relative elevation rasters in gdb and Mosiac rasters 
arcpy.ListRasters('Rel_elv*')  
vtab = arcpy.ValueTable(1)
for raster in rasters:
    vtab.addRow(raster)
arcpy.MosaicToNewRaster_management(vtab, outpath, 'Relative')
share|improve this answer
2  
This should work. Technically the input required is a string of raster layer names separated by a semicolon ;, which is the output of the string representation of the ValueTable. otherwise at a push you could use list.join(";") to get the same result. FYI, in other tools in the case of an actual table input with >1 columns, columns are separated by spaces, rows by semicolons. –  om_henners Sep 3 '12 at 3:27
    
Thank you for sharing this information with me. I was not aware of the Value Table function. I was able to figure out that I had just missed a parameter for that function in my syntax, which is why my original code did not work. This will be very useful for me in the future! –  crmackey Sep 4 '12 at 13:40
add comment
up vote 1 down vote accepted

I figured out what the problem was...I did not read the tool help too closely the first time. It was not working because the number of bands was not an optional parameter. Once I filled it in my original code worked.

This worked:

    outpath = 'G:\\PROJECTS\\Cedar\\Environmental\\FEMA\\Results\\Processing.gdb'
arcpy.env.workspace = outpath

# List the relative elevation rasters in gdb and Mosiac
rasters = arcpy.ListRasters('Rel_elv*')
rcpy.MosaicToNewRaster_management(rasters, outpath, "Relative",
                                                  "", "32_BIT_FLOAT", "", 1, "LAST","FIRST")
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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