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

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