I want to divide every cell of a raster by the raster's maximum cell value using ArcPy. Here is what I have done so far.

densityRaster = LineDensity(shapefileName, None, "", "", "")
maxVal = arcpy.GetRasterProperties_management(densityRaster ,"MAXIMUM")
normalRaster = densityRaster/maxVal #maxValue i get is 5.66

This gives me an error described below. Anybody has clues to where I get it wrong?

Runtime error : ERROR 000732: Input Raster: Dataset 5.666 does not exist or is not supported

If I enter normalRaster = densityRaster/5.666, I get the correct result.

  • 1
    On a side note, you should be able to get the maximum value by accessing the maximum property from your densityRaster since it's a raster object. – dmahr Jun 27 '13 at 13:41
  • @dmahr - nice tip! i would try that..i have just put my feet into arcpy :) – vinayan Jun 28 '13 at 11:43

If you look at type(maxVal), you'll notice that it's neither a number or string. As a matter of fact, it is a ArcPy result object.

In order to extract that information use .getOutput(0). You can cast it to whatever type (int,float,etc) if you want as well.

  • 1
    you are damn right! i didn't check the type..i can get it to work with float(maxVal[0]) now.. – vinayan Jun 26 '13 at 18:29
  • +1 I didn't know it could be accessed like that actually. I thought you had to use .getOutput(0). Honestly, I don't know why some tools return a result object and not just the actual result. – Paul Jun 26 '13 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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