Geoprocessing services


Local (DCOM) connections are only supported for ArcGIS Server versions prior to 10.1.

About geoprocessing
The basis of any geographic information system (GIS) application is geographic data that is modeled as a GIS dataset stored in a database or a file. These datasets can represent raw measurements (for example, satellite imagery), information interpreted and compiled by analysts (for example, roads, buildings, and soil types), or information derived from other data sources using analysis and modeling algorithms. Geoprocessing is the process of using tools to generate derived datasets from other datasets.
Geoprocessing is used to model how data flows from one structure to another to perform many common GIS tasks—for example, to import data from numerous formats, integrate that data into the GIS, and perform a number of standards-quality validation checks against the imported data—as well as to perform powerful analysis and modeling. Geoprocessing is used in almost all phases of a GIS, and some of those phases are described in this topic.

Data compilation

Data compilation procedures are automated using geoprocessing to ensure data quality and integrity, and to perform repetitive quality assurance/quality control (QA/QC) tasks. Automating these workflows with geoprocessing helps to share and communicate a series of procedures, perform batch processing flows, and document the key processes for derived data.

Analysis and modeling

Geoprocessing is the key framework for modeling and analysis. Common modeling applications include the following:
  • Models for suitability and capability, prediction, and assessment of alternative scenarios
  • Integration of external models
  • Model sharing

Data management

Managing GIS dataflow is critical in GIS applications. GIS users apply geoprocessing functions to move data in and out of databases; publish data in many formats, such as Geography Markup Language (GML) profiles; join adjacent datasets; update GIS database schemas; and perform batch processes on GIS databases.

Cartography

Advanced geoprocessing tools are used to derive multiscale cartographic representations, perform generalization logic, and automate much of the cartographic QA/QC workflows for print-quality map products.
ArcGIS for Server for the .NET Framework includes a set of tools and a geoprocessing framework to work with and process geographic information. This collection of tools is used to operate on GIS information objects, such as datasets, attribute fields, and cartographic elements for printed maps. These tools can be used as building blocks for assembling multistep operations, enabling users to automate workflows, program analytical models, and build recurring procedures.
Users can compose such processes graphically using the ModelBuilder application in ArcGIS for Desktop; and they can compose scripts using modern scripting tools, such as Python, VBScript, and JavaScript. Developers can use .NET to build applications that string together a collection of tools, models, or scripts.
The following illustration shows an example ModelBuilder application:

Extensions and tools

ArcGIS for Server for .NET contains a comprehensive collection of geoprocessing functions, including tools for the following:
  • Data management
  • Data conversion
  • Coverage processing
  • Vector analysis
  • Geocoding
  • Linear referencing
  • Cartography
  • Statistical analysis
Additional geoprocessing tools come with many of the ArcGIS  extensions, such as the Spatial Analyst extension, which includes approximately 200 raster modeling tools, and the 3D Analyst extension, which includes triangulated irregular network (TIN) and terrain analysis tools. The Network Analyst extension includes transportation and network tools. The Geostatistical Analyst extension adds kriging and surface interpolation tools. The Data Interoperability extension includes tools for converting data between a variety of formats.
An ArcGIS for Server application can include the execution of a geoprocessing tool, script, or model created using ModelBuilder. The results of a geoprocessing function are typically new datasets that can be downloaded, integrated into maps, queried, and used as inputs for further geoprocessing. For example, a web application can include functions for extracting data from a geodatabase based on the extent of a map, and you can download that extracted dataset to the client machine in a format specified by the user in the application.

Toolboxes and assemblies

The various geoprocessing tools included with ArcGIS for Server for .NET are organized in a collection of toolboxes. In addition, you can create your geoprocessing script, model, or custom tools, and organize them (along with standard tools included with the software) in your toolboxes that you manage as files, or in a geodatabase. You can execute a tool (including models and scripts) as part of your ArcGIS Server applications and services.
As part of the software development kit (SDK) for the Web Application Developer Framework (ADF), tools are integrated with the Visual Studio .NET integrated development environment (IDE) allowing you to generate a managed .NET assembly from a toolbox (system toolbox or custom toolbox). The generated assembly includes a class for each tool in the toolbox that you can use to set up and run geoprocessing tools in the server. These classes are used in conjunction with the Geoprocessor class in the ESRI.ArcGIS.GeoProcessor.dll.
ArcGIS for Desktop must be installed to create this managed assembly.
The assembly generated by the Add ArcGIS Toolbox Reference tool is a thin wrapper around the toolbox and its tools. The classes in the assembly are used to set up the tool's parameters passed down to the geoprocessor that executes the appropriate tool in the toolbox. The process that executes the tool (in the case of the server, the server object container [SOC] process) must have access to the original toolbox from which the assembly was generated. When generating an assembly for use in the server, the toolbox must be one of the following:
  • Located on a shared network drive, accessible from all SOC machines.
  • Located in a geodatabase that can be connected to the SOC machines.
  • If the assembly is generated from a system toolbox (located in \ArcGIS\ArcToolbox\Toolboxes), ArcGIS must be installed in the same location on each SOC machine.
Each generated assembly includes a config file called <assembly_name>.config that includes a path to the toolbox that can be updated if the toolbox is moved after the assembly is generated.

Example

Below is an example showing how to execute (in a client application) a geoprocessing tool published on an ArcGIS Server using ArcObjects. A comprehensive sample is also available under <ArcGIS DeveloperKit install location>/Samples/ServerNet/ArcGIS_GPConsole sample.
[C#]
public static void GPServer_Example()
{
    IServerContext serverContext = null;
    try
    {
        GISServerConnection serverConnection = new GISServerConnection();
        serverConnection.Connect("LocalHost");
        IServerObjectManager serverManager = serverConnection.ServerObjectManager;
        serverContext = serverManager.CreateServerContext("BufferTools", "GPServer");
        IGPServer gpServer = null;
        gpServer = serverContext.ServerObject as IGPServer;
        IGPServer gpserver = (IGPServer)serverContext.ServerObject;
        string taskname = "BufferPoints";
        IGPToolInfo task = gpserver.GetToolInfo(taskname);
        IGPValues taskvals = (IGPValues)serverContext.CreateObject(
            "esriGeoprocessing.GPValues");
        IGPParameterInfos paramInfos = task.ParameterInfo;
        IGPParameterInfo paramInfo;
        string parameterNameString = string.Empty;
        for (int i = 0; i < paramInfos.Count; i++)
        {
            // Data type available as part of IGPParameterInfo
            paramInfo = paramInfos.get_Element(i);
            taskvals.Add(paramInfo.Value);
            //Add to parameter name array
            parameterNameString += paramInfo.Name;
            if (i != paramInfos.Count - 1)
                parameterNameString += ";";
        }
        IGPRecordSet gprecset = (IGPRecordSet)taskvals.get_Element(0);
        IQueryFilter qf = (IQueryFilter)serverContext.CreateObject(
            "esriGeodatabase.QueryFilter");
        gprecset.RecordSet.Table.DeleteSearchedRows(qf);
        IRecordSet rs = gprecset.RecordSet;
        IFields flds = rs.Fields;
        int shpfldindex = flds.FindField("Shape");
        IField fld = flds.get_Field(shpfldindex);
        ISpatialReference inputsr = fld.GeometryDef.SpatialReference;
        IRecordSetInit rsi = (IRecordSetInit)rs;
        ICursor cur = rsi.Insert();
        IRowBuffer rb = rsi.CreateRowBuffer();
        IPoint ipnt = (IPoint)serverContext.CreateObject("esriGeometry.Point");
        ipnt.PutCoords(1000000, 1000000);
        rb.set_Value(shpfldindex, ipnt);
        cur.InsertRow(rb);
        IGPValues invals = (IGPValues)serverContext.CreateObject(
            "esriGeoprocessing.GPValues");
        invals.Add((IGPValue)gprecset);
        IGPLinearUnit gpLU = (IGPLinearUnit)serverContext.CreateObject(
            "esriGeoprocessing.GPLinearUnit");
        gpLU.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
        gpLU.Value = 1000000;
        invals.Add((IGPValue)gpLU);
        string JobID = gpserver.SubmitJob(taskname, invals);
        while (gpserver.GetJobStatus(JobID) != esriJobStatus.esriJobSucceeded)
        {
            System.Threading.Thread.Sleep(5000);
        }
        IStringArray stringArray = (IStringArray)new
            ESRI.ArcGIS.esriSystem.StrArrayClass();
        foreach (string paramName in parameterNameString.Split(';'))
        {
            stringArray.Add(paramName);
        }
        /* GetJobResult(): second parameter can be: 
         * IStringArray of all parameters
         * IStringArray of only output parameters
         * null if you want all output parameters
         */
        IGPResult result = gpserver.GetJobResult(JobID, stringArray, null);
        IJobMessages jobMsgs = result.Messages;
        for (int i = 0; i < jobMsgs.Count; i++)
        {
            Console.WriteLine(jobMsgs.get_Element(i).Description);
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
        System.Diagnostics.Debug.WriteLine(ex.StackTrace);
    }
    finally
    {
        serverContext.ReleaseContext();
    }
[VB.NET]
Public Shared Sub RunGPServerExample()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As GISServerConnection
serverConnection = New GISServerConnection()
serverConnection.Connect(servername)
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
serverContext = serverManager.CreateServerContext("BufferTools", "GPServer")
Dim gpserver As IGPServer = CType(serverContext.ServerObject, IGPServer)
Dim taskname As String = "BufferPoints"
Dim task As IGPToolInfo = gpserver.GetToolInfo(taskname)
Dim taskvals As IGPValues = CType(serverContext.CreateObject("esriGeoprocessing.GPValues"), IGPValues)
Dim paramInfos As IGPParameterInfos = task.ParameterInfo
Dim paramInfo As IGPParameterInfo
Dim parameterNameString As String = String.Empty
For i As Integer = 0 To paramInfos.Count - 1
    ' Data type available as part of IGPParameterInfo
    paramInfo = paramInfos.Element(i)
    taskvals.Add(paramInfo.Value)
    'Add to parameter name array
    parameterNameString & = paramInfo.Name
    If i <> paramInfos.Count - 1 Then
        parameterNameString & = ";"
    End If
Next i
Dim gprecset As IGPRecordSet = CType(taskvals.Element(0), IGPRecordSet)
Dim qf As IQueryFilter = CType(serverContext.CreateObject("esriGeodatabase.QueryFilter"), IQueryFilter)
gprecset.RecordSet.Table.DeleteSearchedRows(qf)
Dim rs As IRecordSet = gprecset.RecordSet
Dim flds As IFields = rs.Fields
Dim shpfldindex As Integer = flds.FindField("Shape")
Dim fld As IField = flds.Field(shpfldindex)
Dim inputsr As ISpatialReference = fld.GeometryDef.SpatialReference
Dim rsi As IRecordSetInit = CType(rs, IRecordSetInit)
Dim cur As ICursor = rsi.Insert()
Dim rb As IRowBuffer = rsi.CreateRowBuffer()
Dim ipnt As IPoint = CType(serverContext.CreateObject("esriGeometry.Point"), IPoint)
ipnt.PutCoords(1000000, 1000000)
rb.Value(shpfldindex) = ipnt
cur.InsertRow(rb)
Dim invals As IGPValues = CType(serverContext.CreateObject("esriGeoprocessing.GPValues"), IGPValues)
invals.Add(CType(gprecset, IGPValue))
Dim gpLU As IGPLinearUnit = CType(serverContext.CreateObject("esriGeoprocessing.GPLinearUnit"), IGPLinearUnit)
gpLU.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters
gpLU.Value = 1000000
invals.Add(CType(gpLU, IGPValue))
Dim JobID As String = gpserver.SubmitJob(taskname, invals)
Do While gpserver.GetJobStatus(JobID) <> esriJobStatus.esriJobSucceeded
    System.Threading.Thread.Sleep(5000)
Loop
Dim stringArray As IStringArray = CType(New ESRI.ArcGIS.esriSystem.StrArrayClass(), IStringArray)
For Each paramName As String In parameterNameString.Split(";"c)
    stringArray.Add(paramName)
Next paramName

'The resultant featureclass gets generated in folder uner <C:\arcgisserver\arcgisJobs\<abd9930839dg9330123
Dim result As IGPResult = gpserver.GetJobResult(JobID, stringArray, Nothing)
If result.Messages IsNot Nothing Then
    Dim jobMsgs As IJobMessages = result.Messages
    For i As Integer = 0 To jobMsgs.Count - 1
        Console.WriteLine(jobMsgs.Element(i).Description)
    Next i
End If
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex.Message)
System.Diagnostics.Debug.WriteLine(ex.StackTrace)
Finally
serverContext.ReleaseContext()
End Try
End Sub