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.

I'm trying to write a script that will, in part, calculate statistics for a raster layer in an Arcmap mxd, but when I run the script I get an "invalid parameter" error (Error 000840), saying that the value isn't a Mosaic Layer, Mosaic Catalog, or Raster Catalog. The Calculate Statistics tool in the toolbox works fine for a single raster, so I'm not sure how to fix this. Relevant code block:

import arcpy
inRaster = arcpy.GetParameterAsText(0)
arcpy.CalculateStatistics_management(inRaster, "1", "1", "-9999")

Any suggestions?

share|improve this question
add comment

1 Answer 1

Try using inRaster = arcpy.GetParameter(0) instead, I think it wants the raster object and not the text string, which is arcpy.GetParameterAsText(0) is giving you.

share|improve this answer
    
Nope, looks like that still gives the same error :/ –  Donna Apr 18 '13 at 0:05
    
The online help suggests to me that it is expecting a text string. Perhaps @Donna should just use arcpy.AddMessage and/or print to see what inRaster has been set to. Maybe that is not actually a valid Mosaic Layer, Mosaic Catalog, or Raster Catalog. Also, has the script been added behind a tool? –  PolyGeo Apr 18 '13 at 0:09
    
Okay, just looked at that...it stores just the raster name but not the complete path as help shown in the help. The inRaster data type is set to Raster Layer; is there a way to extract the full path from that? –  Donna Apr 18 '13 at 0:16
1  
Is this code behind a Toolbox tool? Sounds like it. Try setting the inRaster datatype to Raster Dataset. –  Chad Cooper Apr 18 '13 at 0:26
    
Yeah, it's a script tool within a toolbox. Changing the inRaster type does fix the Calculate Statistics problem - but then my next step is applying additional symbology from a template layer using arcpy.ApplySymbologyFromLayer_management, and it's saying that the input layer (inRaster) doesn't exist or isn't supported...maybe because it's now referencing the file directly rather than the layer in my mxd? –  Donna Apr 18 '13 at 0:41
show 2 more comments

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.