Click or drag to resize

GeoprocessingTask Class

GeoprocessingTask is used to run geoprocessing task that is published as a web service.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Tasks.Geoprocessing
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version:
public sealed class GeoprocessingTask

The GeoprocessingTask type exposes the following members.

Public methodGeoprocessingTask Obsolete.
Initializes a new instance of the GeoprocessingTask class.
Public propertyCredential
Gets or sets the security credential used to access a remote task
Public propertyGeoprocessingTaskInfo
Gets the metadata of this geoprocessing task.
Public propertySource
Gets the source URL that points to a task within a ArcGIS REST geoprocessing service
Public methodStatic memberCode exampleCreateAsync
Initializes a new instance of the GeoprocessingTask class with the given URL that points to a task within an ArcGIS REST geoprocessing service.
Public methodCode exampleCreateDefaultParametersAsync
Creates default parameters for a geoprocessing task.
Public methodCode exampleCreateJob
Returns a job that when started will run a geoprocessing task on the service.
GeoprocessingTask is the main component when running geoprocessing tasks. The task might be published through ArcGIS Server or Local server (on the platforms that supports it) using either synchronous execute or asynchronous submit execution type. When GeoprocessingParameters is created it is important to match GeoprocessingExecutionType to the value on the service. 1. Create GeoprocessingTask using full URL to the target geoprocessing task endpoint. 2. Create GeoprocessingParameters providing corresponding GeoprocessingExecutionType 3. Create needed GeoprocessingParameters and add them to Inputs where key is the name of the parameter and value is created parameter. 4. Set environmental variables on GeoprocessingParameters if needed. 5. Create GeoprocessingJob with CreateJob(GeoprocessingParameters). 6. Start listening for status and message changes using JobChanged event. 7. Run targeted geoprocessing tool using GetResultAsync which returns GeoprocessingResult when finished. 8. Handle returned values accordingly. Access output parameters through Outputs dictionary where key is the name of the output parameter and the value is returned parameter. If used geoprocessing service is configured to use result map service MapImageLayer might be created for you.


Example Name: AnalyzeHotspots

Use a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.

Code example screen shot.

// Copyright 2016 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using System;
using System.Threading.Tasks;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.AnalyzeHotspots
        "Analyze hotspots",
        "This sample demonstrates how to execute the GeoprocessingTask asynchronously to calculate a hotspot analysis based on the frequency of 911 calls. It calculates the frequency of these calls within a given study area during a specified constrained time period set between 1/1/1998 and 5/31/1998.",
        "To run the hotspot analysis, select a data range and click on the 'Run analysis' button. Note the larger the date range, the longer it may take for the task to run and send back the results.")]
    public partial class AnalyzeHotspots
        // URL for the geoprocessing service
        private const string _hotspotUrl = 

        // The geoprocessing task for hot spot analysis 
        private GeoprocessingTask _hotspotTask;

        // The job that handles the communication between the application and the geoprocessing task
        private GeoprocessingJob _hotspotJob;

        public AnalyzeHotspots()

            // Create the UI, setup the control references and execute initialization 

        private async void Initialize()
            // Create a map with a topographic basemap
            MyMapView.Map = new Map(Basemap.CreateTopographic());

                // Create a new geoprocessing task
                _hotspotTask = await GeoprocessingTask.CreateAsync(new Uri(_hotspotUrl));
            catch (Exception e)
                MessageBox.Show(e.ToString(), "Error");

        private async void OnAnalyzeHotspotsClicked(object sender, RoutedEventArgs e)
            // Clear any existing results

            // Show the waiting indication

            // Get the 'from' and 'to' dates from the date pickers for the geoprocessing analysis
            DateTime myFromDate = FromDate.SelectedDate.Value;
            DateTime myToDate = ToDate.SelectedDate.Value;

            // The end date must be at least one day after the start date
            if (myToDate <= myFromDate.AddDays(1))
                // Show error message
                    "Please select valid time range. There has to be at least one day in between To and From dates.", 
                    "Invalid date range");

                // Remove the waiting

            // Create the parameters that are passed to the used geoprocessing task
           GeoprocessingParameters myHotspotParameters = new GeoprocessingParameters(GeoprocessingExecutionType.AsynchronousSubmit);

            // Construct the date query
            string myQueryString = string.Format("(\"DATE\" > date '{0:yyyy-MM-dd} 00:00:00' AND \"DATE\" < date '{1:yyyy-MM-dd} 00:00:00')", myFromDate, myToDate);

            // Add the query that contains the date range used in the analysis
            myHotspotParameters.Inputs.Add("Query", new GeoprocessingString(myQueryString));

            // Create job that handles the communication between the application and the geoprocessing task
            _hotspotJob = _hotspotTask.CreateJob(myHotspotParameters);
                // Execute the geoprocessing analysis and wait for the results
                GeoprocessingResult myAnalysisResult = await _hotspotJob.GetResultAsync();

                // Add results to a map using map server from a geoprocessing task
                // Load to get access to full extent
                await myAnalysisResult.MapImageLayer.LoadAsync();

                // Add the analysis layer to the map view

                // Zoom to the results
                await MyMapView.SetViewpointAsync(new Viewpoint(myAnalysisResult.MapImageLayer.FullExtent));
            catch (TaskCanceledException)
                // This is thrown if the task is canceled. Ignore.
            catch (Exception ex)
                // Display error messages if the geoprocessing task fails
                if (_hotspotJob.Status == JobStatus.Failed && _hotspotJob.Error != null)
                    MessageBox.Show("Executing geoprocessing failed. " + _hotspotJob.Error.Message, "Geoprocessing error");
                    MessageBox.Show("An error occurred. " + ex, "Sample error");
                // Remove the waiting

        private void OnCancelTaskClicked(object sender, RoutedEventArgs e)
            // Cancel current geoprocessing job
            if (_hotspotJob.Status == JobStatus.Started)

            // Hide the waiting indication

        private void ShowBusyOverlay(bool visibility = true)
            // Function to toggle the visibility of interaction with the GUI for the user to 
            // specify dates for the hot spot analysis. When the analysis is running, the GUI
            // for changing the dates is 'grayed-out' and the progress bar with a cancel 
            // button (aka. waiting object) becomes active.

            if (visibility)
                // The geoprocessing task is processing. The busyOverly is present.
                BusyOverlay.Visibility = Visibility.Visible;
                Progress.IsIndeterminate = true;
                // The user can interact with the date pickers. The waiting is invisible.
                BusyOverlay.Visibility = Visibility.Collapsed;
                Progress.IsIndeterminate = false;
<UserControl x:Class="ArcGISRuntime.WPF.Samples.AnalyzeHotspots.AnalyzeHotspots"
             d:DesignHeight="300" d:DesignWidth="300">
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                <!-- Main form -->
                <TextBlock Text="Select a date range for analysis."
                           TextAlignment="Center" TextWrapping="Wrap" />
                <TextBlock Text="From"
                           Margin="5,5,5,0" Grid.Row="1"
                           FontWeight="Bold" />
                <DatePicker x:Name="FromDate"
                            HorizontalAlignment="Stretch" Margin="5" Grid.Row="2"
                            SelectedDate="1/01/98" DisplayDateStart="1/01/98" DisplayDateEnd="5/31/98" />
                <TextBlock Text="To"
                           Margin="5,5,5,0" Grid.Row="3"
                           FontWeight="Bold" />
                <DatePicker x:Name="ToDate"
                            HorizontalAlignment="Stretch" Margin="5" Grid.Row="4"
                            SelectedDate="1/31/98" DisplayDateStart="1/01/98" DisplayDateEnd="5/31/98" />
                <Button x:Name="AnalyzeButton"
                        Content="Run analysis"
                        Margin="5" Grid.Row="5"
                        Click="OnAnalyzeHotspotsClicked" />
                <!-- Waiting overlay -->
                <Grid x:Name="BusyOverlay"
                      Grid.Row="0" Grid.RowSpan="6"
                      Margin="-20" Visibility="Collapsed" Background="#8C000000">
                    <Border HorizontalAlignment="Center" VerticalAlignment="Center"
                            Padding="15" Background="#FFC6C4C4">
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                            <ProgressBar x:Name="Progress"
                                         IsIndeterminate="True" Height="20" />
                            <TextBlock Text="Executing analysis..."
                                       HorizontalAlignment="Center" Margin="5" Height="20" />
                            <Button Content="Cancel"
                                    HorizontalAlignment="Center" Grid.Row="1"
                                    Click="OnCancelTaskClicked" />
See Also
Additional Examples
Hyperlink to ExampleDescription
AnalyzeHotspotsUse a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.
AnalyzeViewshedCalculate a viewshed using a geoprocessing service, in this case showing what parts of a landscape are visible from points on mountainous terrain.
ListGeodatabaseVersionsThis sample calls a custom GeoprocessingTask to get a list of available versions for an enterprise geodatabase. The task returns a table of geodatabase version information, which is displayed in the app as a list.
LocalServerGeoprocessingCreate contour lines from local raster data using a local geoprocessing package `.gpk` and the contour geoprocessing tool.