GP Service example: Data on demand

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data Setup




Using a polygon digitized by the user, clips datasets in a file geodatabase, outputting shapefiles, then creates a .zip file that is e-mailed to the user.


PortlandDataMapService (map service), DataOnDemand (geoprocessing service).

Geoprocessing tasks



Area of interest (polygon Feature Set) and an e-mail address to send the data.

Outputs, a compressed file containing the data.


The example uses a small dataset of the city of Portland, Oregon.



Of note

This service is hosted on ESRI's sampleserver—see note below. This is a clip and ship service, as described in the clip and ship example.

About this example

Corresponding Folder

C:\arcgis\ArcTutor\GP Service Examples\DataOnDemand contains the tools and data.

About this example

This DataOnDemand service is another example of a clip and ship service. Before exploring this service, you should first read the clip and ship example, since the features and capabilities of this service are compared with that service, as described briefly in the table below. If you are building your own clip and ship service, you may want to combine features and capabilities of both services into your service.

Clip and Ship example

This example

User gets to choose which layers to download.

A fixed set of data is downloaded.

The spatial reference of the output data can be specified.

Spatial reference cannot be specified—it is set to the spatial reference of the datasets being clipped.

Output format can be specified.

Only shapefiles are output.

Uses models, scripts, and tool layers. The service is published using a map document.

No models are used, only scripts. The toolbox is published rather than a map document.

Layers from the map document are clipped.

Datasets are clipped. (Because there is no source map document containing layers, layers cannot be used, only datasets.)

Area of interest (the clip polygon the user digitizes) is not downloaded.

Area of interest is downloaded.

Output cannot be e-mailed.

Output can be e-mailed by specifying an e-mail server name in the ClipZipAndEmail script (source file is DataOnDemand/Scripts/

Comparison between the Clip and Ship example and this DataOnDemand example

Other features of this service include

This service is hosted by ESRI

This service is hosted on ESRI's ArcGIS Online servers. You can try out this service as follows:

  1. Add as an ArcGIS server.
  2. Add as an ArcGIS server.
  3. In ArcMap, add the Portland/Portland_ESRI_LandBase_AGO map service from sampleserver1.
  4. Add the Portland/ESRI_CadastralData_Portland geoprocessing service from sampleserver2 to ArcToolbox.
  5. Expand the ESRI_CadastralData_Portland toolbox and execute the ClipAndShip task.

The scripts and tools in the DataOnDemand folder are the same as those used by the ClipAndShip task in the ESRI_CadastralData_Portland geoprocessing service. The data used for this example, found in DataOnDemand/ToolData/Portland.gdb, is a small subset of the data used in the Portland_Portland_ESRI_LandBase_AGO map service.


The map and geoprocessing services found in sampleserver1 and sampleserver2 may change in the future. There is no guarantee that the services described above are always available.


The data is of a small area in the city of Portland, Oregon, and is found in C:\arcgis\ArcTutor\GP Service Examples\DataOnDemand\ToolData\Portland.gdb.

The ClipZipAndEmail tool uses a Feature Set variable, which in turn needs a schema to define the feature types and fields. The schema can be found in C:\arcgis\ArcTutor\GP Service Examples\DataOnDemand\ToolData\Templates.gdb.

The ToolData folder also contains Mapofzip.mxd, which is included in the ZIP file and displays the clipped and shipped data.


The DataOnDemandTools toolbox contains one script tool, ClipZipAndEmail. The source for this script tool is DataOnDemand/Scripts/

Before using the ClipZipAndEmail tool, you must edit the code and provide the name of your e-mail server. (You can either edit the Python source directly in an application like PythonWin or right-click the script tool and click Edit.) Your system administrator should be able to supply you with the name of your e-mail server.

Some important properties and features of this script are described below:


PortlandDataMapService is published as a map service.

The DataOnDemandTools toolbox is published as a geoprocessing service.

Configuring the service

To configure this service for your data, you will need to edit the ClipZipAndEmail script tool. The source for this script tool is DataOnDemand/Scripts/ You can either edit the Python source directly in an application like PythonWin or right-click the script tool and click Edit.

You will need to change the location of data and the list of datasets. In the main routine,

if __name__ == '__main__':

Locate the definition of the dataloc variable and change it:

 global dataloc; dataloc = os.path.dirname(sys.path[0]) + g + "tooldata" + g + "portland.gdb" + g

The location of the data is relative to the location of the script.

Learn more about using the script location to build paths

Next, change the list of datasets to clip, found in this code snippet:

    ds = ["Streets" + g + "streets", \
            "Water" + g + "StreamRoute", "Water" + g + "floodplain", "Water" + g + "riv_fill", \
            "Transit" + g + "railroad", \
            "Census" + g + "blockgrp", \
            "Develop" + g + "Buildings", \
            "Land" + g + "zoning", "Land" + g + "Parks", \
            "Places" + g + "schools", "Places" + g + "hospital"]

Finally, you will need to provide the name of your e-mail server in the script. The code you need to modify is near the top of the script:

def send_mail(send_from, send_to, subject, text, f=""):
    assert type(send_to)==list

    # Provide the name of your email server below
    server = ""

Related Topics