Skip To Content

Geoprocessing service example: Selecting data

In this topic
Complexity: BeginnerData Requirement: ArcGIS Tutorial Data for Desktop

Folder

SelectingData

Purpose

Demonstrates various ways to select data by attribute query or location query.

Services

  • SelectAndMail, SelectAndPrint (geoprocessing service )
  • ParcelBaseMap (map service)

Geoprocessing tasks

SelectAndMail, SelectAndPrint

Inputs

Varies by model; usually a query string or a feature set

Output

Selected data feature class, text, and PDF file

Data

Uses a dataset of an area in the city of Manhattan, Kansas

Extensions

None

About this example

About these services

A common task for geoprocessing services is to select a subset of data based on an attribute query or a spatial query. Another common task is to print the output of a service in different formats so the results can be easily disseminated. The models in this example demonstrate the combination of these two tasks. The primary geoprocessing tools used in these models are Select Layer By Attribute and Select Layer By Location. The tools take layers as input. Their output is the updated input layer containing the selected features. Two script tools are used to print selected features: one prints the selected feature table attributes and values as a text file, the other prints the selected feature map as a PDF file.

In this example, you'll be working with the SelectParcel.tbx toolbox. SelectParcel.tbx contains two toolsets: SelectScripts and SelectModels. SelectScripts contains two script tools:

  1. MailTable takes a parcel layer as input and prints the parcel ID and address of each selected feature to a text file.
  2. PrintMap takes an ArcMap document, data frame, layer name, source of layer as inputs, and exports the content of the map document to a PDF file.
The SelectModels toolset contains two models:
  1. SelectAndMail demonstrates selecting all parcels within a search distance of an input parcel ID and uses the MailTable script tool to print the output as a text file.
  2. SelectAndPrint combines the SelectAndMail model and PrintMap script tool to select and print the selected features to a PDF file.
The two models are used to publish as geoprocessing services.

Data

The data is of a small area in the city of Manhattan, Kansas. The data for this example can be downloaded from ArcGIS.com. Once downloaded, extract the zip file to C:\arcgis\ArcTutor. The geodatabase used in this example is GP Service Examples\SelectingData\ToolData\ManhattanKS.gdb.

Overview of the models

SelectAndMail model

The first few processes of the SelectAndMail model is illustrated below. The model contains the project data variable Parcels and the variable Parcel ID, a model parameter, which is used in the Expression parameter for the Select Layer By Attribute tool. This parameter uses variable substitution to construct an expression that selects features whose PID attribute matches the value of the Parcel ID variable.

Although it is not required, it is a good practice to make variables used in variable substitutions a precondition to the process that substitutes the variable. To make a precondition, follow these steps:

  1. In ModelBuilder, right-click a tool and click Properties.
  2. Click the Preconditions tab.
  3. Choose the variable or variables that are a precondition to tool execution.
SelectAndMail model illustration part 1

Both the Select Layer By Attribute and Select Layer By Location tools have several options for selection type. For example, the Select Layer by Attribute tool above uses the default NEW_SELECTION. You can use other selection types such as add or remove features from the current selection.

The Select Layer By Location tool lets you establish a spatial relationship, such as CONTAINS, WITHIN, and INTERSECT. The SelectAndMail model uses INTERSECT as illustrated below.

This is required

The remainder of the SelectAndMail model is illustrated below. The output of Select Layer By Location is copied to a feature class Selected Parcels using Copy Features. Selected Parcels is used as an input to the script tool MailTable, which prints the parcel ID and address to the text file Output.txt.

SelectAndMail model illustration part 2

SelectAndPrint model

The model SelectAndPrint combines the SelectAndMail model and the PrintMap script tool to select and print the selected features as a PDF file. The output of the model SelectAndMail is Selected Parcels, which is used as the input of the script tool PrintMap. PrintMap requires you to provide the values for input parameters Map, DataFrame, Layer, DataSource, WorkspaceType, and the output parameter OutputPDF, as illustrated below:

SelectAndPrint model

Make a connection to ArcGIS Server

Make sure you have the permission to publish to the server. If you do, follow the steps to create a server publish or manage connection:

  1. In the Catalog window, navigate to GIS Servers > Add ArcGIS Server to bring up the ArcGIS for Server wizard.
  2. Check Publish GIS Services or Administer GIS Server and click Next to bring up the General window.
  3. In the General window, enter the value of Server URL and provide User Name and Password for authentification.
  4. Click Finish to complete the connection.

You should see the server connection appear under GIS Servers.

Share the map service

Follow the next steps to create a map service to be used as a reference map:

  1. From the Catalog window, navigate to C:\arcgis\ArcTutor\GP Service Examples\SelectingData.
  2. Open ParcelBaseMap.mxd.
  3. From the ArcMap pull down menu, select File > Share as > Service. The Share a Service wizard opens.
  4. Check the radio button of Publish a service and click Next.
  5. Provide a connection to ArcGIS Server. Name the service ParcelBaseMap. Click Next.
  6. Choose the default root folder or select another folder and click Continue to open the Service Editor.
  7. In the Service Editor window, click Capabilities to show all the options. Mapping and KML are checked by default. Uncheck KML.
  8. Click Item Description and provide content for the required fields Summary and Tags.
  9. Click Analyze Analyze.
  10. If you see any warning Warning or error Error messages in the Prepare window, you can fix them by right-clicking the row with the error or warning message and clicking the highlighted message.
  11. When you are ready, click Publish Publish to publish the service.

You should get a successful message when it is published. After refreshing the server connection that you created in the previous section, you should be able to see the map service under the server connection.

Share the geoprocessing service

Run SelectAndMail tool and share the result

    Run the SelectAndMail model tool to create a result in the Results window that you can share as a service. To run the tool:
  1. From the Catalog window, navigate to C:\arcgis\ArcTutor\GP Service Examples\SelectingData. If you do not want to run from the directory, copy and paste to a local directory.
  2. Open SelectAndMail.mxd.
  3. From the Catalog window, navigate to the Home Go To Home Folder directory. Expand the Models toolset of SelectParcel.tbx and double-click SelectAndMail to open the tool dialog box.
    1. For the first parameter Parcel ID, you can set the ID you would like to select or use the default value.
    2. For the parameter Search Distance, you can set the distance and unit or use the default value.
    3. For the parameter Selected Parcels, you can set your own output path or use the default value. This is where you save the feature class of selected parcels.
    4. For the parameter OutputTxt, you can set your own output text file path or use the default value. This is where you save the text file that shows the values of parcel ID and addresses.
  4. Click OK to run the tool.
  5. If the Results window is not open, click Geoprocessing > Results on the ArcMap pull down menu.
  6. In the Current Session node of the Results window, examine the SelectAndMail result created by the steps above.

    The result should display the model tool icon Model. If an error Error is displayed, you'll need to expand the result, read the error message contained in the Messages node, then rerun the tool with modifications until a valid result is created.

    To examine the contents of the output text file, expand the result in the Results window and double-click Output.txt to open the file in your default text editor.

  7. To share the model task as a geoprocessing service:
    1. Right-click the result in the Results window and select Share As > Geoprocessing Service.
    2. The Share as Service window opens and displays three options. Check the option Publish a service and click Next.
    3. Select the server administration connection you created previously in Choose a connection and provide a service name in Service name. Click Next.

      When providing the Service name, if you leave the default name SelectAndMail, your service and task name will be the same. If you would like the service name to be different than the task name, provide a different service name.

    4. Choose either Use existing folder or Create new folder and click Continue to bring up Service Editor window.
    5. In the left pane of Service Editor, click Parameters. In the right pane of Service Editor, navigate to Maximum number of records returned by the server under Properties. Change the default value 1000 to 2000 because the number of output features may exceed 1000.
    6. Click Publish on the upper right corner of the Service Editor. A Copying Data to Server window appears showing the layer Parcel will be uploaded to the server. Click OK.
    7. You will see two windows: Package in progress and Package in Service. These will be followed by a Succeeded window with a message Successfully published service when publishing is done. Click OK to finish the publishing process.

Run SelectAndPrint and share the result

    Run the SelectAndPrint model tool to create a result in the Results window that you can share as a service. To run the tool:
  1. From the Catalog window, navigate to C:\arcgis\ArcTutor\GP Service Examples\SelectedParcelMap. If you do not want to run from the directory, copy and paste to a local directory.
  2. Open SelectAndPrint.mxd.
  3. From the Catalog window, navigate to the Home Go To Home Folder directory. Expand the Models toolset of SelectParcel.tbx and double-click SelectAndPrint to open the tool dialog box.
    1. For first parameter Parcel ID, you can set the ID you would like to select or use the default value.
    2. For the parameter Search Distance, you can set the distance and unit or use the default value.
    3. For the parameter Selected Parcels, you can set your own output path or use the default value. This is where you save the feature class of selected parcels.
    4. For the parameter OutputPDF, you can set your own output PDF file path or use the default value. This is where you save your selected parcels in a Map file with PDF format.
  4. Click OK to run the tool.
  5. If the Results window is not open, click Geoprocessing > Results on the ArcMap main menu.
  6. In the Current Session node of the Results window, examine the SelectAndPrint result created by the steps above.

    The result should display the model tool icon Model. If an error Error is displayed, you'll need to expand the result, read the error message contained in the Messages node, then rerun the tool with modifications until a valid result is created.

    To examine the contents of the output PDF file, expand the result in the Results window and double-click OutputPDF.pdf to open the file.

  7. To share the model task as a geoprocessing service, follow the next steps:
    1. Right-click the model tool icon that you ran in the previous step and select Share As > Geoprocessing Service.
    2. A Share as Service window displays with three options. Check the option Publish a service and click Next.
    3. Select the server administration connection you created previously in Choose a connection and provide a service name in Service name. Click Next.

      When providing the Service name, if you leave the default name SelectAndPrint, your service and task name will be the same. If you would like the service name to be different than the task name, provide a different service name.

    4. Choose either Use existing folder or Create new folder and click Continue to bring up Service Editor window.
    5. Click Publish on the upper right corner of the Service Editor. A Copying Data to Server window appears showing the layer Parcel, and the Map file SelectAndPrint.mxd will be uploaded to the server. Click OK.
    6. You will see two windows: Package in progress and Package in Service. These will be followed by a Succeeded window with a message Successfully published service when publishing is done. Click OK to finish the publishing process.

Use map and geoprocessing service

The following steps show how to use the map service ParcelBaseMap and the two geoprocessing services SelectAndMail and SelectAndPrint that you previously published.

Use SelectAndMail service

  1. Open a new ArcMap document.
  2. In the Catalog window
    1. Navigate to your server connection under GIS Servers, select the map service ParcelBaseMap, and drag it into the ArcMap table of contents.
    2. Expand the map service in the table of contents to view the Parcels layer.
  3. In the Catalog window, navigate to your server connection under GIS Servers, find the geoprocessing service SelectAndMail that you published in the previous section. Expand the service to see the task SelectAndMail.
  4. Double-click the task SelectAndMail to open the task dialog box.
  5. Keep the default value of the parameters or provide your own values, and click OK to run the task.
  6. The output file Output will be added to the table of contents as a table.
  7. Check the Results window. Under the session Current Session and task SelectAndMail, you should see the output text file Output.txt.
  8. Open Output.txt by double-clicking the file in the result. You can see the content containing the attributes and values of Parcel ID and Address of the selected parcels.

Use SelectAndPrint service

  1. Open a new ArcMap document.
  2. In the Catalog window
    1. Navigate to your server connection under GIS Servers, select the map service ParcelBaseMap, and drag it into the ArcMap table of contents.
    2. Expand the map service in the table of contents to view the Parcels layer.
  3. In the Catalog window, navigate to your server connection under GIS Servers, find the geoprocessing service SelectAndPrint that you published in the previous section. Expand the service to see the task SelectAndPrint.
  4. Double-click the task SelectAndPrint to open the task dialog box.
  5. Keep the default value of the parameters or provide your own values, and click OK to run the task.
  6. Check the Results window. Under the session Current Session and task SelectAndPrint you will see the output file OutputPDF.pdf.
  7. Open OutputPDF.pdf by double-clicking it in the result. You will see a map file in PDF format showing the selected parcels.
Related topics