DEM terrain from OpenTopography
This page shows how to download a real Digital Elevation Model (DEM) from OpenTopography and use it as terrain in Gazebo Harmonic.
The default example downloads a 2 km x 2 km area using USGS10m, if the selected area is covered by USGS 3DEP. For a lighter Gazebo world, use the 0.5 km x 0.5 km option shown below. A 10 m DEM gives about 50 x 50 height samples for a 0.5 km square.
Note
USGS10m is a USGS 3DEP dataset, so it covers the United States, Alaska, Hawaii, and U.S. territories. For other countries, use a global dataset such as COP30, NASADEM, AW3D30, or SRTMGL1. Those are usually 30 m resolution, not 10 m.
request size
A 2 km x 2 km world is only 4 km2. OpenTopography documents a much larger request limit for USGS10m, so the simulation size here is chosen for Gazebo performance, not because the API requires such a small area.
Install tools
Gazebo uses GDAL internally for DEM files. Use GDAL on the command line to inspect and reproject the DEM before loading it in simulation.
Check:
Get an OpenTopography API key
- Open OpenTopography.
- Create an account or sign in.
- Open your MyOpenTopo dashboard.
- Click
Get an API KeyorRequest API key. - Store it in an environment variable:
Do not commit the API key into the repository.
OpenTopography also documents daily API limits. Keep generated examples and notebooks using OPENTOPOGRAPHY_API_KEY from the environment instead of hard-coding a key.
Pick an area
Choose the center of the terrain as latitude and longitude.
Example near Mount Baker, Washington:
The download script converts the center point into an approximate square latitude/longitude bounding box. By default it downloads 2000 m x 2000 m.
Output:
For a smaller 0.5 km x 0.5 km area, pass 500 as the third argument:
Output:
The script calls:
with:
| Parameter | Value |
|---|---|
datasetName |
USGS10m |
south north west east |
bounding box around the center point |
outputFormat |
GTiff |
API_Key |
from OPENTOPOGRAPHY_API_KEY |
Prepare the DEM for Gazebo
The downloaded DEM is usually in geographic coordinates, meaning latitude and longitude degrees. For simulation, reproject it to a meter-based coordinate system.
The script below chooses the UTM zone from the longitude and resamples to 10 m cells:
Output:
For the 0.5 km x 0.5 km DEM, pass the same size:
Output:
Inspect the file:
Look for:
Size is ...Pixel Size = (10.000..., -10.000...)Minimum=...Maximum=...
For a 2 km x 2 km area at 10 m resolution, expect roughly 200 x 200 pixels. For a 0.5 km x 0.5 km area at 10 m resolution, expect roughly 50 x 50 pixels. It may not be exact because the first crop is defined in latitude/longitude.
Generate the Gazebo world
Generate the SDF from the actual DEM metadata:
Then run:
The generated SDF uses the DEM as both collision and visual geometry:
The exact size and pos values are generated from gdalinfo:
x = raster_width_pixels * pixel_width_my = raster_height_pixels * pixel_height_mz = Maximum elevation - Minimum elevationpos z = -Maximum elevation
Using pos z = -Maximum elevation moves the highest point near z = 0, which makes the terrain easier to view from the default Gazebo camera. If you want the lowest point near z = 0, change pos z to -Minimum elevation.
Fuel-style mesh model
The Gazebo moon examples show two useful patterns:
dem_moon.sdfis a world that configures moon gravity, GUI, physics, a falling box, and then includes a terrain model.- The
Moon 60S 30SFuel model is a regular model folder withmodel.config,model.sdf, and a.daemesh. It is not loaded as a DEM heightmap at runtime.
This mesh approach can be more stable for rendering because Gazebo uses the normal mesh pipeline instead of the OGRE heightmap terrain shader.
Output:
The generated model is structured like a Fuel model:
The world includes it with a model URI:
Before running the world, point Gazebo at the local model folder:
The mesh generator converts the DEM grid into a centered terrain mesh:
xandyare local meter coordinates from the UTM raster.z = elevation - minimum_elevation, so the lowest point is nearz = 0.- The generated
.daeis used for both collision and visual geometry. - The world uses DART with Bullet collision detection, matching the moon DEM example's heightmap-friendly physics setting.
Files
Download script
Prepare script
Mesh model generator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
World generator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
If 10 m is not available
If OpenTopography returns an error for USGS10m, the selected point is probably outside USGS 3DEP coverage or the account does not have access.
For non-U.S. terrain, use a 30 m global dataset. Example API endpoint:
For a 0.5 km x 0.5 km world, 30 m DEM gives about 17 x 17 samples. For a 2 km x 2 km world, it gives about 67 x 67 samples. It is still useful for large terrain shape, but it will not show small local features.
Common problems
- If Gazebo cannot load the
.tif, rungdalinfo dem_500m_10m_utm.tiffirst. If GDAL cannot read it, Gazebo will not read it. - If the terrain is huge or tiny, check that the DEM was reprojected to UTM meters before generating the world.
- If the terrain is visually offset from collision, make sure the same
<heightmap>values are used in both<collision>and<visual>. - If objects do not fall, make sure simulation is running. Use
gz sim -r -v4 dem_world.sdfor press the play button in the GUI. Also check that the inserted model does not have<static>true</static>. - If OGRE crashes with a fragment shader error like
detailCol0 undeclared, make sure the visual heightmap has a<texture>block with valid diffuse and normal texture files. - If simulation is slow, resample to 20 m or 30 m with
gdalwarp -tr 20 20. - If the terrain is hard to find in the GUI, check the generated
<pos>z value. - If
dem_mesh_world.sdfcannot findmodel://local_dem_terrain, setGZ_SIM_RESOURCE_PATH="$PWD/models"from the folder that contains the generatedmodelsdirectory.