Thursday, 20 October 2016

arcgis 10.0 - Unable to Provide Input for a MultiValue Parameter Script Tool


I have the following script:


#Import ArcPy site package
import arcpy
from arcpy import env
from arcpy import Raster

from arcpy.sa import ZonalStatistics
from arcpy.sa import CreateConstantRaster

# Set Environment Workspace
ws = env.workspace = "MY_WORKSPACE_PATH\\FGD.gdb"
# Set Environment Raster Cell Size
env.cellSize = 10

# Check out ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")


# Get Parameters as Text
rasters = arcpy.GetParameterAsText(0)
inputRasters = rasters.split(";")
inZoneData = arcpy.GetParameterAsText(1)
zoneField = arcpy.GetParameterAsText(2)

# The constant raster = 0
addedRaster = CreateConstantRaster(0)


# Process each raster string
for raster in inputRasters:
addedRaster = addedRaster + Raster(ws + "\\" + raster)

# Execute Zonal Statistics
zoneStats = ZonalStatistics(inZoneData, zoneField, addedRaster, "MAXIMUM", "DATA")

# Save the output
zoneStats.save(ws + "\\" + NewTest_12102011")


I have imported the script as a script tool in ArcMap, my parameters are in the correct order and have the correct attributes (this script works when I have, for example, just two raster inputs as parameters). The input rasters are referenced as a String (this tool will eventually be used as a Geoprocessing Task, so I cannot use rasters a input directly). The problem I have is that when I open the tool, there is no way for me to input anything into the first parameter.


enter image description here


To provide some clarity: each value that could be entered into the parameter would be the name of a raster inside the geodatabase. For instance, say the user enters "rasterOne" and "rasterTwo". This would refer to MY_WORKSPACE_PATH\FGD.gdc\rasterOne and MY_WORKSPACE_PATH\FGD.gdc\rasterTwo, which are then cast to a Raster object with


Raster("MY_WORKSPACE_PATH\\FGD.gdc\\rasterOne")

Any suggestions would be great. Thanks.



Answer



I have found the following workflow to work:



  1. Create a model and drag my script tool into it.


  2. Create a variable, and check the "Multivalue" checkbox.

  3. Link the variable and the script tool with the connector tool, and choose for it to be a parameter from the script tool, i.e. in my case a string of rasters


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...