To find the elevation of a location, you use the ArcGIS 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. All elevation values will be returned in meters as measures of ellipsoidal height above ground level or orthometric height above mean sea level.
You can build applications that use the service to:
- Determine the height of a specific location above mean sea level or ground level.
- Measure the depth of a water body at a specific location.
- Compare the relative elevation of different points to determine slope.
- Plan flight paths by assessing elevation changes along a route.
- Create elevation profiles of trails or roads.
How to access the Elevation service
There is no direct integration with OpenLayers to access the Elevation service. Instead, you use the ArcGIS REST JS elevation
and request
packages to make an authenticated request to the service.
- Reference the OpenLayers library.
- Reference the
elevation
andrequest
packages to make an authenticated request to the service. - Set up authentication.
- If you are using an API key, make sure it has privileges to access the Elevation service.
- If you are using user authentication, the account must be an ArcGIS Location Platform account with Elevation service privileges.
- Define parameters to pass to the service.
- Call the service and handle the results.
Example
Find the elevation of a point
This example illustrates how to find the elevation of a specific location.
olms.apply(map, basemapURL).then(() => {
const popup = new Popup();
map.addOverlay(popup);
const markerLayer = new ol.layer.Vector({
source: new ol.source.Vector()
});
map.addLayer(markerLayer);
const circle = new ol.style.Style({
image: new ol.style.Circle({
radius: 4,
fill: new ol.style.Fill({ color: "#FF0000" }),
stroke: new ol.style.Stroke({ color: "#000", width: 1 })
})
});
map.on("click", async (event) => {
const coordinate = ol.proj.toLonLat(event.coordinate);
const [lng, lat] = coordinate;
const response = await arcgisRest.findElevationAtPoint({
lon: lng,
lat: lat,
relativeTo: elevationMeasure,
authentication: arcgisRest.ApiKeyManager.fromKey(accessToken)
})
const { x, y, z } = response.result.point;
let message = `<b>Elevation relative to ${elevationMeasure === "meanSeaLevel" ? "mean sea level" : "ground level"}</b><br>Latitude: ${y.toFixed(5)}<br>Longitude: ${x.toFixed(5)}<br>Elevation: ${z} m`;
popup.show(event.coordinate, message);
const point = new ol.Feature({
geometry: new ol.geom.Point(event.coordinate)
});
point.setStyle(circle);
markerLayer.getSource().clear();
markerLayer.getSource().addFeature(point);
});
Find the elevations of multiple points
This example illustrates how to get elevation values of multiple locations at once.
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
points.forEach(([lon, lat], index) => {
const elevation = elevationValues[index];
// Popup
const popup = new Popup();
popup.container.getElementsByClassName('ol-popup-closer')[0].remove();
popup.container.style = 'width:30px;'
map.addOverlay(popup);
popup.show(ol.proj.fromLonLat([lon, lat]),`${elevation} m`);
});
}