GP service step by step: Watershed
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. |
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:
Create a toolshare folder
- Start ArcCatalog.
- 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.
- 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.
- 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.
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.
- In the Catalog window, right-click StoweBasemap.mxd and click Publish to ArcGIS Server.
- In the first panel, name the service StoweBasemap (the default).
- Click Next.
- The only capability that you need is mapping—all other capabilities are optional for this service.
- Click Next.
- Click Finish.
You can test the StoweBasemap service by starting ArcMap with a blank document, then add the service by clicking Add Data , navigating to the server, and choosing StoweBasemap.
Toolbox and map document
- In the Stowe folder, create a new toolbox with the name StoweHydro.
- 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.
- 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.
Set the geoprocessing scratch workspace environment to the Scratch folder, as follows:
- In ArcMap, click Geoprocessing > Environments.
- Expand the Workspace Settings category.
- Enter the path to the scratch workspace you created above (for example, E:\Watershed\Scratch)
- Accept the change by clicking OK.
- 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:
Steps to building the model
- In the Catalog window, right-click the StoweHydro toolbox and choose New > Model.
This opens ModelBuilder with a new empty model.
- Create a variable with the Feature Set data type, as follows:
- Right-click in the ModelBuilder canvas and click Create Variable.
- Choose Feature Set as the data type.
- Click OK.
- Rename the variable as Pour Point.
- 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.
- 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.
- Add the Snap Pour Point tool to the model by dragging the tool from the ArcToolbox, Catalog, or Search window.
- Right-click Snap Pour Point and make a variable from the Snap Distance parameter.
- 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.
- 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.
- Right-click Snap Pour Point and click Make Variable > From Environment > Processing Extent > Extent, as illustrated below.
- Double-click the Extent variable and set it to Union of Inputs.
- 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.
- 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.
- Rename the Raster To Point output variable atos Output snapped pour point.
- Right-click Output snapped pour point and make it a Model Parameter.
- 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.
- Right-click Watershed raster and click Managed.
- 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.
- Rename the output variable of the Raster To Polygon tool as Output Watershed.
- Right-click Output Watershed and make it a Model Parameter.
- In the main ModelBuilder menu, click Model > Model Properties.
- Set Name to CreateWatershedPolygon.
- Set Label to Create Watershed Polygon.
- Check Store Relative pathnames.
- 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.
- In the Catalog window, double-click the Create Watershed Polygon tool to open its dialog box. The dialog box appears as shown below:(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.).
- Click 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:
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.
- Open the properties for the snapped_pour layer and set the symbol to a red cross.
- Open the properties for the Watershed layer and set the fill symbol to a light blue.
- Right-click snapped_pour, click Save As Layer File, then save as Stowe\ToolData\snapped_pour.lyr.
- Right-click Watershed, click Save As Layer File, then save as Stowe\Tooldata\Watershed.lyr.
- Edit the Create Watershed Polygon model.
- 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.
- Do the same for the Output Watershed variable, setting the symbology layer to watershed.lyr.
- Save and close the model.
- Remove the existing snapped_pour and Watershed layers from the table of contents.
Create tool layer
- If you have not done so, remove the snapped_pour and Watershed layers from the table of contents.
- 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.
- 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.
- Finally, remove the PourPoint layer since it is no longer needed. You should first save the layer to a layer file for subsequent reuse.
- 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.
- 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.
- Click Next.
- 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.
- Click Next. From this point on, you can accept the default values provided by the wizard.
Use the service
- Start ArcMap with a blank document.
- Add the StoweBasemap map service to the ArcMap table of contents from your ArcGIS Server connection.
- Expand the StoweHydro geoprocessing service from the ArcGIS Server connection and open the Create Watershed Polygon tool.
- 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:
- Examine the results of the task in the Results window, as illustrated below: