Create contour lines from local raster data using a local geoprocessing package .gpk
and the contour geoprocessing tool.
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
- Create and run a local server with
LocalServer.Instance
. - Start the server asynchronously with
server.StartAsync()
. - Start a
LocalGeoprocessingService
and run aGeoprocessingTask
.- Instantiate
LocalGeoprocessingService(Url, ServiceType)
to create a local geoprocessing service. - Call
LocalGeoprocessingService.StartAsync()
to start the service asynchronously. - Instantiate
GeoprocessingTask(LocalGeoprocessingService.Url + "/Contour")
to create a geoprocessing task that uses the contour lines tool.
- Instantiate
- Create an instance of
GeoprocessingParameters
.- Instantiate
GeoprocessingParameters(ExecutionType)
creates geoprocessing parameters. - Create a parameter using
gpParams.Inputs["ContourInterval"] = new GeoprocessingDoublevalue)
using the desired contour value.
- Instantiate
- Create and start a
GeoprocessingJob
using the previous parameters.- Create a geoprocessing job with
GeoprocessingTask.CreateJob(GeoprocessingParameters)
. - Start the job with
GeoprocessingJob.Start()
.
- Create a geoprocessing job with
- Add contour lines as an
ArcGISMapImageLayer
to the map.- Get url from local geoprocessing service using the
service.Url
property. - Get server job id of geoprocessing job using the
GeoprocessingJob.ServerJobId
property. - Replace
GPServer
from url withMapServer/jobs/jobId
, to get generate contour lines data. - Create a map image layer from that new url and add that layer to the map.
- Get url from local geoprocessing service using the
Relevant API
- GeoprocessingDouble
- GeoprocessingJob
- GeoprocessingParameter
- GeoprocessingParameters
- GeoprocessingTask
- LocalGeoprocessingService
- LocalGeoprocessingService.ServiceType
- LocalServer
- LocalServerStatus
Offline data
This sample downloads the following items from ArcGIS Online automatically:
- Contour.gpkx - A Geoprocessing Package for generating contour lines.
- RasterHillshade.tpkx - A tile package for the hillshade.
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
<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 Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3"
FontWeight="SemiBold"
Text="Use the slider to select a contour interval (height difference between contour lines). Use the buttons to update or clear the contours."
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"
Margin="0,5,0,0"
VerticalAlignment="Center"
Maximum="350"
Minimum="50" />
<TextBlock x:Name="MyContourDepthLabel"
Grid.Row="2"
Grid.Column="2"
Margin="0,5,0,0"
VerticalAlignment="Center"
Text="{Binding Value, ElementName=MyContourSlider, StringFormat=N2}"
TextAlignment="Center" />
<Button x:Name="MyUpdateContourButton"
Grid.Row="3"
Grid.Column="0"
Margin="0,5,5,0"
Click="MyUpdateContourButton_OnClick"
Content="Generate"
IsEnabled="False" />
<Button x:Name="MyResetButton"
Grid.Row="3"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="5,5,0,0"
Click="MyResetButton_OnClick"
Content="Reset"
IsEnabled="False" />
</Grid>
</Border>
</Grid>
</UserControl>