As discussed in Terrain visualization, any Lightspeed view has built-in support for 3D terrain data. The TLspRasterLayer class takes care of many of the visualization aspects of 3D terrain, but many applications need to perform various queries or analysis tasks on the terrain data. This article describes the tools that are available for this in the LuciadLightspeed API. These tools are bundled in the ILspTerrainSupport, an instance of which can be obtained from the view’s TLspViewServices.

Querying terrain data

To obtain the terrain elevation for a given point in the world, ILspTerrainSupport provides two different methods: getViewDependentHeightProvider() and getModelHeightProvider(). Both of these methods return an ILcdHeightProvider, but the request method determines what characteristics it has.

The view-dependent provider returns height values that correspond to the terrain data as it is currently being rendered in the view. This means that the view-dependent height provider never causes additional height data to be loaded from the underlying elevation model(s), from disk or from the network. On the other hand, this also implies that the resolution or accuracy of the returned values is dependent on the level of detail at which the terrain is being visualized.

The terrain model height provider, on the other hand, can return values at any resolution, up to and including the highest level of detail available in the underlying data. To do this, the provider may have to read additional data from disk or from the network, if the required level of detail is not currently in use by the view. As a result, querying the terrain model height provider is potentially a lot more costly than using the view-dependent one.

It is therefore important to choose the appropriate provider for a given use case. The view-dependent provider is strongly recommended for all interactive usages, such as visualization or graphical editing of objects. For instance, to determine a vertical offset to reposition 2D points to ground level in a painter or styler, choose the view-dependent provider.

For computation or analysis tasks where accuracy is key, line-of-sight computations for example, choose the terrain model provider.

Querying tile-based terrain data

The height providers discussed in the previous section provide support for point-sampled access to the terrain elevation. In some cases, however, it might be desirable to sample whole regions of the terrain at a uniform resolution. Sampling a large number of points using this approach does not provide the optimal performance.

For these cases, ILspTerrainSupport provides access to the terrain elevations in the form of an ILcdEarthTileSet, which you can obtain through the getElevationTileSet() method. The returned tileset contains a single coverage which provides tiles containing TLcdEarthElevationData objects. Like the terrain model elevation provider, the tileset can provide data at any requested resolution.

For more information about tilesets, see Earth tileset modeling.

Determining a point on the terrain using intersection calculation

The methods described in Querying terrain data and Querying tile-based terrain data have in common that they provide terrain elevation values for a given 2D point or area. Another useful feature offered by ILspTerrainSupport is the ability to compute the intersection between a line, or ray, in the 3D world and the 3D terrain surface. These methods are:

  • getPointOnTerrain(): takes a point in view coordinates as input and returns the front-most point on the terrain which projects to the same view coordinates. This is useful, for example, to query the terrain under the mouse cursor.

  • intersectTerrain(): takes two points in world coordinates as input. A ray is cast from the first point in the direction of the second, and the first location where this ray intersects the terrain is returned. This is more general than the previous method, and could be used, for instance, to determine where a moving point could collide with the terrain.