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.
-
Have you ruled out the ListRasters method as shown in the online help topic? help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…user681– user6812011年12月12日 14:56:37 +00:00Commented Dec 12, 2011 at 14:56
-
@DanPatterson I have ruled that out. I don't want to input every raster in the work space/GDB, nor provide a list of available rasters. As mentioned, this will eventually be a Geoprocessing Task running on ArcServer. In a Flex application, a user would select a check box with a corresponding ID attribute. This ID attribute would correspond to a raster in the GDB, say id="rasterOne". This is pushed into an array and provided as a parameter in execute/submitJob. The array might be params = ["rasterOne", "rasterTwo"]. Similar to this example:Baskinomics– Baskinomics2011年12月12日 15:06:23 +00:00Commented Dec 12, 2011 at 15:06
-
@DanPatterson example link: help.arcgis.com/en/webapi/flex/samples/index.html#/…Baskinomics– Baskinomics2011年12月12日 15:07:36 +00:00Commented Dec 12, 2011 at 15:07
-
Not sure about Flex, but in arctoolbox you can provide a Filter option, which defaults to None, if you specify Value List, you could put the names of the rasters in there and they should show in a checklist form (if memory serves).user681– user6812011年12月12日 15:36:57 +00:00Commented Dec 12, 2011 at 15:36
-
1Really frustrating, this is STILL a bug 7 years later at version 10.6!goWithSwagger– goWithSwagger2018年02月16日 19:57:13 +00:00Commented Feb 16, 2018 at 19:57
3 Answers 3
In addition to the above comments, I will show what this simple script and the toolbox with a filter list allows and you can decide if that is the desired outcome. The following script
import arcpy
selected= arcpy.GetParameterAsText(0)
arcpy.AddMessage("\nselected data " + str(selected) + "\n")
was added to a toolbox with one multivalue parameter with values provided to be selected. The following image shows the input stage with 3 string values selected (eg names of input data for example) multivalue selection
The following is the output.
Executing: Multiparameter first;second;third
Start Time: Mon Dec 12 10:57:45 2011
Running script Multiparameter...
selected data first;second;third
Completed script Multiparameter...
Succeeded at Mon Dec 12 10:57:45 2011 (Elapsed Time: 0.00 seconds)
Not sure if that helps, but it might useful for other posts.
-
1+1 Thanks for the visual example. Did you provide the values through the Import Script Tool or in the script itself?\Baskinomics– Baskinomics2011年12月12日 17:27:59 +00:00Commented Dec 12, 2011 at 17:27
-
When defining the tool parameters, the "Filter" option allows you to switch from None to a Value List and you can enter the values there. You may be able to use SetParameterAsText to define them within a script, but I haven't played with that option.user681– user6812011年12月12日 17:52:40 +00:00Commented Dec 12, 2011 at 17:52
-
Your suggestion worked and I found where to input those values. ThanksBaskinomics– Baskinomics2011年12月17日 20:46:12 +00:00Commented Dec 17, 2011 at 20:46
Looks like a bug in arcmap to me. You could just take a single-value string input, comma separated, and split it:
list_of_strings = arcpy.GetParameterAsText(0).split(',')
-
That's how I originally had the code (I took it from the Clip and Ship tutorial data, but when I opened the script they used in the model it was from 9.3, and I am running 10.0). Even so, shouldn't it work just the same the way I have it now? Or would you recommend removing the extra variable and just adding it to the end of 'rasters'?Baskinomics– Baskinomics2011年12月12日 15:48:13 +00:00Commented Dec 12, 2011 at 15:48
I have found the following workflow to work:
- Create a model and drag my script tool into it.
- Create a variable, and check the "Multivalue" checkbox.
- 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
Explore related questions
See similar questions with these tags.