ArcGIS GPConsole


Purpose
This sample demonstrates how to work with geoprocessing via ArcObjects, both locally and on ArcGIS Server (the server). To work with geoprocessing locally, an ArcGIS Engine license is required, depending on which geoprocessing tool you use. To work with geoprocessing on the server, ArcGIS Server must be available and the current user must be in the agsusers or agsadmin groups on the server.
 
This sample uses the prepackaged CreateFeatureclass and CopyFeatures tools as well as a custom BufferPoints model (located in the BufferTools toolbox included with the sample data).
 
It is assumed in this sample that a geoprocessing service has been created from the BufferTools toolbox included with the sample data. The BufferTools toolbox contains the BufferPoints model. The BufferPoints model accepts two inputs: an input feature set (points) and a linear unit (buffer distance). The output is a feature set containing the buffer geometry. The input feature set determines the type of geometry that the model can buffer, as well as its spatial reference. In this sample, the InputPoints.lyr layer file defines the input geometry as point and the spatial reference as NAD_1983_Texas_Statewide_Mapping_System. The model solves for input and output data in this spatial reference.
 
Data references are provided in this sample to illustrate that multiple data types can be used with geoprocessing functions. 

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample.

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/GP/RunBuffer/BufferTools.tbx.
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the appropriate services are available (see the Purpose section for details).
  2. In Windows Explorer, navigate to <ArcGIS Developer Kit install location>\Samples\ServerNET\ArcGIS_GPConsole.
  3. Open the CSharp directory, open ArcGIS_GPConsole_CSharp.sln in Visual Studio, and open the Program.cs file.
  4. If you're using ArcGIS Server (using ArcObjects remotely), set the servername variable.
  5. If you're using geoprocessing locally, and you have an ArcGIS Engine license, set the esriLicenseCode variable appropriately.
  6. Change the ESRI.ArcGIS.Geoprocessor.Geoprocessor constructor to reference a local (no parameters) or remote (server context parameter) geoprocessor.
  7. In the CreateFeatureclass tool section of the code, change the out_name and out_path parameters on the tool before execution. The out_name parameter is the name of the feature class. The out_path parameter is where it is created.
  8. In the CopyFeatures tool section of the code, define an input and output data source, and change the input and output file and feature classes appropriately. If you're working with geoprocessing in ArcGIS Server, the server object container (SOC) account needs to have read access for the input file and feature class location and read and write access to the output file and feature class location.
  9. Select to use the geoprocessor to execute a custom tool on the server or to use IGPServer to work with a published geoprocessing service.
  10. In Visual Studio, click the Debug drop-down menu and click Start Debugging.

At run time
  1. The console window displays the results of the geoprocessing tasks.

Additional information

The methods for working with geoprocessing services and the Microsoft .NET Framework are as follows (the first two methods are presented in this sample):
  • Work with a geoprocessor in a local .NET assembly. This is the recommended method of executing tools within system toolboxes and custom toolboxes that are local or on a server. The ESRI.ArcGIS.Geoprocessor.Geoprocessor .NET class wraps an IGeoprocessor Component Object Model (COM) object and can be created for both local and remote geoprocessing functions. The wrapper provides you with better design-time information (IntelliSense) than working with COM objects and interfaces. When working with published server tools, a server context is not required. It does not provide data type information for tools or models explicitly. More information about tool or model parameters can be found using these ArcObjects: IToolboxWorkspace, IGPToolbox, IGPTool, and IGPParameter.
  • Work with a published geoprocessing service via the ESRI.ArcGIS.Geoprocessing.IGPServer interface (you must have local access to the server object manager [SOM]). IGPServer provides full control over task execution on the geographic information system (GIS) server and as a server object. It works with a specific set of geoprocessing value types provided in ESRI.ArcGIS.Geoprocessing. You can define a set of features entered by the user, as well as work with layers in an associated map document.
  • Work with a published geoprocessing service via a Web service endpoint. The Web service provides a geoprocessing service-specific Web Service Description Language (WSDL) that can be used to generate a set of client-side value objects and a Web service proxy to work with geoprocessing on the GIS server. The value objects include a set of geoprocessing-specific types (prefixed GP*), and the Web service proxy provides a set of methods to submit asynchronous jobs, execute synchronous jobs, check their status, get results, and so on. This option can be used without installing ESRI software.
  • Work directly with the GeoProcessor COM object. A reference to ESRI.ArcGIS.Geoprocessing.GeoProcessor can be created locally (via GeoProcessorClass) or on the server via a server context.


ArcGIS_GPConsole_CSharp\ArcGIS_GPConsole\Program.cs Executable class containing the geoprocessing logic.
ArcGIS_GPConsole_CSharp\ArcGIS_GPConsole\LicenseInitializer.cs Class library used to check out a license for an ArcGIS Engine application.
Download the C# files
ArcGIS_GPConsole_VBNet\ArcGIS_GPConsole\Program.vb Executable class containing the geoprocessing logic.
ArcGIS_GPConsole_VBNet\ArcGIS_GPConsole\LicenseInitializer.vb Class library used to check out a license for an ArcGIS Engine application.
Download the VB.NET files

Download the files for all languages