Learn how to find elevation values for points along a path in New Zealand's South Island with the Elevation service.
The Elevation service is a location service that returns elevation values for a single location or multiple locations. Elevation coverage is provided for both topography (land elevations) and bathymetry (water depths) and takes location inputs as longitude and latitude coordinates.
In this tutorial, you use the Elevation service to return elevation values for points along a path in New Zealand's South Island. The values will be returned as measures above mean sea level in meters.
Prerequisites
An ArcGIS Location Platform account.
Steps
Get the starter app
Select a type of authentication below and follow the steps to create a new application.
Set up authentication
Create developer credentials in your portal for the type of authentication you selected.
Set developer credentials
Use the API key or OAuth developer credentials so your application can access location services.
Add script references
Reference the ArcGIS REST JS request
and elevation
packages to access the Elevation service.
-
Reference the
request
andelevation
packages from ArcGIS REST JS.Use dark colors for code blocks <!-- Load Leaflet from CDN --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin="" /> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script> <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.14/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-vector@4.2.7/dist/esri-leaflet-vector.js"></script> <!-- Load ArcGIS REST JS --> <script src="https://unpkg.com/@esri/arcgis-rest-request@4/dist/bundled/request.umd.js"></script> <script src="https://unpkg.com/@esri/arcgis-rest-elevation@1/dist/bundled/elevation.umd.js"></script>
Update the map
-
Set the basemap to
arcgis/topographic
display topographic details.Use dark colors for code blocks const basemapEnum = "arcgis/topographic";
-
To focus on South Island, New Zealand, update the map's viewpoint to
-44.6323,169.0016
and set the zoom level to12
.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }).setView([-44.6323,169.0016], 12);
Define points of interest
You need to define the coordinates of interest from Kingston to Frankton in New Zealand's South Island, passing through the Lake Wakatipu. You then draw a polyline connecting these points to visualize the route on the map.
-
Define a set of points starting from Kingston, passing through Lake Wakatipu, and reaching Frankton.
Use dark colors for code blocks const points = [ [168.957299, -44.665736], [168.970268, -44.655672], [168.993555, -44.645187], [169.007703, -44.630505], [168.999450, -44.609314], [169.026863, -44.610783], [169.056045, -44.609104] ];
-
Use
L.polyline()
to connect the points with a polyline.Use dark colors for code blocks const points = [ [168.957299, -44.665736], [168.970268, -44.655672], [168.993555, -44.645187], [169.007703, -44.630505], [168.999450, -44.609314], [169.026863, -44.610783], [169.056045, -44.609104] ]; L.polyline(points.map(([lng, lat]) => [lat, lng])).addTo(map); // Leaflet requires [lat, lng]
Get elevation data
After defining the points and drawing the route, you make a request to the Elevation service to get the elevations of the points along the route.
-
Define a function called
get
and call it.Elevation Data() Use dark colors for code blocks async function displayElevationData() { } displayElevationData();
-
Make a request to the Elevation service, passing in the array of points.
Use dark colors for code blocks async function displayElevationData() { const data = await arcgisRest.findElevationAtManyPoints({ coordinates: points, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); } displayElevationData();
Display results
Once the elevation data is fetched, you can display the results on the map. This involves extracting the elevation values from the response and creating a marker at each point to show the elevation information.
-
Extract the
z
values from the service response to be used for displaying the elevation at each point.Use dark colors for code blocks async function displayElevationData() { const data = await arcgisRest.findElevationAtManyPoints({ coordinates: points, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); const elevationValues = data.result.points.map((point) => point.z); } displayElevationData();
-
Use
L.marker()
to place markers on the map at each point, and show a tooltip with the elevation value.Use dark colors for code blocks async function displayElevationData() { const data = await arcgisRest.findElevationAtManyPoints({ coordinates: points, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); const elevationValues = data.result.points.map((point) => point.z); points.forEach(([lng, lat], index) => { L.marker([lat, lng]) .addTo(map) .bindTooltip(`${elevationValues[index]} m`, { permanent: true, direction: "top", offset: [-15, -10] }) .openTooltip(); }); } displayElevationData();
Run the app
Run the app.
You should now see a map centered over the New Zealand's South Island, displaying the path between Kingston to Frankton, passing through the Lake Wakatipu, with elevation values along the route.What's next?
Learn how to use additional ArcGIS location services in these tutorials: