makeRasterLayer_management

474
4
04-14-2012 04:19 AM
thomsh
by
New Contributor
Hello

im sitting over a probably simple problem since hours, but somehow i cant solve the problem

Im converting ascii to esri rasters in a separte Method (core of this method): this works fine
    arcpy.env.workspace = resultsPath
    arcpy.ASCIIToRaster_conversion(inRaster, outRaster, "FLOAT")


in another method, im trying to make Rasters and later .lyr files out of those created rasters:
def addRammsFiles(mxd, nameR):
    arcpy.env.workspace= targetPath
    for files in arcpy.ListRasters():
            rasterName = arcpy.Describe(files).name
            rasterPath = targetPath + "/" + rasterName
            arcpy.MakeRasterLayer_management(rasterPath , rasterName)
            #arcpy.SaveToLayerFile_management(rasterName, rasterPath + ".lyr")

Im always getting the Error 00582: Error occured during excecution. (The name of the raster is < 13)
Does someone have an idea why it doesnt work (it worked previously, with rasters from featureToRaster)

help would be DEEPLY appreciated!

qet
Tags (2)
0 Kudos
4 Replies
curtvprice
MVP Esteemed Contributor
You probably want to use catalogPath instead of name. You also want to strip off any extensions on the input raster name so the .lyr file name will be valid:

import os
arcpy.env.workspace = targetPath
for files in arcpy.ListRasters():
    rasterPath = arcpy.Describe(files).catalogPath
    arcpy.MakeRasterLayer_management(rasterPath , "lyrRaster")
    arcpy.SaveToLayerFile_management("lyrRaster", 
        os.path.splitext(rasterPath)[0] + ".lyr")
0 Kudos
thomsh
by
New Contributor
Thx a lot! now it works 🙂
perfect idea!

one more (and hopefully last) question - why is it not possible to put a parameter to the MakeRasterLayer_management out_rasterlayer field:

for example:
rasterPath = arcpy.Describe(files).catalogPath
rasterName = "test"
arcpy.MakeRasterLayer_management(rasterPath, rasterName)


(i get this same Execution error 000582)

greetings,
qet
0 Kudos
curtvprice
MVP Esteemed Contributor
one more (and hopefully last) question - why is it not possible to put a parameter to the MakeRasterLayer_management out_rasterlayer field:

for example:
rasterPath = arcpy.Describe(files).catalogPath
rasterName = "test"
arcpy.MakeRasterLayer_management(rasterPath, rasterName)

i get this same Execution error 000582)
[000582 : Error occurred during execution.]


I don't know why it's failing for you. This has always worked for me. In fact I usually do it that way... are you sure that's where your script is failing?

000582 is an extremely generic error. Did you get another error message as well?
0 Kudos
thomsh
by
New Contributor
yes im sure - and i also worked for me in previous scripts...

thx for ur answers, guess i will have to try and error a bit more 🙂

qet
0 Kudos