Visualizing terrains with Cesium

Today we did some experiments to visualize terrains in Cesium, using Cesium Terrain Builder (https://github.com/geo-data/cesium-terrain-builder) and Cesium Terrain Server (https://github.com/geo-data/cesium-terrain-server)

Step 1] Get some raster data with height information

For this demonstration we use a raster file from the Dutch AHN2 in tif format with cells 0.5m X 0.5m, it can be obtained from http://www.rijkswaterstaat.nl/apps/geoservices/geodata/dmc/ahn2_05_int/geogegevens/raster/01_09/i09bz1.tif  (500MB)

This image is about a part of Texel:

image

Step 2] Tile the raster with Cesium Terrain Builder

The original tif image is quite big (500MB) so we cut it into tiles using the  Cesium Terrain Builder. We use the tool ‘ctb-tile‘ for tiling inside a Docker container:

$ docker run -v  d:/gisdata/nederland/terrain:/data -ti -i homme/cesium-terrain-builder:latest bash

root@c1412e2fd51c:/# ctb-tile -o /data/tiles /data/i09bz1.tif

image

This takes some time to process (like 10 minutes), so grab a coffee and relax…

In the meantime binary .terrain files are generated for 20 zoom levels.

image

The terrain tiles are encoded in the so called ‘quantized-mesh-1.0 terrain format’, more info about this format at https://github.com/AnalyticalGraphicsInc/quantized-mesh

Step 3: Run the Cesium Terrain Server

If all the tiles are generated we can start the Cesium Terrain Server. We use another Docker command for this:

$ docker run -p 8080:8000 -v d:/gisdata/nederland/terrain:/data/tilesets/terrain geodata/cesium-terrain-server

image

One tile we can retrieve from the server using a wget command:

wget http://localhost:8080/tilesets/tiles/0/0/0.terrain

image[22]

Step 4: Visualize the terrain in Cesium

Cesium is a WebGL globe viewer that runs in a browser, see https://cesiumjs.org/ for more info.

All it takes now is to change in de basic Cesium viewer the index.html so it points to our local terrain server for getting the terrain tiles.

image

Put the Cesium viewer on a webserver (for example caddy https://caddyserver.com/) , open a browser and zoomin to Texel.. If you change the perspective the terrain should become visible:

image

Advertisements

10 thoughts on “Visualizing terrains with Cesium

  1. Hi Bert, I find this tutorial is amazing since really few information about cesium. But I have a problem in the 4th step, the terrain not showed when running in the browser. I follow your step and use the same data. I used the wget too and its work fine, the terrain can retrieve. When I see in the Network (web developer tools in Mozilla), the terrain not loaded. Can you give me some solution for this problem? thank you.

      • Hi Bertt. I actually made stupid mistake in the script and finally the terrain showed up. Do you have an idea how to handle a big size data of DTM? I have data for a city that have high vertical resolution (~10 cm). I think It will caused a problem if I run the cesium terrain builder for nearly 100 gb data. Thank you in advance.

  2. great its working now! About the scaling up: we tiled the Netherlands with the terrain builder without a problem, took like 1-2 days and of course some disk space… Just try some smaller batches first and get an estimate how long it will take.

  3. Hi Bertt, that is a nice tutorial, I also used this tutorial nearly a year ago and thankfully it saved my master thesis. I’m currently working on a nodejs tool that takes a raster image and replaces the height values in the pixels with “STK” server values, using “sampleTerrain” function. I tried it with the image in this tutorial and it worked :), after one and a half hour (500 MB) but it worked. I think it can work as an alternative for people who would like to build their city models and don;t have specific requirements regarding the terrain data, or don’t want to involved with too much code and docker.

  4. “http://assets.agi.com/stk-terrain/world” which is the default terrain provider for Cesium.
    I’m using node-gdal to read / write raster data.
    -Loop over the output pixels.
    – Use “SampleTerrain” method to interpolate the height value in the pixel’s location – from STK-World –
    – Assign the retrieved value to the output pixel.
    In theory using this raster as height reference to create a 3D city model will create a model that will be clamped / fit to the default ” STK-World” terrain in Cesium. I need to further test it and see.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s