Local server geoprocessing

View on GitHub
Sample viewer app

Create contour lines from local raster data using a local geoprocessing package .gpk and the contour geoprocessing tool.

Image of local server geoprocessing

Use case

For executing offline geoprocessing tasks in your ArcGIS Runtime apps via an offline (local) server.

How to use the sample

Contour Line Controls (Top Left):

  • Interval - Specifies the spacing between contour lines.
  • Generate Contours - Adds contour lines to map using interval.
  • Clear Results - Removes contour lines from map.

How it works

  1. Create and run a local server with LocalServer.Instance.
  2. Start the server asynchronously with server.StartAsync().
  3. Start a LocalGeoprocessingService and run a GeoprocessingTask.

    1. Instantiate LocalGeoprocessingService(Url, ServiceType) to create a local geoprocessing service.
    2. Call LocalGeoprocessingService.StartAsync() to start the service asynchronously.
    3. Instantiate GeoprocessingTask(LocalGeoprocessingService.Url + "/Contour") to create a geoprocessing task that uses the contour lines tool.
  4. Create an instance of GeoprocessingParameters.

    1. Instantiate GeoprocessingParameters(ExecutionType) creates geoprocessing parameters.
    2. Create a parameter using gpParams.Inputs["ContourInterval"] = new GeoprocessingDoublevalue) using the desired contour value.
  5. Create and start a GeoprocessingJob using the previous parameters.

    1. Create a geoprocessing job with GeoprocessingTask.CreateJob(GeoprocessingParameters).
    2. Start the job with GeoprocessingJob.Start().
  6. Add contour lines as an ArcGISMapImageLayer to the map.

    1. Get url from local geoprocessing service using the service.Url property.
    2. Get server job id of geoprocessing job using the GeoprocessingJob.ServerJobId property.
    3. Replace GPServer from url with MapServer/jobs/jobId, to get generate contour lines data.
    4. Create a map image layer from that new url and add that layer to the map.

Relevant API

  • GeoprocessingDouble
  • GeoprocessingJob
  • GeoprocessingParameter
  • GeoprocessingParameters
  • GeoprocessingTask
  • LocalGeoprocessingService
  • LocalGeoprocessingService.ServiceType
  • LocalServer
  • LocalServerStatus

Offline data

This sample downloads the following items from ArcGIS Online automatically:

Additional information

Local Server can be downloaded for Windows and Linux platforms from the developers website. Local Server is not supported on macOS.

Tags

geoprocessing, local, offline, parameters, processing, service

Sample Code

LocalServerGeoprocessing.xamlLocalServerGeoprocessing.xaml.cs
                                                    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<UserControl x:Class="ArcGISRuntime.WPF.Samples.LocalServerGeoprocessing.LocalServerGeoprocessing"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock
                    Text="Use the slider to select a contour interval (height difference between contour lines). Use the buttons to update or clear the contours."
                    Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
                    FontWeight="SemiBold" TextWrapping="Wrap" />
                <ProgressBar x:Name="MyLoadingIndicator"
                             Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"
                             Height="15" Margin="0,5,0,0"
                             IsIndeterminate="True" />
                <Slider x:Name="MyContourSlider"
                        Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                        VerticalAlignment="Center" Margin="0,5,0,0"
                        Minimum="50" Maximum="350" />
                <TextBlock x:Name="MyContourDepthLabel"
                           Grid.Row="2" Grid.Column="2"
                           VerticalAlignment="Center" Margin="0,5,0,0"
                           TextAlignment="Center"
                           Text="{Binding Value, ElementName=MyContourSlider, StringFormat=N2}" />
                <Button x:Name="MyUpdateContourButton"
                        Grid.Row="3" Grid.Column="0"
                        Content="Generate"
                        Margin="0,5,5,0"
                        IsEnabled="False"
                        Click="MyUpdateContourButton_OnClick" />
                <Button x:Name="MyResetButton"
                        Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2"
                        Content="Reset"
                        Margin="5,5,0,0"
                        IsEnabled="False"
                        Click="MyResetButton_OnClick" />
            </Grid>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.