GEOG 485:
GIS Programming and Automation

1.3.3 Model parameters

PrintPrint

Most tools, models, and scripts that you create with ArcGIS have parameters. Input parameters are values with which the tool (or model or script) starts its work, and output parameters represent what the tool gives you after its work is finished.

A tool, model, or script without parameters is only good in one scenario. Consider the model you just built that used the Buffer, Intersect, and Clip tools. This model was hard-coded to use the us_cities, us_roads, and us_boundaries shapefiles and output a shapefile called suitable_land. In other words, if you wanted to run the model with other datasets, you would have to open ModelBuilder, double-click each element (US Cities, US Roads, US Boundaries, and Suitable land), and change the paths that were written directly into the model. You would have to follow a similar process if you wanted to change the buffer distances, too, since those were hard-coded to 10 miles.

Let’s modify that model to use some parameters, so that you can easily run it with different datasets and buffer distances.

  1. If it's not open already, open the map document C:\WCGIS\Geog485\Lesson1\ModelPractice.mxd in ArcMap.
  2. In the Catalog window, find the model you created in the previous lesson which should be under Toolboxes > My Toolboxes > Lesson 1 > Find Suitable Land
  3. Right-click the model Find Suitable Land and click Copy. Now right-click the Lesson 1 toolbox and click Paste. This creates a new copy of your model that you can work with to create model parameters. Using a copy of the model like this allows you to easily start over if you make a mistake.
  4. Rename the copy of your model Find Suitable Land With Parameters or something similar.
  5. In your Lesson 1 toolbox, right-click Find Suitable Land With Parameters and click Edit. You'll see the model appear in ModelBuilder.
  6. Right-click the element US Cities (should be a blue oval) and click Model Parameter. This means that whoever runs the model must specify the cities dataset to use before the model can run.
  7. You need a more general name for this parameter now, so right-click the US Cities element and click Rename. Change the name to just "Cities."
  8. Even though you "parameterized" the cities, your model still defaults to using the C:\WCGIS\Geog485\Lesson1\us_cities.shp dataset. This isn't going to make much sense if you share your model or toolbox with other people because they may not have the same us_cities shapefile, and even if they do, it probably won't be sitting at the same path on their machines.

    To remove the default dataset, double-click the Cities element and delete the path, then click OK. Some of the elements in your model may turn white. This signifies that a value has to be provided before the model can successfully run.

  9. Now you need to create a parameter for the distance of the buffer to be created around the cities. Right-click the element that you named "Buffer the cities" and click Make Variable > From Parameter > Distance [value or field].
  10. The previous step created a new element Distance [value or field]. Rename this element to "Cities buffer distance" and make it a model parameter. (Review the steps above if you're unsure about how to rename an element or make it a model parameter.) For this element, you can leave the default at 10 miles. Your model should look similar to this, although the title bar of your window may vary:
     
    see long description
    Figure 1.7 The "Find Suitable Land With Parameters" model following Step 10, above, and showing two parameters.
    Click link to expand for a text description of Figure 1.7

    A white oval labeled cities and a light blue oval labeled cities buffer distance lead to a white box labeled buffer the cities which leads to a white oval labeled buffered cities

    A blue oval labeled US roads leads to a yellow box labeled buffer the roads which leads to a green oval labeled buffered roads

    The white oval labeled buffered cities and the green oval labeled buffered roads both lead to a white box labeled intersect. This white box labeled leads to a white oval labeled intersected buffers.

    The white oval labeled intersected buffers and a blue oval labeled US Boundaries leads to a white box labeled clip.

    The white box labeled clip leads to a white oval labeled suitable land.

  11. Repeating what you learned above, rename the US Roads element to "Roads," make it a model parameter, and remove the default value.
  12. Repeating what you learned above, make a parameter for the Roads buffer distance. Leave the default at 10 miles.
  13. Repeating what you learned above, rename the US Boundaries element to Boundaries, make it a model parameter, and remove the default value. Your model should look like this (notice the five parameters indicated by "P"s):
     
    see long description
    Figure 1.8 The "Find Suitable Land With Parameters" model following Step 13, above, and showing five parameters.
    Click link to expand for a text description of Figure 1.8

    A white oval labeled cities and a light blue oval labeled cities buffer distance lead to a white box labeled buffer the cities which leads to a white oval labeled buffered cities

    A white oval labeled US roads and a light blue oval labeled roads buffer distance both lead to a white box labeled buffer the roads which leads to a white oval labeled buffered roads

    The white oval labeled buffered cities and the white oval labeled buffered roads both lead to a white box labeled intersect. This white box labeled leads to a white oval labeled intersected buffers.

    The white oval labeled intersected buffers and a white oval labeled US Boundaries leads to a white box labeled clip.

    The white box labeled clip leads to a white oval labeled suitable land.

  14. Save your model and close ModelBuilder.
  15. Double-click your model Lesson 1 > Find Suitable Land With Parameters and examine the tool dialog. It should look similar to this:

    Screen capture to show the model interface with parameters.
    Figure 1.9 The model interface, or tool dialog, for the model "Find Suitable Land With Parameters."

    People who run this model will be able to browse to any cities, roads, and boundaries datasets, and will be able to control the buffer distance. The green dots indicate parameters that must be supplied with valid values before the model can run.

  16. Test your model by supplying the us_cities, us_roads, and us_boundaries shapefiles for the model parameters. If you like, you can try changing the buffer distance.

    Note that sometimes the result does not add itself to the display like it should. You should just be able to add it to the display by using the Add Data button and browsing to the suitable_land.shp location.

The above exercise demonstrated how you can expose values as parameters using ModelBuilder. You need to decide which values you want the user to be able to change and designate those as parameters. When you write Python scripts, you'll also need to identify and expose parameters in a similar way.