Generate elevation profile with Local Server

View inWPFWinUI
View on GitHub

Create an elevation profile using a geoprocessing package executed with ArcGIS Runtime Local Server.

Image of local server generate elevation profile

Use case

Applications that include ArcGIS Runtime Local Server are valuable in offline workflows that require advanced spatial analysis or data manipulation. This sample uses a geoprocessing package (.gpkx) created in ArcGIS Pro involving a custom geoprocessing model that includes the Interpolate Shape (3D Analyst) geoprocessing tool. The geoprocessing package is executed with ArcGIS Runtime Local Server.

You can generate elevation profiles to carry out topographical analysis of valley profiles, or visualize a hiking, cycling, or road trip over varied topography.

How to use the sample

The sample loads at the full extent of the raster dataset. Click the "Draw Polyline" button and sketch a polyline along where you'd like the elevation profile to be calculated (the polyline can be any shape). Click the "Save" button to save the sketch and draw the polyline. Click "Generate Elevation Profile" to interpolate the sketched polyline onto the raster surface in 3D. Once ready, the view will automatically zoom onto the newly drawn elevation profile. Click "Clear Results" to reset the sample.

How it works

  1. Create a Raster from a raster dataset, and apply a series of RasterFunctions to mask any data at or below sea level.
  2. Start the Local Server instance with LocalServer.Instance.StartAsync().
  3. Start a LocalGeoprocessingService and create a GeoprocessingTask.
    1. Instantiate LocalGeoprocessingService(Url, ServiceType) to create a local geoprocessing service.
    2. Invoke LocalGeoprocessingService.StartAsync() to start the service asynchronously.
    3. Instantiate GeoprocessingTask.CreateAsync(LocalGeoprocessingService.Url + "/CreateElevationProfileModel") to create a geoprocessing task that uses the elevation profile tool.
  4. Create an instance of GeoprocessingParameters and get its list of inputs with GeoprocessingParameters.Inputs.
  5. Add GeoprocessingFeatures with a FeatureCollectionTable pointing to a polyline geometry, and GeoprocessingString with a path to the raster data on disk to the list of inputs.
  6. Create and start a GeoprocessingJob using the input parameters.
    1. Create a geoprocessing job with GeoprocessingTask.CreateJob(GeoprocessingParameters).
    2. Start the job with GeoprocessingJob.Start().
  7. Add generated elevation profile as a FeatureLayer to the scene.
    1. Get the url from the local geoprocessing service using LocalGeoprocessingService.Url.
    2. Get the server job id of the geoprocessing job using GeoprocessingJob.ServerJobId.
    3. Replace GPServer from the url with MapServer/jobs/jobId, to get generate elevation profile data.
    4. Create a ServiceGeodatabase from the derived url and create a FeatureLayer from the first FeatureTable.
    5. Set the surface placement mode and add a renderer to the feature layer, then add the new layer to the scene's list of operational layers.

Relevant API

  • GeoprocessingFeatures
  • GeoprocessingJob
  • GeoprocessingParameter
  • GeoprocessingParameters
  • GeoprocessingTask
  • LocalGeoprocessingService
  • LocalGeoprocessingService.ServiceType
  • LocalServer
  • LocalServerStatus
  • Raster
  • RasterFunction

About the data

This sample loads with a 10m resolution digital terrain elevation model of the Island of Arran, Scotland (data Copyright Scottish Government and Sepa 2014).

Three raster functions (json format) are applied to the raster data to mask out data at or below sea level.

The geoprocessing task is started with a gpkx. This Create elevation profile geoprocessing package was authored in ArcGIS Pro using ModelBuilder, and the Interpolate Shape (3D Analyst) tool.

Additional information

Local Server can be downloaded for Windows and Linux platforms from your ArcGIS Developers dashboard. Local Server is not supported on macOS.

The Package Result tool in ArcGIS Pro is used to author ArcGIS Runtime compatible geoprocessing packages (.gpkx files). For more information on running powerful offline geoprocessing tasks to provide advanced spatial analysis to your applications, see ArcGIS Runtime Local Server SDK.

The results of the geoprocessing tasks executed with ArcGIS Runtime Local Server can be accessed with code, persisted, and shared, for example as a feature collection portal item. This contrasts with the Scene visibility analyses, viewshed and line of sight, which are calculated dynamically at render-time and are displayed only in analysis overlays.

Tags

elevation profile, geoprocessing, interpolate shape, local server, offline, parameters, processing, raster, raster function, scene, service, terrain

Sample Code

LocalServerGenerateElevationProfile.xamlLocalServerGenerateElevationProfile.xamlLocalServerGenerateElevationProfile.xaml.cs
Use dark colors for code blocksCopy
                                                                        
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.LocalServerGenerateElevationProfile.LocalServerGenerateElevationProfile"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:SceneView x:Name="MySceneView" />
        <Border x:Name="MyButtonPanel"
                Width="250"
                HorizontalAlignment="Left"
                Style="{StaticResource BorderStyle}"
                Visibility="Collapsed">
            <StackPanel>
                <Button x:Name="MyGenerateElevationProfileButton"
                        Width="200"
                        Margin="5"
                        Click="GenerateElevationProfileButton_Click"
                        Content="Generate Elevation Profile"
                        IsEnabled="False" />
                <Button x:Name="MyDrawPolylineButton"
                        Width="200"
                        Margin="5"
                        Click="DrawPolylineButton_Click"
                        Content="Draw Polyline"
                        IsEnabled="False" />
                <Button x:Name="MyClearResultsButton"
                        Width="200"
                        Margin="5"
                        Click="ClearResultsButton_Click"
                        Content="Clear Results"
                        IsEnabled="False" />
                <ProgressBar x:Name="MyProgressBar"
                             Width="200"
                             MinHeight="10"
                             Margin="5,10,5,0"
                             Maximum="100"
                             Minimum="0"
                             Visibility="Collapsed" />
                <TextBlock x:Name="MyProgressBarLabel"
                           Margin="0,5,0,0"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Visibility="Collapsed" />
                <Button x:Name="MyCancelJobButton"
                        Width="200"
                        Margin="5"
                        Click="CancelJobButton_Click"
                        Content="Cancel"
                        Visibility="Collapsed" />
                <Button x:Name="MySaveButton"
                        Width="200"
                        Margin="5"
                        Click="SaveButton_Click"
                        Content="Save"
                        Visibility="Collapsed" />
            </StackPanel>
        </Border>
        <Border Width="300"
                HorizontalAlignment="Right"
                Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock x:Name="MyInstructionsTitleTextBlock"
                           FontSize="14"
                           FontWeight="SemiBold"
                           Text="Instructions:"
                           Visibility="Collapsed" />
                <TextBlock x:Name="MyInstructionsContentTextBlock"
                           Text="Starting Local Server..."
                           TextWrapping="WrapWholeWords" />
            </StackPanel>
        </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.