The RasterModelHeightProvider
class allows you to retrieve
height values from an elevation model.
Creating a RasterModelHeightProvider
When creating a RasterModelHeightProvider
, you must provide a IRasterModel
containing
elevation data. Optionally, you can specify if you want to apply bilinear interpolation to the height values. You can also
specify the coordinate reference in which the height provider operates. If you don’t provide any coordinate reference,
the RasterModelHeightProvider
uses the coordinate reference of the raster model.
A RasterModelHeightProvider
can retrieve elevation data at a particular coordinate and at a particular density.
The result is expressed as a height value above mean sea level.
Pixel density
When you retrieve elevation data, you must specify the maximum pixel density of the data you want. The pixel density
represents the number of samples present in the data over a unit of area in a given coordinate reference. A PixelDensity
can be created from a distance between samples (in meters), to simplify use cases like sampling along a line
every N meters.
When it queries data from a multi-level model, the RasterModelHeightProvider
looks for the most detailed level with a
pixel density equal to or lower than the requested pixel density. If it doesn’t find data with a pixel density equal
to or lower than the desired pixel density, it returns the least detailed data.
auto heightProvider = RasterModelHeightProvider::newBuilder().rasterModel(elevationModel).interpolate(false).reference(wgs84).build(); auto sanSebastian = Coordinate{43.325638, -1.99256}; auto cadaques = Coordinate{42.288199, 3.298322}; auto line = GeometryFactory::createLine(wgs84, sanSebastian, cadaques, LineInterpolationType::Geodesic); double sampleDistance = 10000.0; // 10 km auto numberOfSamples = static_cast<size_t>(line->getLength2D() / sampleDistance); std::vector<double> samples; samples.reserve(numberOfSamples); for (size_t i = 0; i < numberOfSamples; ++i) { auto t = static_cast<double>(i) / static_cast<double>(numberOfSamples - 1); auto point = line->computePoint(t); auto density = PixelDensity::fromSampleDistance(sampleDistance, point, wgs84); auto height = heightProvider.retrieveHeightAt(point, density); samples.push_back(height.value()); }