divide tool

839
4
Jump to solution
06-23-2014 02:12 PM
mohamadbakhtiari
New Contributor
Hi everyone
I want to build a toolset by using add a script that before I had provided in Pythonwin, this tool divide one raster by maximum value from that raster for normalization it. I found that by command arcpy.getParameterAsText(), we can give flexibility to toolset for introducing parameters. but in case Divide operation, we only can introduce raster1 or constant1 and raster2 or constant2 and I don't know determine name and path of output using arcpy.getParameterAsText() like operations of Buffer, clip and so on. I look forward for your helpful answers. Meanwhile I pasted the script as follows.
Thank you

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True

    # Get the input parameters for
inPath = arcpy.GetParameterAsText(0)
constant = arcpy.GetParameterAsText(1)
    #outPath = arcpy.GetParameterAsText(2)
    #bufferDistance = arcpy.GetParameterAsText(2)

    # Run the Buffer tool
Divide(inPath,constant)
    #env.workspace = outPath

    # Report a success message   
arcpy.AddMessage("All done!")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
Use the Raster class to create a Raster object from your input filename.

Try:
import arcpy from arcpy import env from arcpy.sa import * import os arcpy.env.overwriteOutput = True  # Get the input parameters for  inPath = arcpy.GetParameterAsText(0) constant = int(arcpy.GetParameterAsText(1)) #convert to integer outPath = arcpy.GetParameterAsText(2)  # Run the Divide tool result = Divide(Raster(inPath),constant) result.save(os.path.join(outPath, "someraster"))  # Report a success message     arcpy.AddMessage("All done!")

View solution in original post

0 Kudos
4 Replies
Luke_Pinner
MVP Regular Contributor
Use the Raster class to create a Raster object from your input filename.

Try:
import arcpy from arcpy import env from arcpy.sa import * import os arcpy.env.overwriteOutput = True  # Get the input parameters for  inPath = arcpy.GetParameterAsText(0) constant = int(arcpy.GetParameterAsText(1)) #convert to integer outPath = arcpy.GetParameterAsText(2)  # Run the Divide tool result = Divide(Raster(inPath),constant) result.save(os.path.join(outPath, "someraster"))  # Report a success message     arcpy.AddMessage("All done!")
0 Kudos
mohamadbakhtiari
New Contributor
Hi lpinner
thank you, I tested you code in the toolset but when a number (with Double type) introduced for division rater by it, that doesn't work and the error message was " ERROR 000732: Input Raster: Dataset 7 does not exist or is not supported Failed to execute (Script)". then I introduced a raster (with Raster layer type). Unfortunately again it wasnot work. the error message is: "ERROR 000875: Output raster: I:\Session7\gt\someraster's workspace is an invalid output workspace.". I don't know what do. I plan to do this task about Fuzzy membership and Weighted sum.
please help me.
regards
Mohsen
0 Kudos
mohamadbakhtiari
New Contributor
Hi lpinner
Thank you, I again tried your code of course with a little change and  fortunately this time it was work. I remove the "someraster" from method of save and the result aw OK. I plan to do this work about about Fuzzy membership and Weighted sum with 5 layer. can you help me about these?
Regard
Mohsen
0 Kudos
Luke_Pinner
MVP Regular Contributor
Thank you, I again tried your code of course with a little change and  fortunately this time it was work.
That's good. Please click the check mark next to my post to indicate it answered your question.

I plan to do this work about about Fuzzy membership and Weighted sum with 5 layer. can you help me about these?
You should start a new thread with your new question.
0 Kudos