There are two ways to retrieve elevation data:

  • You retrieve elevation data from a single model, with the user controlling the level of detail. See this article for more information.

  • You retrieve elevation data from the map using the Map::HeightProvider class. You can query the map to obtain elevation data:

    • At a specified device-independent pixel coordinate. In this case, the level of detail is automatically calculated based on the current view.

    • At a particular point on the map and at a specified pixel density.

The Map::HeightProvider handles multiple elevation layers by querying the height of each visible layer from top to bottom and returns the height value from the first layer whose underlying model has elevation data at the specified pixel/map coordinate.

If no visible elevation model has elevation data at the specified pixel/map coordinate, the height provider doesn’t return any value.

Retrieving elevation in a view

The Map::HeightProvider takes as parameters a coordinate in device independent pixels, and a boolean value to specify if you want to apply bilinear interpolation to the height values. The height provider returns an elevation in the unit of measure of the map.

Program: Retrieving elevation from the map at pixel coordinate (0,0)
const Map::HeightProvider& heightProvider = _map->getHeightProvider();
Coordinate centerOfTheScreen{_map->getWidth() / 2.0, _map->getHeight() / 2.0};
std::optional<double> elevation = heightProvider.retrieveHeightAt(centerOfTheScreen, false);

Retrieving elevation at a point on the map

The Map::HeightProvider takes as parameters a point on the map, the maximum pixel density of the data you want and a boolean flag to specify if you want to apply bilinear interpolation to the height values. The height provider returns an elevation in the unit of measure of the map.

Program: Retrieving elevation at a point on the map
auto reference = *CoordinateReferenceProvider::create("EPSG:4326");
auto coordinate = Coordinate{0.0, 0.0};
auto pointOnMap = GeometryFactory::createPoint(reference, coordinate);
double sampleDistance = 10'000.0; // 10 km
auto pixelDensity = PixelDensity::fromSampleDistance(sampleDistance, coordinate, reference);
const Map::HeightProvider& heightProvider = _map->getHeightProvider();
std::optional<double> elevation = heightProvider.retrieveHeightAt(*pointOnMap, pixelDensity, false);