ArcGIS Server Banner

GP Service step-by-step: Watershed

GP Service step-by-step: Watershed

Release 9.3 E-mail This TopicPrintable VersionGive Us feedback


Folder Watershed.
Purpose A basic service that computes a watershed polygon. Uses the Spatial Analyst extension.
Services StoweBasemap (map service).

StoweHydro (geoprocessing service).
Geoprocessing tasks Create Watershed Polygon.
Inputs User digitizes a point in the study area.
Outputs Polygon of computed watershed and a snapped pour point.
Data This example uses digital elevation data (raster) and other data found in the Spatial Analyst tutorial.
Extensions Spatial Analyst.

Corresponding Folder

C:\arcgis\ArcTutor\GP Service Examples\Watershed contains the completed model and data. After completing all the steps described below, you will have duplicated the contents of this folder.

Data preparation

Data

You can find the data for this example in C:/arcgis/ArcTutor/Spatial. The data is for the town of Stowe, Vermont. The contents of C:/arcgis/ArcTutor/Spatial is illustrated below.

ArcTutor/Spatial contents

Create a toolshare folder

  1. Start ArcCatalog.
  2. In a location of your choice, create a new folder named Watershed. Within Watershed, create a ToolData and Scratch folder. Within Scratch, create a new file geodatabase named Scratch.
  3. Copy the contents of the c:/arcgis/ArcTutor/Spatial folder into Tooldata.

Data Processing

For this service, you'll need to create four new raster datasets, as shown below.

Derived data

  1. dem_fill is the result of executing the Fill tool using elevation as input.
  2. hillshade is the result of executing the Hillshade tool using dem_fill as input.
  3. flowdir is the result of executing the Flow Direction tool using dem_fill as input.
  4. accumulation is the result of executing the Flow Accumulation tool using flowdir as input.

The model in this example uses a feature set, and you will need a point feature class to use as the feature set schema. In Stowe.gdb, create a new point feature class named PourPoint.

Basemap

The basemap contains three layers: Landuse (landuse raster), Hillshade (hillshade raster), and Roads (Stowe.gdb/roads feature class), as illustrated below. You will need to create a map document containing these layers. The ArcMap document is named StoweBasemap.mxd.

Basemap and legend

The Hillshade layer is drawn with a transparency of 55 percent. To change transparency, right-click the Hillshade layer, choose Properties, click the Display tab, and change the transparency.

After creating and saving StoweBasemap.mxd, publish it as a map service to your server.

  1. In ArcCatalog, right-click StoweBasemap and click Publish to ArcGIS Server.
  2. In the first panel, name the service StoweBasemap (the default).
  3. Click Next.
  4. The only capability that you need is Mapping—all other capabilities are optional and for this service.
  5. Click Next.
  6. Click Finish.

You can test the StoweBasemap service by starting ArcMap with a blank document, then add the service by clicking Add Data Add Data, navigating to the server, and choosing StoweBasemap.

Toolbox and map document

  1. In the Stowe folder, create a new toolbox with the name StoweHydro.
  2. Start ArcMap with a new document and add the accumulation and flowdir rasters to the table of contents, renaming the layers to Flow Accumulation and Flow Direction. Add the PourPoint feature class you created above.
  3. Optionally, change the symbology of PourPoint to a red plus sign, as illustrated below.
  4. Show the ArcToolbox window Show/Hide ArcToolbox Window.
  5. Add the StoweHydro toolbox to the ArcToolbox window.

The table of contents and the ArcToolbox window should appear similar to the following illustration. The Flow Direction and Flow Accumulation layers will be used in the published task, but never displayed to the user. Therefore, the symbology of these layers does not matter.

Table of contents and ArcToolbox

Set the geoprocessing scratch workspace environment to the Scratch folder, as follows:

  1. Right-click the ArcToolbox entry and click Environments.
  2. Expand the General Settings category.
  3. Enter the pathname to the Scratch folder (for example, E:\Watershed\Scratch).

Save the map as StoweHydro.mxd.

Create the model

The input to the Create Watershed Polygon model a user-supplied point and a WatershedID for the point. A watershed polygon is output for each input point. In addition, the user-supplied points will be snapped to the cells of highest flow accumulation using the Snap Pour Point tool. The snapped points will also be output.

Since these models make use of layers in the map document, you create these models in ArcMap using the StoweHydro map document.

The Create Watershed Polygon model is illustrated below.

Create Watershed Polygon

Steps to building the model

  1. Right-click StoweHydro in ArcToolbox and choose New > Model.
  2. Create a variable with the Feature Set data type, as follows:
    1. Right-click in the ModelBuilder canvas and click Create Variable.
    2. Choose Feature Set as the data type.
    3. Click OK.

  3. Change the variable name to Pour Point.
  4. Right-click Pour Point and click Properties. Click the Data Type tab. Set the schema to the PourPoint layer by choosing it in the drop-down list.
  5. Right-click Pour Point and click Model Parameter. A check should appear next to Model Parameter, and a P will appear next to the Pour Point variable.
  6. Add the Snap Pour Point tool.
  7. Right-click Snap Pour Point and make a variable from the Snap Distance parameter.
  8. Double-click Snap Distance and set the Snap Distance to 250 meters. It is not a requirement that you make Snap Distance a model variable, but doing so gives anyone who views the model a visual clue that snap distance is an important variable.
  9. Double-click Snap Pour Point and set the input parameter Pour Point. Set the Pour point field parameter to WatershedID. Set the Input accumulation raster parameter to the Flow Accumulation layer. These settings are illustrated below.
  10. Snap Pour Point parameter settings

  11. Right-click Snap Pour Point and click Make Variable > From Environment > General Settings > Extent, as illustrated below.
  12. Making a variable from the Extent environment

  13. Double-click the Extent variable and set it to Union of Inputs.
  14. Change the name of the output of Snap Pour Point to Pour Point Raster. This is intermediate output and will be deleted after the model executes. Right-click Pour Point Raster and click Managed. A checkmark should appear next to Managed.
  15. Add the Raster to Point tool. Double-click Raster to Point and set the Input raster parameter to Pour Point Raster. Set the Output point features parameter to %scratchworkspace%\snapped_pour.shp.
  16. Raster to Point parameter settings

  17. Rename the Raster to Point output variable to Output snapped pour point.
  18. Right-click Output snapped pour point and make it a model parameter.
  19. Add the Watershed tool and use the Flow Direction layer for the Input flow direction raster parameter. Change the name of the output of Watershed to Watershed raster.
  20. Watershed raster is intermediate output. Right-click Watershed raster and click Managed. A checkmark should appear next to Managed.
  21. Add the Raster to Polygon tool. Set the Input raster parameter to Watershed raster. Set the Output Polygon features parameter to %scratchworkspace%\Watershed.shp.
  22. Change the name of the output variable of Raster to Polygon to Output Watershed.
  23. Right-click Output Watershed and make it a model parameter.
  24. In the main ModelBuilder menu, click Model, then click Model Properties.
  25. Save and close the model.

Creating symbology layer files

In this next series of steps, you will be creating layer files to use as output symbology for your task.

  1. In the ArcToolbox window, double-click the Create Watershed Polygon tool to open its dialog. The dialog should appear as illustrated below.
  2. Create Watershed Polygon dialog

    (The order of the parameters in your tool dialog may be different, depending on the order in which you made variables model parameters. You can change the order of parameters in the tool's properties.)

  3. Click Add feature Add feature to add a pour point. The location you use for the Pour Point should be in a valley, not on a mountaintop where there is no watershed.
  4. Learn more about using the feature set control to add features.

  5. Click the WatershedID cell and enter an integer value.
  6. The illustration below shows a result of executing Create Watershed Polygon.

    Example watershed output

In the above illustration, note that the output watershed polygon is green and the snapped pour point is a small dot. (Your symbology may be different.) In the following steps, you will create better symbology. Save this symbology as a layer file (.lyr), then use these layer files to define the symbology of your output variables.

  1. Open the properties for the snapped_pour layer and set the symbol to a dark blue x.
  2. Open the properties for the Watershed layer and set the fill symbol to a light blue.
  3. Right-click snapped_pour, click Save As Layer File, and save to Stowe\ToolData\snapped_pour.lyr.
  4. Right-click Watershed, click Save As Layer File, and save to Stowe\Tooldata\Watershed.lyr.
  5. Edit the Create Watershed Polygon model.
  6. Right-click the Output snapped pour point variable and click Properties. In the Properties dialog box, click the Layer Symbology tab and set the symbology layer to snapped_pour.lyr, as illustrated below.
  7. Layer Symbology

  8. Do the same for the Output Watershed variable, setting the symbology layer to watershed.lyr.
  9. Save and close the model.
  10. Remove the existing snapped_pour and Watershed layer from the table of contents.

Create tool layer

  1. If you have not done so, remove the snapped_pour and Watershed layers from the table of contents.
  2. To create the tool layer, drag and drop the Create Watershed Polygon tool from the ArcToolbox window into the ArcMap table of contents. Your tool layer may appear with or without sublayers, as illustrated below. Sublayers will appear if the tool outputs exist at the time you create the tool layer.
  3. Tool layer for the Create Polygon Watershed tool

  4. Right-click the tool layer and click Open. The tool dialog opens. Add a pour point and a watershed ID and run the tool. After the tool runs, the two sublayers will be refreshed and will have the symbology as defined in the symbology layers you created above.
  5. Finally, remove the PourPoint layer since it is no longer needed. You should first save the layer to a layer file for subsequent reuse.
  6. Save the map as Stowe/StoweHydro.mxd and exit ArcMap.

Publish the service

In previous steps, you published the StoweBasemap map service. Now you will publish the StoweHydro geoprocessing service. The StoweHydro service contains the Create Watershed Polygon task.

  1. In ArcCatalog, navigate to your server, right-click and choose Add New Service. Name the service StoweHydro and choose Geoprocessing Service as the type, as illustrated below.
  2. Add New Service panel 1

  3. Click Next.
  4. In the next panel, you choose StoweHydro.mxd as the source for your geoprocessing service, as illustrated below. Since you will test your service, check Show Messages.
  5. Add New Service wizard panel 2

  6. Click Next. From this point on, you can accept the default values provided by the wizard.

Use the service

  1. Start ArcMap with a blank document.
  2. Add the StoweBasemap map service to the ArcMap table of contents.
  3. Add the StoweHydro geoprocessing service to ArcToolbox.
  4. Expand the StoweHydro toolbox and open the Create Watershed Polygon tool. The illustration below shows the result of these steps.
  5. Services in ArcMap session

  6. Add a point and a Watershed ID to Create Watershed Polygon and click OK to run the task.
  7. After the task completes, the table of contents should have the two output layers, as illustrated below.
  8. Completed task

  9. Take the opportunity to examine the result of the task in the Results tab of ArcToolbox, as illustrated below.
  10. Results

See Also

  • Guide to the geoprocessing service examples