Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Analyze hotspots

This code sample is available for these platforms:
View Sample on GitHub

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

Image of analyze hotspots

Use case

This tool identifies statistically significant spatial clusters of high values (hot spots) and low values (cold spots). For example, a hotspot analysis based on the frequency of 911 calls within a set region.

How to use the sample

Select a date range (between 1998-01-01 and 1998-05-31) from the dialog and tap on Analyze. The results will be shown on the map upon successful completion of the GeoprocessingJob.

How it works

  1. Create a GeoprocessingTask with the URL set to the endpoint of a geoprocessing service.
  2. Create a query string with the date range as an input of GeoprocessingParameters.
  3. Use the GeoprocessingTask to create a GeoprocessingJob with the GeoprocessingParameters instance.
  4. Start the GeoprocessingJob and wait for it to complete and return a GeoprocessingResult.
  5. Get the resulting ArcGISMapImageLayer using GeoprocessingResult.MapImageLayer.
  6. Add the layer to the map's operational layers.

Relevant API

  • GeoprocessingJob
  • GeoprocessingParameters
  • GeoprocessingResult
  • GeoprocessingTask


Geoprocessing, GeoprocessingJob, GeoprocessingParameters, GeoprocessingResult

Sample Code

        <Style TargetType="TextBlock">
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="Margin" Value="0,5,0,0" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Right" />
        <Style TargetType="DatePicker">
            <Setter Property="Margin" Value="5,5,0,0" />
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}" Width="Auto">
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                <TextBlock Text="Select a date range for analysis."
                           Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                           Margin="0" HorizontalAlignment="Stretch"
                           TextWrapping="Wrap" TextAlignment="Center" />
                <TextBlock Text="From:"
                           Grid.Row="1" Grid.Column="0" />
                <DatePicker x:Name="FromDate"
                            Grid.Row="1" Grid.Column="1"
                            HorizontalAlignment="Stretch" />
                <TextBlock Text="To:"
                           Grid.Row="2" Grid.Column="0" />
                <DatePicker x:Name="ToDate"
                            Grid.Row="2" Grid.Column="1"
                            HorizontalAlignment="Stretch" />
                <Button Content="Run analysis"
                        Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
                        Margin="0,5,0,0" HorizontalAlignment="Stretch"
                        Click="OnAnalyzeHotspotsClicked" />
                <Grid x:Name="BusyOverlay"
                      Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Grid.ColumnSpan="2"
                    <Border HorizontalAlignment="Center"
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            <ProgressBar x:Name="Progress"
                                         Height="20" />
                            <TextBlock Text="Executing analysis..."
                                       Margin="5" Height="20" />
                            <Button Content="Cancel"
                                    Click="OnCancelTaskClicked" />
// 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 Windows.UI.Popups;
using Windows.UI.Xaml;

namespace ArcGISRuntime.UWP.Samples.AnalyzeHotspots
        name: "Analyze hotspots",
        category: "Geoprocessing",
        description: "Use a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.",
        instructions: "Select a date range (between 1998-01-01 and 1998-05-31) from the dialog and tap on Analyze. The results will be shown on the map upon successful completion of the `GeoprocessingJob`.",
        tags: new[] { "Geoprocessing", "GeoprocessingJob", "GeoprocessingParameters", "GeoprocessingResult" })]
    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());

            // Set the initial start date for the DatePicker defined in xaml
            DateTimeOffset myFromDate = new DateTimeOffset(new DateTime(1998, 1, 1));
            FromDate.Date = myFromDate;

            // Set the initial end date for the DatePicker defined in xaml
            DateTimeOffset myToDate = new DateTimeOffset(new DateTime(1998, 1, 31));
            ToDate.Date = myToDate;

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

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

            // Hide the BusyOverlay indication

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

            // Show the BusyOverlay indication

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

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

                // Remove the BusyOverlay

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

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

            // 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)
                    MessageDialog message = new MessageDialog("Executing geoprocessing failed. " + _hotspotJob.Error.Message, "Geoprocessing error");
                    await message.ShowAsync();
                    MessageDialog message = new MessageDialog("An error occurred. " + ex.ToString(), "Sample error");
                    await message.ShowAsync();
                // Remove the BusyOverlay

        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. BusyOverlay 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 BusyOverlay is invisible.
                BusyOverlay.Visibility = Visibility.Collapsed;
                Progress.IsIndeterminate = false;