Geoprocessing service example: Stream network
Folder |
StreamNet |
Purpose |
Creates a stream network from flow and accumulation data |
Services |
|
Geoprocessing task |
Create Stream Network |
Inputs |
Minimum upstream drainage area in hectares |
Output |
Stream network |
Data |
Uses digital elevation data (raster) and other data found in the Spatial Analyst tutorial |
Extension |
Spatial Analyst |
Of note |
Uses a result map service to draw the network |
Corresponding folder
The data for this example can be downloaded from ArcGIS.com. Once downloaded, extract the zip file to C:\arcgis\ArcTutor. The GP Service Examples\StreamNet folder contains the completed model and data.
About the Create Stream Network task
The primary purpose of the Create Stream Network task is to produce a stream network for cartographic display. Two results are illustrated below, using a hillshade of the study area (the town of Stowe, Vermont) as a reference map. The idea behind this service is to let the user produce several different networks and choose one that suits his or her cartographic needs.
![]() |
The task creates a stream network defined by a minimum area—the smaller the area, the more stream segments are produced. Each stream segment is assigned a stream order value based on the number of upstream stream segments, and this value is used to determine the line thickness to display each stream segment.
The number of stream segments produced depends on the minimum area used. Using an input of 1 hectare, approximately 32,000 stream segments are produced. For 45 hectares, approximately 600 stream segments are produced.
One of the decisions that you make when creating a geoprocessing service is determining the maximum number of records and features that can be returned from the server to the client. The default is 1,000, and you can increase this to billions. However, transporting large numbers of features across the web is expensive and slow. Whenever you have a service that may output a large number of features, you should consider using a result map service to create a map of the result and let ArcGIS for Server transport the map across the web instead of the features. Because the number of stream segments produced by the Create Stream Network task is dependent on the minimum drainage area and if you substitute your own data, the size and topography of the study area, this example uses a result map service to draw the results instead of transporting the features across the web to the client.
Preparation work
Before publishing the map and geoprocessing services, you will need to create GIS Server connections.
Setup GIS Server connections
You will need to set up a publisher connection which will allow you to use and publish to ArcGIS for Server.
- In the Catalog window, navigate to the GIS Server node and double-click Add ArcGIS Server.
- Choose Publish GIS Services and click Next.
- Enter the Server URL for your GIS Server. For example, http://myserver:6080/arcgis/. Provide a user name and password and click Finish. You now have a (publisher) connection to your GIS Server under the GIS Servers node of your Catalog window.
Reference Map
The reference map for this example, StoweHillshade.mxd, has only one layer, Hillshade, as illustrated below. The Hillshade layer is drawn with a transparency of 55 percent.
![]() |
Stowe hillshade reference map |
StoweHillshade.mxd needs to be published as a map service which will provide reference when using the geoprocessing service.
- Start a new ArcMap session.
- Open the StoweHillshade map document.
- From the File menu, click Share As > Service.
- Choose Publish a Service and click Next.
- Select the publisher connection you made when setting up the GIS Server connections. Accept the default name and click Next.
- Click Create new folder and type Stream. This will create a folder to hold your published service.
- Click Continue to launch the Service Editor.
- Click the Analyze
button. Fix any errors.
You should receive one warning—the data will be copied to the server—and one message—the layer draws at all scale ranges. You can safely ignore these messages or take action if you see fit.
- Click the Publish
button to finish publishing your map service.
Model and tool data
The toolbox for the geoprocessing service is StoweStreamNet.tbx, and the source map document for the service is StoweStreamNet.mxd. StoweStreamNet.mxd contains two source data layers: Flow Direction (the flowdir raster) and Flow Accumulation (the accumulation raster).
Open the StoweSteamNet map document from your Catalog window by double-clicking it.
Model overview
To better understand the model, expand StoweStreamNet.tbx toolbox, right-click the Create Stream Network model, and select Edit. The Create Stream Network model is illustrated below. There is one input variable: Minimum upstream area in hectares. This variable is a double and is the minimum drainage area required to create a stream segment. Smaller areas create more stream segments.
The model calculates the number of raster cells for the input area, then uses the Con tool to perform a conditional if-else evaluation on each of the input cells in the Flow Accumulation raster. Since a cell value in the Flow Accumulation raster is the number of upstream cells flowing into the cell, any cell with an upstream area greater than the cutoff is selected. Selected cells form stream segments and are assigned a 1 in the output raster.
The Stream Order tool assigns a numeric order value to a raster representing branches of a linear network, such as the output of the Con tool. In general, streams with a high order have higher water flows, so stream order can be used as a surrogate for stream width. The output of the model is symbolized so that segments with high order values are drawn with thicker lines.
The Stream To Feature tool converts the Stream Order Raster into the output line feature class. This feature class will be drawn by the result map service using symbology defined in the result map service.
![StreamNet Model StreamNet Model](0154/GUID-97642015-E3A5-4D0C-93A1-B6056C5C9028-web.png)
Project data
The Flow Accumulation and Flow Direction variables are layers from the source map document, StoweStreamNet.mxd. These variables are termed project data because they are nonparameter input data.
Calculating number of cells for the minimum area
All the raster datasets are in Vermont State Plane coordinates, with a linear unit of meters. The cell size is 30 by 30 meters. To determine the spatial reference and cell size of a raster, do either one of the following:
- In the Catalog window, right-click the raster and click Properties.
- In the ArcMap table of contents, right-click a raster layer, click Properties, then click the Source tab.
The Calculate Value tool divides the input hectares by the size of a cell in hectares (30 x 30 meters = 900 square meters = 0.09 hectares) to yield the number of cells for the minimum upstream area. The parameters for the Calculate Value tool, illustrated below, make use of variable substitution. By placing percent signs (%) around a variable name, the contents of the variable are substituted for the value.
Con process
The Con tool performs a conditional if-else evaluation on each of the input cells in the Flow Accumulation raster.
![Con tool parameters Con tool parameters](0154/GUID-85F84CDE-0C5F-4074-93F8-803837DDD07C-web.png)
Note that the expression makes use of variable substitution. In the expression, all cells with a value greater than the minimum number of cells are selected. (The value of a cell in the Flow Accumulation raster is the number of cells flowing into an individual cell.)
The Input true raster or constant value parameter is the value to assign each selected cell and is set to 1.
Stream order process
The Stream Order tool calculates a numeric value for cells that represent branches of a stream network. The parameter values for Stream Order in the model are shown below.
![Stream Order parameters Stream Order parameters](0154/GUID-1861FBB3-4B1E-4AC4-AB40-DF62A016D4B8-web.png)
The output raster contains the Shreve stream order value for every cell that represents a stream.
Stream to feature process
The Stream To Feature tool creates a shapefile of the stream segments contained in Stream Order Raster.
![Stream to Feature parameters Stream to Feature parameters](0154/GUID-8692A46C-B96E-458C-8163-2E2A1901D236-web.png)
Setting output symbology
- Expand StoweStreamNet.tbx and double-click the Create Stream Network model.
- Accept the default of 45 hectares and execute the model by clicking OK.
- The StreamNet layer will be added to ArcMap.
- Right-click the StreamNet layer and click Properties to open the Layer Properties window.
- In the steps below, you will change the symbology to graduated line symbols. Click the Symbology tab to set the appropriate symbology.
- Click Graduated symbols found beneath the Quantities category.
- Choose GRID_CODE as the value field.
- Click Classify.
- On the Classification dialog box, choose Manual as the classification method.
- You will set up a manual classification with breaks of 100, 250, 500, 750, and 10000. In the Break Values panel, click the last value in the list. This allows you to edit the value. Enter one of the break values, such as 10000. The list refreshes so that the values are sorted.
- Continue editing and setting the break values until the list appears as illustrated below.
- Click OK. The Symbology tab now looks as illustrated below. You may need to reset the color to blue by clicking Template and choosing a suitable blue color.
- Click OK.
- The legend for the StreamNet layer displays GRID_CODE as the classification field, which will not make much sense to the user of your service. To change it, click GRID_CODE in the legend, press the F2 key, and change the text to something more descriptive, such as Shreve Order or Stream Order.
![Changing the legend Changing the legend](0154/GUID-95B83A78-7153-4C0E-BC79-542B74103BD1-web.png)
Publishing
To publish the geoprocessing service, perform the following steps:
- In the Results window, right-click the Create Stream Network result and choose Share As > Geoprocessing Service.
- Choose Publish a Service and click Next.
- Select the Publisher connection you made when setting up the GIS Server connections. Change the Service name to StoweStreamNet and click Next.
- Select the Stream folder you created when publishing the map service from the Use existing folder drop-down list and click Continue to launch the Service Editor.
- Click the Analyze
button. There should be no errors. If there are, correct them before proceeding.
- Open the Parameters page to set the properties of the service.
- Check the View results with a map service check box. This setting allows the geoprocessing service to return a result image of the output in addition to the features.
- Optionally set the message level to Info to see tool execution messages when running the service.
- Click the Publish
button to finish publishing your geoprocessing service.
Using the services
To use the services, start ArcMap and add the StoweHillshade map service from the user connection you created previously. From the same GIS Server connection, open the Create Steam Network task from the StoweStreamNet geoprocessing service. Provide a value for the Minimum upstream area in hectares parameter and execute the task. Do not add the Create Steam Network map service since this is a result map service.
![ArcMap before executing the service ArcMap before executing the service](0154/GUID-B0D28D35-7350-4E0C-AFAF-96C461846560-web.png)
![ArcMap after executing the Create Steam Network task ArcMap after executing the Create Steam Network task](0154/GUID-E561D547-D688-442A-BD44-3C35C4F44036-web.png)
Configuring your own steam network task
You can use your own data with the model included in this tutorial to set up your own stream network task. To set up the model with your own data, you'll need to use the Flow Direction and Flow Accumulation tools to precompute raster inputs. You do not need to create a hillshade, though the output from the Hillshade tool provides an effective reference map to draw your stream network on.
Once you have created the input rasters, update those inputs inside the model. Additionally, you may want to add an appropriate range to the Minimum upstream area in hectares parameter your users will use to provide the numeric value. By setting a range appropriate to your rasters, you can ensure valid inputs are given.
- Right-click the model and select Properties.
- Select the Parameters tab and click the None value under the Filter heading of the Minimum upstream area in hectares parameter.
- Choose Range from the drop-down list.
- Enter a minimum and maximum value and accept the changes by clicking OK.
![Note Note](rsrc/note.png)
The minimum value you allow could impact how many features are returned. If the service you are creating could produce a large number of streams (features), you may need to increase the Maximum number of records returned to the server when publishing. Alternatively, you could return no features by setting the value to 0 since you are publishing the service with a result map service to draw the results.
The last modification before publishing involves setting appropriate break values in the classification symbology. The breaks will largely depend on the size of your study area, and you will need to experiment with different break values. A larger study area with more potential streams may require you to create breaks with a higher value. Follow the instructions in the above section on setting output symbology.