Converting Elevation DEMs to 3DTiles
3DTiles is an open standard for organizing massive geometry datasets into a spatial data structure for efficient access and rendering of geospatial data. Terrain data is well suited for this format and STK now offers a tool to convert elevation and imagery data into a 3D Tileset. We have a tool to help you perform the conversion called AgTerrain2Tiles.
AgTerrain2Tiles is a utility designed to take a collection of files that define a single resolution datasource and build a 3D Tileset representing the datasource. If an optional collection of imagery files is provided, the imagery will be built into the resulting collection of glTF content files.
Datasource inputs
A datasource is defined as the collection of source elevation files (e.g., tifs, dems, etc) that originates from a sole data provider. Examples of this include the USGS 3DEP 1/3 arc second elevation data, where one or more elevation rasters can be selected as inputs for this conversion process.
It’s important that data is at a consistent resolution (e.g., 1/3 arc second or about 10ms) for all input files, as the processing tool uses the max resolution of the input data to determine the depth of the resulting 3DTileset tree.
Command line options
From a command prompt, navigate to the STK Install location’s bin directory. Show the help by running the conversion tool and passing in the --help flag:
.\AgTerrain2Tiles.exe --help
The available command line options are summarized in the table below:
Option | Description | Default Value |
---|---|---|
--terrain | [Required] File or directory specifying the input terrain elevation data. | n/a |
--imagery | File or directory specifying the input imagerydata. | n/a |
--outputDir | Defines the output directory where this tileset will be placed. | Current directory |
--help | Shows the help. | n/a |
--toMetersFactor | Scales input height values to meters. | 1.0 |
--name | Defines the output root directory where this tileset will be placed. | n/a |
--imageryFilter | Specifies the filtering algorithm (nearest or bilinear) to use when imagery is sampled. Nearest is more performant, Bilinear is higher quality. | bilinear |
--heightReference | Specifies the height reference (vertical datum) for all elevations in the terrain source. Must be one of the following: ellipsoid, egm96, egm2008, navd88, mars)gmm3. | ellipsoid |
--combine | Builds this (non-overlapping) tileset in the target tileset's location; both the root node of this tileset and the target tileset root(s) are combined under a single parent root node. This is the recommended way to merge two disjoint tilesets, such as a polar projection based tileset with an equirectangular based tileset. | n/a |
--extensions | Defines file extensions that are used to filter input files specified in -- terrain and --imagery options. Multiple extensions can be specified by using a comma separated list (*csv). | .tif, .lbl. tiff, .flt |
--saveConfig | Use this option to save the current command line options to a json file. | n/a |
--config.json | Load commandline options from a json configuration file. | n/a |
--resume | Resume processing, skipping over tiles that have already been written. | n/a |
When defining a terrain or imagery datasource, the value can refer to either a single raster file or a directory containing of many files that describe a datasource. When a directory is defined, this utility recurses through the directory tree and gathers all files that match the extensions listed by the --extension option, always including the default extensions listed in the table above.
All files in a datasource should be of the same grid space resolution; mosaicking multiple terrain resolutions will be available in a future release.
Config.json
Specifying all options via command line can be error prone and tedious. Any set of command line options can be saved off for future use with the --saveConfig=[filename] command option and loaded with the --config.json=[filename] command option.
The config.json file is the only mechanism available that enables users to define data source attribution as well as an attribution string for the Tileset author to be embedded in the Tileset. An example configuration file is provided below, describing the configuration used to build a small Tileset containing Shackleton’s peak on the Lunar surface:
Json code example
{
"configVersion" : 1,
"attribution" : "Copyright ANSYS, Inc",
"outputDir" : "C:/Terrain/out",
"name" : "shackleton",
"terrain" : [
{
"input" : "C:/Terrain/Lunar/LDEM_shackleton_20m.tif",
"attribution" : "Terrain derived from LOLA LDEM, Improved LOLA Elevation Maps for South Pole Landing Sites, Sept 2021.",
"toMeters" : 1000.0
}
],
"imagery" : [
{
"input" : "C:/Imagery/Lunar/NAC_ROI_SHKLTNPKLO1_P888S1247.tif",
"attribution" : "NAC_ROI_SHKLTNPKLO1, Optimized Illuminated Terrain Coverage of the Candidate Artemis III Landing Sites with LROC nac controlled Mosaics, 2023."
}
]
}
Examples
Process a tif file that includes the half dome feature from Yosemite National Park. This dataset was retrieved from the USGS National Viewer, which defines elevation data in the North American Vertical Datum, 1988 (NAVD88). As a result, we must set the heightReference to navd88 to ensure that AgTerrain2Tiles interprets height values accurately. Note that in this example, this configuration is saved to halfdome.json.
.\AgTerrain2Tiles.exe --terrain=C:\Terrain\halfDome.tif --imagery=C:\ Terrain\halfDome_Hillshade.tif --name=HalfDome --outputDir=C:\Terrain\out --heightReference=navd88 --toMetersFactor=1.0 --extensions=".tif" --saveConfig="C:\Terrain\configs\halfdome.json"
Building on the previous example, if we need to rerun this example (e.g., now build this Tileset with attribution strings), we can load from a config.json file.
.\AgTerrain2Tiles.exe --config.json=C:\Terrain\configs\halfdome.json
The AgTerrain2Tiles utility is also capable of processing tilesets in a polar stereographic projection. In the example below, we see how to process data representing the lunar south pole using elevation data provided by LOLA.
.\AgTerrain2Tiles.exe --terrain=C:\Terrain\Lunar\LDEM_80S_20MPP_ADJ.tiff --imagery=C:\Imagery\LDEM_80S_20MPP_ADJ_HILL.tiff --name=moon_southpole --outputDir=C:\Terrain\out --heightReference=ellipsoid --toMetersFactor=1.0 --extensions=".tiff" --saveConfig="C:\Terrain\configs\moon_southpole.json"