GP service step by step: Watershed

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data Setup

Folder

Watershed

Purpose

Using the Spatial Analyst extension, this basic service computes a watershed polygon.

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.

About this example

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 Analyst. The data is for the town of Stowe, Vermont. The contents of this location are shown below:

ArcTutor\Spatial Analyst 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 Analyst folder into ToolData.

Data processing

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

Derived data
  • Dem_fill is the result of executing the Fill tool using elevation as input.
  • Hillshade is the result of executing the Hillshade tool using dem_fill as input.
  • Flowdir is the result of executing the Flow Direction tool using dem_fill as input.
  • 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.

  • For a coordinate system, import any of the existing datasets within the ToolData folder.
  • Use the default values for xy tolerance and configuration keyword.

Basemap

The basemap contains three layers: Landuse (landuse raster), Hillshade (hillshade raster), and Roads (Stowe.gdb/roads feature class). You will need to create a map document containing these layers. Name the ArcMap document 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, then change the transparency.

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

Steps:
  1. In the Catalog window, right-click StoweBasemap.mxd 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 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, respectively. Add the PourPoint feature class you created above.
  3. Optionally, change the symbology of PourPoint to a red plus sign, as illustrated.

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:

Steps:
  1. In ArcMap, click Geoprocessing > Environments.
  2. Expand the Workspace Settings category.
  3. Enter the path to the scratch workspace you created above (for example, E:\Watershed\Scratch)
  4. Accept the change by clicking OK.
  5. Save the map as StoweHydro,mxd.

Create the model

The input to the Create Watershed Polygon model is a user-supplied 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

Steps:
  1. In the Catalog window, right-click the StoweHydro toolbox and choose New > Model.

    This opens ModelBuilder with a new empty 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.
  4. Rename the variable as Pour Point.
  5. Right-click Pour Point and click Properties. Click the Data Type tab. Set the schema to the Pour Point layer by choosing it in the drop-down list.
  6. Right-click Pour Point and click Model Parameter. A check mark appears next to Model Parameter, and a P appears next to the Pour Point variable.
  7. Add the Snap Pour Point tool to the model by dragging the tool from the ArcToolbox, Catalog, or Search window.
  8. Right-click Snap Pour Point and make a variable from the Snap Distance parameter.
  9. 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 that views the model a visual clue that snap distance is an important variable.
  10. Double-click Snap Pour Point and set the input raster parameter to Pour Point. Set the Pour point field parameter to ObjectID if not already set. Set the Input accumulation raster parameter to the Flow Accumulation layer.
    Snap Pour Point parameter settings
    Snap Pour Point parameter settings
  11. Right-click Snap Pour Point and click Make Variable > From Environment > Processing Extent > Extent, as illustrated below.
    Making a variable from the Extent environment
  12. Double-click the Extent variable and set it to Union of Inputs.
  13. Rename the output of Snap Pour Point as Pour Point Raster. This is intermediate output and should be deleted after the model executes. Right-click Pour Point Raster and check Managed.
  14. Add the Raster To Point tool to the model. 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.
    Raster to Point parameter settings
    Raster To Point parameter settings
  15. Rename the Raster To Point output variable atos Output snapped pour point.
  16. Right-click Output snapped pour point and make it a Model Parameter.
  17. Add the Watershed tool to the model and use the Flow Direction layer for the Input flow direction raster parameter. Rename the output of the Watershed tool as Watershed raster. Watershed raster is intermediate output.
  18. Right-click Watershed raster and click Managed.
  19. Add the Raster To Polygon tool to the model. Set the Input raster parameter to Watershed raster. Set the Output Polygon features parameter to %scratchworkspace%\Watershed.shp.
  20. Rename the output variable of the Raster To Polygon tool as Output Watershed.
  21. Right-click Output Watershed and make it a Model Parameter.
  22. In the main ModelBuilder menu, click Model > Model Properties.
    1. Set Name to CreateWatershedPolygon.
    2. Set Label to Create Watershed Polygon.
    3. Check Store Relative pathnames.
  23. 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.

Steps:
  1. In the Catalog window, double-click the Create Watershed Polygon tool to open its dialog box. The dialog box appears as shown below:
    Create Watershed Polygon dialog
    Create Watershed Polygon tool dialog box
    (The order of the parameters in your tool dialog box may be different, depending on the order in which you made variables model parameters. You can change the order of parameters in the model tool's properties.).
  2. 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. The following illustration shows a result of executing Create Watershed Polygon: Example watershed output

In the above illustration, note that the output watershed polygon is blue 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.

Steps:
  1. Open the properties for the snapped_pour layer and set the symbol to a red cross.
  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, then save as Stowe\ToolData\snapped_pour.lyr.
  4. Right-click Watershed, click Save As Layer File, then save as Stowe\Tooldata\Watershed.lyr.
  5. Edit the Create Watershed Polygon model.
  6. Right-click the Output snapped pour point variable and click Properties. On the Properties dialog box, click the Layer Symbology tab and set the symbology layer to snapped_pour.lyr.
    Layer Symbology
    Setting layer symbology
  7. Do the same for the Output Watershed variable, setting the symbology layer to watershed.lyr.
  8. Save and close the model.
  9. Remove the existing snapped_pour and Watershed layers from the table of contents.

Learn more about setting symbology using layer files

Create tool layer

Steps:
  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 the Create Watershed Polygon tool into the ArcMap table of contents. Your tool layer may appear with or without sublayers, as illustrated below. Sublayers appear if the tool outputs exist at the time you create the tool layer.
    Tool layer for the Create Polygon Watershed tool
    Tool layer for the Create Polygon Watershed tool
  3. Right-click the tool layer and click Open. The tool dialog box opens. Add a pour point using the feature set control and run the tool. After the tool runs, the two sublayers in the ArcMap table of contents are refreshed and have the symbology as defined in the symbology layers you created above.
  4. Finally, remove the PourPoint layer since it is no longer needed. You should first save the layer to a layer file for subsequent reuse.
  5. Save the map as 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.

Steps:
  1. In the Catalog window, navigate to your server, right-click, then choose Add New Service. Name the service StoweHydro and choose Geoprocessing Service as the type.
  2. Click Next.
  3. Choose StoweHydro.mxd as the source for your geoprocessing service, as illustrated below. Since you will test your service, check the Show Messages checkbox. In a production environment, you may want to disable messages. Add New Service wizard panel 2
  4. Click Next. From this point on, you can accept the default values provided by the wizard.

Use the service

Steps:
  1. Start ArcMap with a blank document.
  2. Add the StoweBasemap map service to the ArcMap table of contents from your ArcGIS Server connection.
  3. Expand the StoweHydro geoprocessing service from the ArcGIS Server connection and open the Create Watershed Polygon tool.
  4. Add a point to the Create Watershed Polygon using the feature set control and click OK to run the task. After the task completes, the table of contents has the two output layers, as illustrated below: Completed task
  5. Examine the results of the task in the Results window, as illustrated below: Results

Related Topics


11/18/2013