GP Service example: Clip and ship
Folder |
ClipAndShip |
Purpose |
Using a polygon digitized by the user, this service clips layers from the study area into a file geodatabase, then creates a .zip file that can be downloaded by the user. |
Services |
Portland (Map service), ClipAndShip (Geoprocessing service). |
Geoprocessing tasks |
Extract Data Task. |
Inputs |
Layers to Clip, Area of Interest, Feature Format, Raster Format. |
Outputs |
A ZIP file containing the data. |
Data |
The example uses a number of datasets from the study area of Portland, Oregon. |
Extensions |
None. |
Of note |
Creates output.zip, a compressed file containing a file with the format specified. This file mimics the arrangement of the layers in the ArcMap document that is published as a geoprocessing service. |
Corresponding Folder
C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip contains the completed models and data.
About this example
This example shows the detail steps of publishing and using a map and a geoprocessing service. The geoprocessing task lets you select the layers you want, digitize a polygon (or multiple polygons) of the area of interest, and select the output feature and raster data format. Data in the map is clipped to the area of interest, then bundled and shipped to the user—hence the name "clip and ship".
Data
The study area for this example is a small area in the city of Portland, Oregon. Data includes places, transportation networks, hydrologic features, land records, and a hillshade raster of the study area. The data can be found in C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip\ToolData\Portland.gdb.
Publishing
- From the Catalog window, navigate to C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip.
- Right-click Portland.mxd and select Publish to ArcGIS Server.
- In the first window, keep all defaults and click Next.
- in the next panel, deselect all check boxes except Mapping (always enabled). Click Next.
- Click Finish. The map service Portland will be published to the ArcGIS Server. You will use it as a basemap later.
- Open C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip\Portland.mxd in ArcMap.
- In the Catalog window,
- Expand Toolboxes > System Toolboxes > Server Tools.tbx > Data Extraction > Extract Data Task.
- Drag the Extract Data Task tool to the ArcMap table of contents.
The tool layer Extract Data Task appears in the table of contents.
- Save the map document containing the tool layer as ClipAndShip.mxd.
- In the Catalog window, right-click the connection to your ArcGIS Server and select Add New Service.
- In the Add GIS Service panel, type ClipAndShip as the service name and select Geoprocessing Service as the Type. Click Next.
- In the next panel, check A Map as your source file. Enter the path to the ClipAndShip.mxd map document that you created above and click Next.
- For any remaining panels, leave the default value and click Next until the last panel, where you click Finish. You should see the service ClipAndShip under your ArcGIS Server connection.
Using
The following steps show how to use the map and geoprocessing services that you previously published.
- Open a new ArcMap document.
- In the Catalog window,
- Go to GIS Servers > Add ArcGIS Server and check Use GIS Services. On the General panel, enter the Server URL, then click Finish. A server usage connection with the host name (and port number if it is a Java server) appears under GIS Servers.
- Navigate to your server usage connection under GIS Servers, select the map service Portland, and drag it into the ArcMap table of contents.
- Expand the Portland map service in the table of contents, and you will see all the layers belonging to the Portland map service.
- In the Catalog window, navigate to your server connection under GIS Servers, find the geoprocessing service ClipAndShip, and expand it. The task Extract Data Task appears.
- Double-click the task Extract Data Task to open the task dialog box.
- At the top of the task panel is a list of Layers to Clip. Note that the layer names in the check box are the same as the layers of the Portland map service in the table of contents. Check the box next to each layer that you want to be included in your download.
- The next parameter of the Extract Data Task is the Area of Interest. This parameter is used to digitize an area of interest that will be used to clip each of the Layers to Clip. Click Add Feature, then digitize a polygon as an area of interest.
- Other input parameters, Feature Format and Raster Format, can be modified or left as default.
- Click OK to run the geoprocessing task.
The output is returned from the server and written to the location set in your geoprocessing scratch workspace environment.
When the task completes, open the Results window to view the results of the task. Double-click output.zip to open the compressed file, then extract the data to a location of your choice.
Customizing the GP Service source model
The previous example uses the model tool Extract Data Task from the Server toolbox. If you copy the model tool to a new custom toolbox, it can be opened in ModelBuilder and edited. The Extract Data Task model contains input variables Spatial Reference and Customized Spatial Reference Folder, which are not exposed as model parameters. Spatial Reference has a default value, Same as Input, which means the spatial reference of the output files is the same as the input layers. If you want to get a spatial reference for the output files that is different from that of the input files, you can set Spatial Reference as an input parameter so that when the model tool dialog box is opened, a different spatial reference can be specified. The variable Customized Spatial Reference Folder is an optional variable allowing you to specify a path that saves the custom and/or standard spatial reference.
In addition to the two Spatial Reference variables, which can be modified to customize the Extract Data Task, the existing model parameter Feature Format can also be modified to contain additional formats you need.
The following steps show how to customize the Extract Data Task by exposing the variable Spatial Reference as a parameter, adding a path for the custom spatial reference folder, and adding new output formats for the Feature Format parameter.
A toolbox named ExtractPortlandTbx that contains a customized model ExtractPortlandData is saved under C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip. The model is the finished product after performing the following steps.
- The first step is to create a new toolbox and model. In the Catalog window, go to C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip.
- Right-click the folder and select New > Toolbox.
- Rename the toolbox ExtractPortland.
- In the Catalog window,
- Expand Toolboxes > System Toolboxes > Server Tools.tbx > Data Extraction > Extract Data Task.
- Select the Extract Data Task, right-click the model, then select Copy.
- Go to ExtractPortland.tbx that is created in step 1b, right-click and select Paste.
The model Extract Data Task is copied to the toolbox.
- Right-click the model, select Rename, then rename the model ExtractPortlandData.
- Right-click the model ExtractPortlandData and select Edit to open the model in ModelBuilder. In the model, right-click the variable Spatial Reference and select Model Parameter. The letter P appears on the upper right-hand corner of the variable so it is now a model parameter.
- Create a new folder where all the standard and custom coordinate system projection files will be saved.
- In Windows Explorer, go to C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip. Right-click the folder and select New > Folder.
- Rename the new folder SpatialReference.
- Go to <ArcGISInstallDirectory>\Desktop10.0\Coordinate Systems\Projected Coordinate Systems, copy the State Plane folder.
- Paste it into the new SpatialReference folder.
- Right-click the model ExtractPortlandData and select Edit. Double-click the variable Custom Spatial Reference Folder and enter the path to the new SpatialReference folder (C:\arcgis\ArcTutor\GP Service Examples\ClipAndShip\SpatialReference), then click OK.
- With the ExtractPortlandData model still open in ModelBuilder,
- Go to the Model menu > Properties > Parameters tab.
The parameter Spatial Reference appears at the bottom of the parameter list.
- Reorder the parameters so the output parameter is the last parameter. Highlight the parameter Output Zip Fileand click the button to move it to the bottom of the list.
- Go to the Model menu > Properties > Parameters tab.
- Still in the Parameters tab,
- Highlight the variable Spatial Reference, then change the Filter value to Value List.
- Enter the values Same As Input, NAD 1983 StatePlane Oregon South FIPS 3602 (US Feet), and WGS1984 to the value list.
- Click OK to close the Value List dialog box.
- Click OK to close the model Properties dialog box.
- Save the model and exit ModelBuilder.
- Save the customized model and add it as a tool layer in a new ArcMap document that contains all the layers from Portland.mxd.
- Refer to the instruction in the Publishing and Using sections above to publish and use the customized model as a geoprocessing service.