2

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?

1 Answer 1

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.

7
  • Nope, looks like that still gives the same error :/
    – Donna
    Apr 18, 2013 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, 2013 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, 2013 at 0:16
  • 1
    Is this code behind a Toolbox tool? Sounds like it. Try setting the inRaster datatype to Raster Dataset. Apr 18, 2013 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, 2013 at 0:41

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.