Select to view content in your preferred language

Weighted Overlay - passing parameter as text error?

2645
5
Jump to solution
03-25-2014 08:17 AM
NoahHuntington
Deactivated User
For some reason when hardcoding the save path for the wieghted raster just before runtime it works perfectly. Like such...
arcpy.env.cellSize = "90" arcpy.env.workspace = r'G:\Xcel\Route Tool\Potter\Scratch.gdb' landuseRaster = r'G:\Xcel\Route Tool\Potter\Data.gdb\Potter_Randall_Landuse_Raster' slope_Reclass_Raster = r'G:\Xcel\Route Tool\Potter\Scratch.gdb\slope_Reclass'  #Generate a list identifying what the individual input values should be reclassified as. remapLanduse = RemapValue([['Cropland and pasture',2],['Herbaceous Rangeland',1],['Nonforested wetland',10],['Other agricultural land',1],['Strip mines, quarries and gravel pits',2],                             [ 'Mixed rangeland',1],['Lakes',10],['Residential',3],['Commercial and Services',3],['Confined feeding operations',3],['Transportation, communications and services',10],                             ['Transitional areas',3],['Shrub-brushland rangeland',1],['Other urban or built-up land',3],['Bare exposed rock',3],['Industrial',2],['Reservoirs',10],['Forested wetland',10],['Mixed urban or built-up land',3]])  remapSlope = RemapValue([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]])   #Define the input rasters, the field identifying the input values, the remap of their values, the weight of each raster, and the evaluation scale to use in the Weighted Overlay tool. myWOTable = WOTable([[landuseRaster, 80, "LANDUSE", remapLanduse],                      [slope_Reclass_Raster, 20, "Value", remapSlope],                      ], [1, 10, 1])  outWeightedOverlay = WeightedOverlay(myWOTable)  arcpy.AddMessage("Creating weighted raster...") weighted_Raster = env.workspace + '\weighted_Raster' outWeightedOverlay.save(weighted_Raster)


However when I try to pass the workspace to weighted overlay tool using parameter as text I receive a generic 999999 error? Like such....
subs  = arcpy.GetParameterAsText(0) Field = arcpy.GetParameterAsText(1) originValue = arcpy.GetParameterAsText(2) destValue   = arcpy.GetParameterAsText(3) lines = arcpy.GetParameterAsText(4) Dem = arcpy.GetParameterAsText(5) landuseRaster = arcpy.GetParameterAsText(6) outwork = arcpy.GetParameterAsText(7)  arcpy.env.workspace = outwork + "\Scratch.gdb"


.... run a few tools including generate 'slope_Reclass_Raster'
#Generate a list identifying what the individual input values should be reclassified as. remapLanduse = RemapValue([['Cropland and pasture',2],['Herbaceous Rangeland',1],['Nonforested wetland',10],['Other agricultural land',1],['Strip mines, quarries and gravel pits',2],                             [ 'Mixed rangeland',1],['Lakes',10],['Residential',3],['Commercial and Services',3],['Confined feeding operations',3],['Transportation, communications and services',10],                             ['Transitional areas',3],['Shrub-brushland rangeland',1],['Other urban or built-up land',3],['Bare exposed rock',3],['Industrial',2],['Reservoirs',10],['Forested wetland',10],['Mixed urban or built-up land',3]])  remapSlope = RemapValue([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]])   #Define the input rasters, the field identifying the input values, the remap of their values, the weight of each raster, and the evaluation scale to use in the Weighted Overlay tool. myWOTable = WOTable([[landuseRaster, 80, "LANDUSE", remapLanduse],                      [slope_Reclass_Raster, 20, "Value", remapSlope],                      ], [1, 10, 1])  outWeightedOverlay = WeightedOverlay(myWOTable)  arcpy.AddMessage("Creating weighted raster...") weighted_Raster = env.workspace + '\weighted_Raster' outWeightedOverlay.save(weighted_Raster)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NoahHuntington
Deactivated User
Thanks to everyone who chimed in. All very knowledgeable advice. It was indeed an object issue with the slope_Reclass_Raster. Corrected the variable with the following before passing to WOTable. Posting for the archives.
arcpy.AddMessage("Computing slope Reclass...") outSlice = Slice('slope_Raster', 10, "NATURAL_BREAKS") slope_Reclass_Raster = outSlice.save('slope_Reclass') slope_Reclass_Raster = "slope_Reclass"

View solution in original post

0 Kudos
5 Replies
AdamCox1
Deactivated User
I think the issue is you are not escaping the '\' characters when you set the workspace path and when you create the output path string.  You should use r"\Scratch.gdb" or "\\Scratch.gdb" any time you need to construct a path.
0 Kudos
NoahHuntington
Deactivated User
I think the issue is you are not escaping the '\' characters when you set the workspace path and when you create the output path string.  You should use r"\Scratch.gdb" or "\\Scratch.gdb" any time you need to construct a path.


Thanks Adam.  You are right about the filepath.  For some reason this still runs successful in the hardcoded script here.  I have corrected and still produce an error while trying to parse the user file path? I think there may be more at play here?

Success:
arcpy.env.cellSize = "90"
arcpy.env.workspace = r'G:\Xcel\Route Tool\Potter\Scratch.gdb'
landuseRaster = r'G:\Xcel\Route Tool\Potter\Data.gdb\Potter_Randall_Landuse_Raster'
slope_Reclass_Raster = r'G:\Xcel\Route Tool\Potter\Scratch.gdb\slope_Reclass'


#Generate a list identifying what the individual input values should be reclassified as.
remapLanduse = RemapValue([['Cropland and pasture',2],['Herbaceous Rangeland',1],['Nonforested wetland',10],['Other agricultural land',1],['Strip mines, quarries and gravel pits',2],
                            [ 'Mixed rangeland',1],['Lakes',10],['Residential',3],['Commercial and Services',3],['Confined feeding operations',3],['Transportation, communications and services',10],
                            ['Transitional areas',3],['Shrub-brushland rangeland',1],['Other urban or built-up land',3],['Bare exposed rock',3],['Industrial',2],['Reservoirs',10],['Forested wetland',10],['Mixed urban or built-up land',3]])

remapSlope = RemapValue([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]])


#Define the input rasters, the field identifying the input values, the remap of their values, the weight of each raster, and the evaluation scale to use in the Weighted Overlay tool.
myWOTable = WOTable([[landuseRaster, 80, "LANDUSE", remapLanduse],
                     [slope_Reclass_Raster, 20, "Value", remapSlope],
                     ], [1, 10, 1])

outWeightedOverlay = WeightedOverlay(myWOTable)

arcpy.AddMessage("Creating weighted raster...")
outWeightedOverlay = WeightedOverlay(myWOTable)
arcpy.AddMessage("The current workspace is: %s" % env.workspace)
arcpy.AddMessage("Saving weighted raster...")
outWeightedOverlay.save(env.workspace + '\\weighted_Raster')

...and fail
subs  = arcpy.GetParameterAsText(0)
Field = arcpy.GetParameterAsText(1)
originValue = arcpy.GetParameterAsText(2)
destValue   = arcpy.GetParameterAsText(3)
lines = arcpy.GetParameterAsText(4)
Dem = arcpy.GetParameterAsText(5)
landuseRaster = arcpy.GetParameterAsText(6)
outwork = arcpy.GetParameterAsText(7)

#create *.gdb to store scratch intermediate data
arcpy.CreateFileGDB_management(outwork, "Scratch.gdb")
env.workspace = outwork + "\\Scratch.gdb"

...

remapLanduse = RemapValue([['Cropland and pasture',2],['Herbaceous Rangeland',1],['Nonforested wetland',10],['Other agricultural land',1],['Strip mines, quarries and gravel pits',2],
                            [ 'Mixed rangeland',1],['Lakes',10],['Residential',3],['Commercial and Services',3],['Confined feeding operations',3],['Transportation, communications and services',10],
                            ['Transitional areas',3],['Shrub-brushland rangeland',1],['Other urban or built-up land',3],['Bare exposed rock',3],['Industrial',2],['Reservoirs',10],['Forested wetland',10],['Mixed urban or built-up land',3]])

remapSlope = RemapValue([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]])


#Define the input rasters, the field identifying the input values, the remap of their values, the weight of each raster, and the evaluation scale to use in the Weighted Overlay tool.
myWOTable = WOTable([[landuseRaster, 80, "LANDUSE", remapLanduse],
                     [slope_Reclass_Raster, 20, "Value", remapSlope],
                     ], [1, 10, 1])

outWeightedOverlay = WeightedOverlay(myWOTable)

arcpy.AddMessage("Creating weighted raster...")
outWeightedOverlay = WeightedOverlay(myWOTable)
arcpy.AddMessage("The current workspace is: %s" % env.workspace)
arcpy.AddMessage("Saving weighted raster...")
outWeightedOverlay.save(env.workspace + '\\weighted_Raster')
0 Kudos
AdamCox1
Deactivated User
Well, I guess I would just suggest printing all of the parameters when you get them as text at the beginning of the script, and also printing all of the corresponding variables in the hard-coded version.  It sounds like there is some value or object type issue.  Perhaps you are getting something as text that you previously used as an object?  I don't know a whole lot about raster processing, so can't be much more help...
0 Kudos
NoahHuntington
Deactivated User
Well, I guess I would just suggest printing all of the parameters when you get them as text at the beginning of the script, and also printing all of the corresponding variables in the hard-coded version.  It sounds like there is some value or object type issue.  Perhaps you are getting something as text that you previously used as an object?  I don't know a whole lot about raster processing, so can't be much more help...


I think your probably right. This is good advice..  I'll keep looking at it.
0 Kudos
NoahHuntington
Deactivated User
Thanks to everyone who chimed in. All very knowledgeable advice. It was indeed an object issue with the slope_Reclass_Raster. Corrected the variable with the following before passing to WOTable. Posting for the archives.
arcpy.AddMessage("Computing slope Reclass...") outSlice = Slice('slope_Raster', 10, "NATURAL_BREAKS") slope_Reclass_Raster = outSlice.save('slope_Reclass') slope_Reclass_Raster = "slope_Reclass"
0 Kudos