View on GitHub Sample viewer app

Create an elevation profile using a geoprocessing package executed with ArcGIS Maps SDK for Local Server.

Image of local server generate elevation profile

Use case

Applications that include ArcGIS Maps SDK for 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 Maps SDK for 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). Right-click 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.
  3. Start the server asynchronously with Server.startAsync().
  4. Wait for the server to be in the LocalServerStatus.STARTED state.
    • Callbacks attached to Server.addStatusChangedListener() will invoke whenever the status of the local server has changed.
  5. Start a LocalGeoprocessingService and create a GeoprocessingTask.
    1. Instantiate LocalGeoprocessingService(Url, ServiceType) to create a local geoprocessing service.
    2. Invoke LocalGeoprocessingService.start() to start the service asynchronously.
    3. Instantiate GeoprocessingTask(LocalGeoprocessingService.url() + "/CreateElevationProfileModel") to create a geoprocessing task that uses the elevation profile tool.
  6. Create an instance of GeoprocessingParameters and get its list of inputs with gpParameters.getInputs().
  7. 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.
  8. 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().
  9. Add generated elevation profile as a FeatureLayer to the scene.
    1. Get the url from the local geoprocessing service using LocalGeoprocessingService.getUrl().
    2. Get the server job id of the geoprocessing job using GeoprocessingJob.getServerJobId().
    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 Maps SDKs for Native Apps compatible geoprocessing packages (.gpkx files). For more information on running powerful offline geoprocessing tasks to provide advanced spatial analysis to your applications, see ArcGIS Maps SDK for Local Server.

The results of the geoprocessing tasks executed with ArcGIS Maps SDK for 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

module-info.java module-info.java LocalServerGenerateElevationProfileController.java LocalServerGenerateElevationProfileSample.java
/*
* Copyright 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
module com.esri.samples.local_server_generate_elevation_profile {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
requires javafx.fxml;
// make all @FXML annotated objects reflectively accessible to the javafx.fxml module
opens com.esri.samples.local_server_generate_elevation_profile to javafx.fxml;
exports com.esri.samples.local_server_generate_elevation_profile;
}